Skip to content

Commit

Permalink
Merge pull request #324 from bci-oss/feature/configurable-postgres-va…
Browse files Browse the repository at this point in the history
…riables

configurable postgres variable
  • Loading branch information
tunacicek authored Feb 19, 2024
2 parents 87f0e5d + 9b9e449 commit 99834f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion charts/registry/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sources:
- https://github.com/eclipse-tractusx/sldt-digital-twin-registry

type: application
version: 0.4.3
version: 0.4.4
appVersion: 0.3.23

dependencies:
Expand Down
18 changes: 17 additions & 1 deletion charts/registry/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,20 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- define "dtr.selectorLabels" -}}
app.kubernetes.io/name: {{ include "dtr.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- end }}

{{/*
Determine database hostname
*/}}
{{- define "dtr.postgres.primary.fullname" -}}
{{- if .Values.postgresql.fullnameOverride -}}
{{- .Values.postgresql.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default "postgresql" .Values.postgresql.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
6 changes: 3 additions & 3 deletions charts/registry/templates/registry/postgres-init.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data:
{{- $password:= ( .Values.postgresql.auth.password | b64enc) | default ( index $secret.data "password" ) | quote }}
password: {{ $password }}
SPRING_DATASOURCE_PASSWORD: {{ $password }}
SPRING_DATASOURCE_URL: {{ printf "jdbc:postgresql://%s-postgresql:%v/%s" .Release.Name .Values.postgresql.service.ports.postgresql .Values.postgresql.auth.database | b64enc }}
SPRING_DATASOURCE_URL: {{ printf "jdbc:postgresql://%s:%v/%s" (include "dtr.postgres.primary.fullname" .) .Values.postgresql.service.ports.postgresql .Values.postgresql.auth.database | b64enc }}
SPRING_DATASOURCE_USERNAME: {{ .Values.postgresql.auth.username | b64enc }}
# 2. Check if default postgresql secret (Release.Name-postgresql) exists
{{ else if $defaultSecret -}}
Expand All @@ -45,7 +45,7 @@ data:
{{- $password:= ( .Values.postgresql.auth.password | b64enc) | default ( index $defaultSecret.data "password" ) | quote }}
password: {{ $password }}
SPRING_DATASOURCE_PASSWORD: {{ $password }}
SPRING_DATASOURCE_URL: {{ printf "jdbc:postgresql://%s-postgresql:%v/%s" .Release.Name .Values.postgresql.service.ports.postgresql .Values.postgresql.auth.database | b64enc }}
SPRING_DATASOURCE_URL: {{ printf "jdbc:postgresql://%s:%v/%s" (include "dtr.postgres.primary.fullname" .) .Values.postgresql.service.ports.postgresql .Values.postgresql.auth.database | b64enc }}
SPRING_DATASOURCE_USERNAME: {{ .Values.postgresql.auth.username | b64enc }}
{{ else -}}
# 3. If no secret exists, use provided value from values file or generate a random one if secret not exists.
Expand All @@ -54,7 +54,7 @@ stringData:
postgres-password: {{ $password }}
password: {{ $password }}
SPRING_DATASOURCE_PASSWORD: {{ $password }}
SPRING_DATASOURCE_URL: {{ printf "jdbc:postgresql://%s-postgresql:%v/%s" .Release.Name .Values.postgresql.service.ports.postgresql .Values.postgresql.auth.database }}
SPRING_DATASOURCE_URL: {{ printf "jdbc:postgresql://%s:%v/%s" (include "dtr.postgres.primary.fullname" .) .Values.postgresql.service.ports.postgresql .Values.postgresql.auth.database }}
SPRING_DATASOURCE_USERNAME: {{ .Values.postgresql.auth.username }}
{{ end }}
{{- end -}}

0 comments on commit 99834f7

Please sign in to comment.