Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 13 additions & 3 deletions charts/sourcebot/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/}}
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions charts/sourcebot/tests/basic_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading