From 6289bfa9a68c768e96615a9920dbf2e9d9c75bcc Mon Sep 17 00:00:00 2001 From: Felipe Galindo Sanchez Date: Thu, 5 Oct 2023 13:32:09 -0700 Subject: [PATCH 1/2] fix pgbouncer connection with useStandardNaming 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 --- .../secrets/metadata-connection-secret.yaml | 2 +- .../airflow_aux/test_basic_helm_chart.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/chart/templates/secrets/metadata-connection-secret.yaml b/chart/templates/secrets/metadata-connection-secret.yaml index 7f9840f9db197..b2622180d03f7 100644 --- a/chart/templates/secrets/metadata-connection-secret.yaml +++ b/chart/templates/secrets/metadata-connection-secret.yaml @@ -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) }} diff --git a/helm_tests/airflow_aux/test_basic_helm_chart.py b/helm_tests/airflow_aux/test_basic_helm_chart.py index 7eb786d39bc01..23fc1edbb238f 100644 --- a/helm_tests/airflow_aux/test_basic_helm_chart.py +++ b/helm_tests/airflow_aux/test_basic_helm_chart.py @@ -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( From 0adc87952690b50caea15cd0c781e215e931a52f Mon Sep 17 00:00:00 2001 From: Felipe Galindo Sanchez Date: Thu, 5 Oct 2023 14:42:53 -0700 Subject: [PATCH 2/2] fix static check --- helm_tests/airflow_aux/test_basic_helm_chart.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/helm_tests/airflow_aux/test_basic_helm_chart.py b/helm_tests/airflow_aux/test_basic_helm_chart.py index 23fc1edbb238f..5cdf1c7e98777 100644 --- a/helm_tests/airflow_aux/test_basic_helm_chart.py +++ b/helm_tests/airflow_aux/test_basic_helm_chart.py @@ -580,10 +580,10 @@ def test_postgres_connection_url_pgbouncer(self): 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" + 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): @@ -593,10 +593,10 @@ def test_postgres_connection_url_pgbouncer_use_standard_naming(self): 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" + 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):