From 736e9f268ae5a7fc90b9c7b669902bc2ad5fa1c6 Mon Sep 17 00:00:00 2001 From: Jan Lauber Date: Wed, 7 Sep 2022 11:16:05 +0200 Subject: [PATCH] add init container to check if db is ready, only when db is deployed also Signed-off-by: Jan Lauber --- charts/safir/templates/deployment.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/charts/safir/templates/deployment.yaml b/charts/safir/templates/deployment.yaml index 780a282..822f200 100644 --- a/charts/safir/templates/deployment.yaml +++ b/charts/safir/templates/deployment.yaml @@ -52,6 +52,21 @@ spec: {{- if .Values.initContainers }} {{- include "common.tplvalues.render" (dict "value" .Values.initContainers "context" $) | nindent 8 }} {{- end }} + {{- if .Values.postgresql.enabled }} + # pg_isready init container to check if the database is ready + - name: pg-isready + image: postgres + command: + - 'sh' + - '-c' + - | + until pg_isready -h {{ .Release.Name }}-postgresql.{{ .Release.Namespace }}.svc.cluster.local -p 5432; do + echo "Waiting for PostgreSQL to be ready..." + sleep 2 + done + - 'echo' + - 'PostgreSQL is ready' + {{- end }} containers: - name: apache image: {{ include "safir.apache.image" . }}