From 832dea2c7dd152b86b2ca62b72a5fe6e0e8b45ff Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 21 Jan 2024 19:50:54 -0600 Subject: [PATCH] h-a: Add init container to wait for PostgreSQL When Home Assistant starts, if PostgreSQL is unavailable, it will come up successfully, but without the history component. It never tries again to connect and enable the component. This makes it difficult to detect the problem and thus easy to overlook the missing functionality. To avoid having extended periods of missing state history, we'll force Home Assistant to wait for PostgreSQL to come up before starting. --- home-assistant/kustomization.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/home-assistant/kustomization.yaml b/home-assistant/kustomization.yaml index df0e51e..746e057 100644 --- a/home-assistant/kustomization.yaml +++ b/home-assistant/kustomization.yaml @@ -47,6 +47,28 @@ patches: spec: template: spec: + initContainers: + - name: waitfordb + image: docker.io/library/postgres:15 + command: + - sh + - -c + - until pg_isready; do sleep 1; done + env: + - name: PGHOST + value: default.postgresql + - name: PGGDATABASE + value: homeassistant + - name: PGUSER + valueFrom: + secretKeyRef: + name: home-assistant.homeassistant.default.credentials.postgresql.acid.zalan.do + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: home-assistant.homeassistant.default.credentials.postgresql.acid.zalan.do + key: password containers: - name: home-assistant env: