Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm deployment fails when postgresql.nameOverride is used #29214

Merged
merged 18 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions chart/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,14 @@ Where `.` is the global variables scope and `.Values.workers` the local variable
{{- end }}
{{- end }}
{{- end }}

{{/*
Helper to get the postgresql connection string conditionally
*/}}
{{- define "airflow.default.postgres.connection.string" -}}
{{- if .Values.postgresql.nameOverride }}
{{- printf "%s" .Values.postgresql.nameOverride }}
{{- else }}
{{- printf "%s-%s.%s" .Release.Name "postgresql" .Release.Namespace }}
{{- end }}
{{- end }}
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 @@ -19,7 +19,7 @@
## Airflow Metadata Secret
#################################
{{- if not .Values.data.metadataSecretName }}
{{- $metadataHost := .Values.data.metadataConnection.host | default (printf "%s-%s.%s" .Release.Name "postgresql" .Release.Namespace) }}
{{- $metadataHost := .Values.data.metadataConnection.host | default (include "airflow.default.postgres.connection.string" .) }}
jedcunningham marked this conversation as resolved.
Show resolved Hide resolved
{{- $pgbouncerHost := (printf "%s-%s.%s" .Release.Name "pgbouncer" .Release.Namespace) }}
{{- $host := ternary $pgbouncerHost $metadataHost .Values.pgbouncer.enabled }}
{{- $port := ((ternary .Values.ports.pgbouncer .Values.data.metadataConnection.port .Values.pgbouncer.enabled) | toString) }}
Expand Down
32 changes: 32 additions & 0 deletions tests/charts/test_basic_helm_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,35 @@ def test_invalid_dags_access_mode(self):
def test_namespace_names(self, namespace):
"""Test various namespace names to make sure they render correctly in templates"""
render_chart(namespace=namespace)


def test_postgres_connection_url_no_override(self):
# no nameoverride provided
assert "postgresql://postgres:postgres@my-release-postgresql.default:5432/postgres?sslmode=disable" == \
render_chart(
"my-release",
values={
"postgresql": {
"enabled": True,
}
},
show_only=[
"templates/secrets/metadata-connection-secret.yaml"
]
)["data"]["connection"]
amoghrajesh marked this conversation as resolved.
Show resolved Hide resolved


def test_postgres_connection_url_name_override(self):
assert "postgresql://postgres:postgres@overrideName:5432/postgres?sslmode=disable" == \
render_chart(
"my-release",
values={
"postgresql": {
"enabled": True,
"nameOverride": "overrideName"
}
},
show_only=[
"templates/secrets/metadata-connection-secret.yaml"
]
)["data"]["connection"]