diff --git a/charts/sourcebot/templates/_helpers.tpl b/charts/sourcebot/templates/_helpers.tpl index 682a10a..568e1f6 100644 --- a/charts/sourcebot/templates/_helpers.tpl +++ b/charts/sourcebot/templates/_helpers.tpl @@ -89,6 +89,18 @@ Return PostgreSQL hostname {{- end }} {{- end }} +{{/* +Return PostgreSQL address, preserving a port already included in the hostname +*/}} +{{- define "sourcebot.postgresql.address" -}} +{{- $hostname := include "sourcebot.postgresql.hostname" . -}} +{{- if regexMatch `^([^:]+|\[[^]]+\]):[0-9]+$` $hostname -}} +{{- $hostname -}} +{{- else -}} +{{- printf "%s:%v" $hostname .Values.postgresql.port -}} +{{- end -}} +{{- end }} + {{/* Return Redis hostname */}} @@ -122,9 +134,7 @@ These will be assembled into DATABASE_URL by the entrypoint.sh script */}} {{- define "sourcebot.databaseEnv" -}} - name: DATABASE_HOST - value: {{ include "sourcebot.postgresql.hostname" . | quote }} -- name: DATABASE_PORT - value: {{ .Values.postgresql.port | quote }} + value: {{ include "sourcebot.postgresql.address" . | quote }} - name: DATABASE_USERNAME value: {{ .Values.postgresql.auth.username | quote }} - name: DATABASE_PASSWORD diff --git a/charts/sourcebot/tests/basic_test.yaml b/charts/sourcebot/tests/basic_test.yaml index 01717de..69d8555 100644 --- a/charts/sourcebot/tests/basic_test.yaml +++ b/charts/sourcebot/tests/basic_test.yaml @@ -122,6 +122,56 @@ tests: value: 3 template: deployment.yaml + - it: should include the PostgreSQL port in the bundled database host + values: + - ../values.lint.yaml + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: DATABASE_HOST + value: RELEASE-NAME-sourcebot-postgresql:5432 + template: deployment.yaml + - notContains: + path: spec.template.spec.containers[0].env + content: + name: DATABASE_PORT + template: deployment.yaml + + - it: should include a custom PostgreSQL port in the external database host + values: + - ../values.lint.yaml + set: + postgresql.deploy: false + postgresql.host: db.example.test + postgresql.port: 6543 + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: DATABASE_HOST + value: db.example.test:6543 + template: deployment.yaml + - notContains: + path: spec.template.spec.containers[0].env + content: + name: DATABASE_PORT + template: deployment.yaml + + - it: should preserve a port already included in the external database host + values: + - ../values.lint.yaml + set: + postgresql.deploy: false + postgresql.host: db.example.test:6543 + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: DATABASE_HOST + value: db.example.test:6543 + template: deployment.yaml + - it: should mount persistence volume when enabled values: - ../values.lint.yaml