From 3426a46c758c7baf90879eddaf0dc2b4a7db20ef Mon Sep 17 00:00:00 2001 From: Jimmy Bernljung Date: Tue, 15 Nov 2022 18:13:16 +0100 Subject: [PATCH 1/2] Add value for Kubernetes cluster name --- charts/posthog/templates/_posthog.tpl | 8 ++++++++ ...et-initContainers-wait-for-service-dependencies.tpl | 10 +++++----- .../posthog/templates/clickhouse-backup-cronjob.yaml | 2 +- charts/posthog/values.yaml | 3 +++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/charts/posthog/templates/_posthog.tpl b/charts/posthog/templates/_posthog.tpl index 9110472f4..54e3e542e 100644 --- a/charts/posthog/templates/_posthog.tpl +++ b/charts/posthog/templates/_posthog.tpl @@ -8,6 +8,14 @@ {{- end -}} {{- end }} +{{- define "posthog.clusterName" }} + {{- if .Values.clusterName -}} + {{- .Values.clusterName -}} + {{- else -}} + cluster + {{- end -}} +{{- end }} + {{- define "snippet.posthog-env" }} - name: SECRET_KEY valueFrom: diff --git a/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl b/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl index 8ef007745..3d7735ef1 100644 --- a/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl +++ b/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl @@ -12,7 +12,7 @@ {{ 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" \ + "http://$CLICKHOUSE_USER:$CLICKHOUSE_PASSWORD@{{ include "posthog.clickhouse.fullname" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.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 }} @@ -22,20 +22,20 @@ done {{ end }} - until (nc -vz "{{ include "posthog.pgbouncer.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local" {{ include "posthog.pgbouncer.port" . }}); + until (nc -vz "{{ include "posthog.pgbouncer.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local" {{ include "posthog.pgbouncer.port" . }}); do echo "waiting for PgBouncer"; sleep 1; done {{ if .Values.postgresql.enabled }} - until (nc -vz "{{ include "posthog.postgresql.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local" {{ include "posthog.postgresql.port" . }}); + until (nc -vz "{{ include "posthog.postgresql.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local" {{ include "posthog.postgresql.port" . }}); do echo "waiting for PostgreSQL"; 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" . }}); + until (nc -vz "{{ include "posthog.redis.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local" {{ include "posthog.redis.port" . }}); do echo "waiting for Redis"; sleep 1; done @@ -48,7 +48,7 @@ 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); + until (nc -vz "$KAFKA_HOST.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local" $KAFKA_PORT); do echo "waiting for Kafka"; sleep 1; done diff --git a/charts/posthog/templates/clickhouse-backup-cronjob.yaml b/charts/posthog/templates/clickhouse-backup-cronjob.yaml index 86a33a105..108cd0546 100644 --- a/charts/posthog/templates/clickhouse-backup-cronjob.yaml +++ b/charts/posthog/templates/clickhouse-backup-cronjob.yaml @@ -34,7 +34,7 @@ spec: - | until ( wget -qO- \ - "http://$CLICKHOUSE_USER:$CLICKHOUSE_PASSWORD@clickhouse-posthog.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local:8123" \ + "http://$CLICKHOUSE_USER:$CLICKHOUSE_PASSWORD@clickhouse-posthog.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local:8123" \ --post-data "SELECT count() FROM clusterAllReplicas('posthog', system, one)" ); do echo "waiting for ClickHouse cluster to become available"; sleep 1; diff --git a/charts/posthog/values.yaml b/charts/posthog/values.yaml index 815f9e3f5..67d23713b 100644 --- a/charts/posthog/values.yaml +++ b/charts/posthog/values.yaml @@ -8,6 +8,9 @@ notificationEmail: # This is used to e.g. generate shareable links to Dashboards. siteUrl: +# -- Cluster name used for internal DNS resolution (svc.{{clusterName}}.local) +clusterName: cluster + image: # -- PostHog image repository to use. repository: posthog/posthog From 6529feda4e84ac5c35520a840c124740d12b1e59 Mon Sep 17 00:00:00 2001 From: Jimmy Bernljung Date: Thu, 17 Nov 2022 11:05:59 +0100 Subject: [PATCH 2/2] Remove redundant template for cluster name as it already has a default value --- charts/posthog/templates/_posthog.tpl | 8 -------- ...et-initContainers-wait-for-service-dependencies.tpl | 10 +++++----- .../posthog/templates/clickhouse-backup-cronjob.yaml | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/charts/posthog/templates/_posthog.tpl b/charts/posthog/templates/_posthog.tpl index 54e3e542e..9110472f4 100644 --- a/charts/posthog/templates/_posthog.tpl +++ b/charts/posthog/templates/_posthog.tpl @@ -8,14 +8,6 @@ {{- end -}} {{- end }} -{{- define "posthog.clusterName" }} - {{- if .Values.clusterName -}} - {{- .Values.clusterName -}} - {{- else -}} - cluster - {{- end -}} -{{- end }} - {{- define "snippet.posthog-env" }} - name: SECRET_KEY valueFrom: diff --git a/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl b/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl index 3d7735ef1..e144cb1ba 100644 --- a/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl +++ b/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl @@ -12,7 +12,7 @@ {{ 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.{{ include "posthog.clusterName" . }}.local:8123" \ + "http://$CLICKHOUSE_USER:$CLICKHOUSE_PASSWORD@{{ include "posthog.clickhouse.fullname" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ .Values.clusterName }}.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 }} @@ -22,20 +22,20 @@ done {{ end }} - until (nc -vz "{{ include "posthog.pgbouncer.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local" {{ include "posthog.pgbouncer.port" . }}); + until (nc -vz "{{ include "posthog.pgbouncer.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ .Values.clusterName }}.local" {{ include "posthog.pgbouncer.port" . }}); do echo "waiting for PgBouncer"; sleep 1; done {{ if .Values.postgresql.enabled }} - until (nc -vz "{{ include "posthog.postgresql.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local" {{ include "posthog.postgresql.port" . }}); + until (nc -vz "{{ include "posthog.postgresql.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ .Values.clusterName }}.local" {{ include "posthog.postgresql.port" . }}); do echo "waiting for PostgreSQL"; sleep 1; done {{ end }} {{ if .Values.redis.enabled }} - until (nc -vz "{{ include "posthog.redis.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local" {{ include "posthog.redis.port" . }}); + until (nc -vz "{{ include "posthog.redis.host" . }}.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ .Values.clusterName }}.local" {{ include "posthog.redis.port" . }}); do echo "waiting for Redis"; sleep 1; done @@ -48,7 +48,7 @@ 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.{{ include "posthog.clusterName" . }}.local" $KAFKA_PORT); + until (nc -vz "$KAFKA_HOST.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ .Values.clusterName }}.local" $KAFKA_PORT); do echo "waiting for Kafka"; sleep 1; done diff --git a/charts/posthog/templates/clickhouse-backup-cronjob.yaml b/charts/posthog/templates/clickhouse-backup-cronjob.yaml index 108cd0546..53a103e0e 100644 --- a/charts/posthog/templates/clickhouse-backup-cronjob.yaml +++ b/charts/posthog/templates/clickhouse-backup-cronjob.yaml @@ -34,7 +34,7 @@ spec: - | until ( wget -qO- \ - "http://$CLICKHOUSE_USER:$CLICKHOUSE_PASSWORD@clickhouse-posthog.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ include "posthog.clusterName" . }}.local:8123" \ + "http://$CLICKHOUSE_USER:$CLICKHOUSE_PASSWORD@clickhouse-posthog.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.{{ .Values.clusterName }}.local:8123" \ --post-data "SELECT count() FROM clusterAllReplicas('posthog', system, one)" ); do echo "waiting for ClickHouse cluster to become available"; sleep 1;