From a517f1b59ce1ee437e2c844b15e0054255f941df Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 23 Mar 2023 22:37:59 -0400 Subject: [PATCH] draft --- ...s-decide-wait-for-service-dependencies.tpl | 44 +++++++++++++++++++ .../posthog/templates/decide-deployment.yaml | 3 +- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 charts/posthog/templates/_snippet-initContainers-decide-wait-for-service-dependencies.tpl diff --git a/charts/posthog/templates/_snippet-initContainers-decide-wait-for-service-dependencies.tpl b/charts/posthog/templates/_snippet-initContainers-decide-wait-for-service-dependencies.tpl new file mode 100644 index 00000000..0524c74f --- /dev/null +++ b/charts/posthog/templates/_snippet-initContainers-decide-wait-for-service-dependencies.tpl @@ -0,0 +1,44 @@ +{{/* Common initContainers-decide-wait-for-service-dependencies definition */}} +{{- define "_snippet-initContainers-decide-wait-for-service-dependencies" }} +- name: decide-wait-for-service-dependencies + image: {{ .Values.busybox.image }} + imagePullPolicy: {{ .Values.busybox.pullPolicy }} + env: + {{- include "snippet.clickhouse-env" . | nindent 4 }} + command: + - /bin/sh + - -c + - > + {{ if .Values.clickhouse.enabled }} + until ( + NODES_COUNT=$(wget -qO- \ + "http://$CLICKHOUSE_USER:$CLICKHOUSE_PASSWORD@{{ include "posthog.clickhouse.fullname" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local:8123" \ + --post-data "SELECT count() FROM clusterAllReplicas('{{ .Values.clickhouse.cluster }}', system, one)" + ) + test ! -z $NODES_COUNT && test $NODES_COUNT -eq {{ mul .Values.clickhouse.layout.shardsCount .Values.clickhouse.layout.replicasCount }} + ); + do + echo "waiting for all ClickHouse nodes to be available"; sleep 1; + done + {{ end }} + + {{ if .Values.redis.enabled }} + until (nc -vz "{{ include "posthog.redis.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local" {{ include "posthog.redis.port" . }}); + do + echo "waiting for Redis"; sleep 1; + done + {{ end }} + + {{ if .Values.kafka.enabled }} + + KAFKA_BROKERS="{{ include "posthog.kafka.brokers" . }}" + + KAFKA_HOST=$(echo $KAFKA_BROKERS | cut -f1 -d:) + KAFKA_PORT=$(echo $KAFKA_BROKERS | cut -f2 -d:) + + until (nc -vz "$KAFKA_HOST.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local" $KAFKA_PORT); + do + echo "waiting for Kafka"; sleep 1; + done + {{ end }} +{{- end }} diff --git a/charts/posthog/templates/decide-deployment.yaml b/charts/posthog/templates/decide-deployment.yaml index e7eb7f9f..874ec901 100644 --- a/charts/posthog/templates/decide-deployment.yaml +++ b/charts/posthog/templates/decide-deployment.yaml @@ -170,6 +170,5 @@ spec: securityContext: {{- omit .Values.decide.securityContext "enabled" | toYaml | nindent 12 }} {{- end }} initContainers: - {{- include "_snippet-initContainers-wait-for-service-dependencies" . | indent 8 }} - {{- include "_snippet-initContainers-wait-for-migrations" . | indent 8 }} + {{- include "_snippet-initContainers-decide-wait-for-service-dependencies" . | indent 8 }} {{- end }}