From 34896d302e01a509b76a9ff3e7ad6457958311dc Mon Sep 17 00:00:00 2001 From: Guido Iaquinti Date: Wed, 23 Nov 2022 11:06:37 +0100 Subject: [PATCH] PgBouncer: use service FQDN --- charts/posthog/templates/_pgbouncer.tpl | 17 ++++++++++++++--- ...Containers-wait-for-service-dependencies.tpl | 2 +- charts/posthog/values.yaml | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/charts/posthog/templates/_pgbouncer.tpl b/charts/posthog/templates/_pgbouncer.tpl index 3b16beb25..0d91a95d2 100644 --- a/charts/posthog/templates/_pgbouncer.tpl +++ b/charts/posthog/templates/_pgbouncer.tpl @@ -1,14 +1,25 @@ -{{/* Common pgbouncer helpers used by PostHog */}} +{{/* Common PgBouncer helpers used by PostHog */}} {{/* -Set pgbouncer host +Set PgBouncer FQDN +*/}} +{{- define "posthog.pgbouncer.fqdn" -}} + {{- $fullname := include "posthog.fullname" . -}} + {{- $serviceName := printf "%s-pgbouncer" $fullname -}} + {{- $releaseNamespace := .Release.Namespace -}} + {{- $clusterDomain := .Values.clusterDomain -}} + {{- printf "%s.%s.svc.%s" $serviceName $releaseNamespace $clusterDomain -}} +{{- end -}} + +{{/* +Set PgBouncer host */}} {{- define "posthog.pgbouncer.host" -}} {{- template "posthog.fullname" . }}-pgbouncer {{- end -}} {{/* -Set pgbouncer port +Set PgBouncer port */}} {{- define "posthog.pgbouncer.port" -}} 6543 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..1a8cc83f3 100644 --- a/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl +++ b/charts/posthog/templates/_snippet-initContainers-wait-for-service-dependencies.tpl @@ -22,7 +22,7 @@ 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.fqdn" . }}" {{ include "posthog.pgbouncer.port" . }}); do echo "waiting for PgBouncer"; sleep 1; done diff --git a/charts/posthog/values.yaml b/charts/posthog/values.yaml index 42df9d726..94e2803af 100644 --- a/charts/posthog/values.yaml +++ b/charts/posthog/values.yaml @@ -2579,3 +2579,7 @@ busybox: ## - myRegistryKeySecretName ## pullSecrets: [] + + +# -- Kubernetes cluster domain name +clusterDomain: cluster.local