Skip to content

Commit

Permalink
Chart: Fix pgbouncer connection with useStandardNaming (#34787)
Browse files Browse the repository at this point in the history
PR #31066 introduced a new option to standardize the naming of the different helm chart resources.
However this didn't include also updating the reference when creating the pgbouncer connection in the
metadata secret. This PR fixes that and makes sure we use the proper hostname for pgbouncer based on
the new option useStandardNaming
  • Loading branch information
fgalind1 committed Oct 5, 2023
1 parent a1a2352 commit 59ed537
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chart/templates/secrets/metadata-connection-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{- if not .Values.data.metadataSecretName }}
{{- $defaultMetadataHost := .Values.postgresql.nameOverride | default (printf "%s-%s.%s" .Release.Name "postgresql" .Release.Namespace) }}
{{- $metadataHost := .Values.data.metadataConnection.host | default $defaultMetadataHost }}
{{- $pgbouncerHost := (printf "%s-%s.%s" .Release.Name "pgbouncer" .Release.Namespace) }}
{{- $pgbouncerHost := (printf "%s-%s.%s" ( include "airflow.fullname" . ) "pgbouncer" .Release.Namespace) }}
{{- $host := ternary $pgbouncerHost $metadataHost .Values.pgbouncer.enabled }}
{{- $port := ((ternary .Values.ports.pgbouncer .Values.data.metadataConnection.port .Values.pgbouncer.enabled) | toString) }}
{{- $database := (ternary (printf "%s-%s" .Release.Name "metadata") .Values.data.metadataConnection.db .Values.pgbouncer.enabled) }}
Expand Down
26 changes: 26 additions & 0 deletions helm_tests/airflow_aux/test_basic_helm_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,32 @@ def test_postgres_connection_url_no_override(self):
== base64.b64decode(doc["data"]["connection"]).decode("utf-8")
)

def test_postgres_connection_url_pgbouncer(self):
# no nameoverride, pgbouncer
doc = render_chart(
"my-release",
show_only=["templates/secrets/metadata-connection-secret.yaml"],
values={"pgbouncer": {"enabled": True}},
)[0]
assert (
"postgresql://postgres:postgres@my-release-pgbouncer.default:6543/"
"my-release-metadata?sslmode=disable"
== base64.b64decode(doc["data"]["connection"]).decode("utf-8")
)

def test_postgres_connection_url_pgbouncer_use_standard_naming(self):
# no nameoverride, pgbouncer and useStandardNaming
doc = render_chart(
"my-release",
show_only=["templates/secrets/metadata-connection-secret.yaml"],
values={"useStandardNaming": True, "pgbouncer": {"enabled": True}},
)[0]
assert (
"postgresql://postgres:postgres@my-release-airflow-pgbouncer.default:6543/"
"my-release-metadata?sslmode=disable"
== base64.b64decode(doc["data"]["connection"]).decode("utf-8")
)

def test_postgres_connection_url_name_override(self):
# nameoverride provided
doc = render_chart(
Expand Down

0 comments on commit 59ed537

Please sign in to comment.