From 96a36b6bf7774ab2d7acb94774f06a9e2dd9dfd0 Mon Sep 17 00:00:00 2001 From: Nithin Shekar Kuruba <81444731+NithinKuruba@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:59:02 -0800 Subject: [PATCH] feat: init container to wait for patroni to be available (#41) * feat: create init container to wait for db pods * feat: update init container script * feat: fix pre-commit --- charts/keycloak/Chart.yaml | 2 +- charts/keycloak/templates/deployment.yaml | 28 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/charts/keycloak/Chart.yaml b/charts/keycloak/Chart.yaml index 808f3ee..5c92c02 100644 --- a/charts/keycloak/Chart.yaml +++ b/charts/keycloak/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: sso-keycloak -version: 1.15.0 +version: 1.15.1 appVersion: 7.6.39-build.1 description: Open Source Identity and Access Management For Modern Applications and Services dependencies: diff --git a/charts/keycloak/templates/deployment.yaml b/charts/keycloak/templates/deployment.yaml index 0e91845..3389bc3 100644 --- a/charts/keycloak/templates/deployment.yaml +++ b/charts/keycloak/templates/deployment.yaml @@ -23,6 +23,34 @@ spec: {{- end }} labels: {{ include "sso-keycloak.labels" . | nindent 8 }} spec: + initContainers: + - name: {{ .Chart.Name }}-init + image: openshift/origin-cli:latest + command: + - "/bin/sh" + - "-c" + - | + namespace="{{ .Release.Namespace }}" + name={{ .Values.patroni.nameOverride }} + echo "Current Namespace: $namespace" + echo "Patroni Statefulset: $name" + check_rollout_status(){ + replicas_desired={{ .Values.patroni.replicaCount }} + replicas_current=$(oc get -n $namespace statefulset $name -o jsonpath='{.status.currentReplicas}') + # Set replicas_current to zero if it is not available + replicas_current="${replicas_current:-0}" + echo "Replicas desired: ${replicas_desired}, Replicas current: ${replicas_current}" + if [ "${replicas_current}" -eq "${replicas_desired}" ]; then + return 0 # Rollout is complete + else + return 1 # Rollout is not complete + fi + } + while ! check_rollout_status; do + echo "Waiting for StatefulSet {{ .Values.patroni.nameOverride }} rollout to complete..." + sleep 5 + done + containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"