From 9a8ca6fca20bac784ce7f62986bf74aa03ce90a2 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Tue, 7 Mar 2023 18:56:20 +0100 Subject: [PATCH] fix(common): keep postgresql credentials if created previously --- library/common/Chart.yaml | 2 +- library/common/templates/spawner/_cnpg.tpl | 71 ++++++++++++---------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 59fc799a..c3c5d290 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 12.2.23 +version: 12.2.24 diff --git a/library/common/templates/spawner/_cnpg.tpl b/library/common/templates/spawner/_cnpg.tpl index b2af6540..e7e1ac12 100644 --- a/library/common/templates/spawner/_cnpg.tpl +++ b/library/common/templates/spawner/_cnpg.tpl @@ -47,49 +47,54 @@ {{- include "tc.v1.common.class.cnpg.pooler" $ }} {{- end }} - {{/* Inject the required secrets */}} + {{- end }} + + {{- $dbPass := "" }} {{- $dbprevious := lookup "v1" "Secret" $.Release.Namespace ( printf "%s-user" $cnpgValues.name ) }} - {{- if $dbprevious }} - {{- $dbPass = ( index $dbprevious.data "password" ) | b64dec }} - {{- else }} - {{- $dbPass = $cnpgValues.password | default ( randAlphaNum 62 ) }} - {{- end }} + {{- if or $enabled $dbprevious -}} + {{/* Inject the required secrets */}} - {{- $std := ( ( printf "postgresql://%v:%v@%v-rw:5432/%v" $cnpgValues.user $dbPass $cnpgValues.name $cnpgValues.database ) | quote ) }} - {{- $nossl := ( ( printf "postgresql://%v:%v@%v-rw:5432/%v?sslmode=disable" $cnpgValues.user $dbPass $cnpgValues.name $cnpgValues.database ) | quote ) }} - {{- $porthost := ( ( printf "%s-rw:5432" $cnpgValues.name ) | quote ) }} - {{- $host := ( ( printf "%s-rw" $cnpgValues.name ) | quote ) }} - {{- $jdbc := ( ( printf "jdbc:postgresql://%v-rw:5432/%v" $cnpgValues.name $cnpgValues.database ) | quote ) }} + {{- if $dbprevious }} + {{- $dbPass = ( index $dbprevious.data "password" ) | b64dec }} + {{- else }} + {{- $dbPass = $cnpgValues.password | default ( randAlphaNum 62 ) }} + {{- end }} - {{- $userSecret := include "tc.v1.common.lib.cnpg.secret.user" (dict "values" $cnpgValues "dbPass" $dbPass ) | fromYaml }} - {{- if $userSecret }} - {{- $_ := set $.Values.secret ( printf "cnpg-%s-user" $cnpgValues.shortName ) $userSecret }} - {{- end }} + {{- $std := ( ( printf "postgresql://%v:%v@%v-rw:5432/%v" $cnpgValues.user $dbPass $cnpgValues.name $cnpgValues.database ) | quote ) }} + {{- $nossl := ( ( printf "postgresql://%v:%v@%v-rw:5432/%v?sslmode=disable" $cnpgValues.user $dbPass $cnpgValues.name $cnpgValues.database ) | quote ) }} + {{- $porthost := ( ( printf "%s-rw:5432" $cnpgValues.name ) | quote ) }} + {{- $host := ( ( printf "%s-rw" $cnpgValues.name ) | quote ) }} + {{- $jdbc := ( ( printf "jdbc:postgresql://%v-rw:5432/%v" $cnpgValues.name $cnpgValues.database ) | quote ) }} - {{- $urlSecret := include "tc.v1.common.lib.cnpg.secret.urls" (dict "std" $std "nossl" $nossl "porthost" $porthost "host" $host "jdbc" $jdbc) | fromYaml }} - {{- if $urlSecret }} - {{- $_ := set $.Values.secret ( printf "cnpg-%s-urls" $cnpgValues.shortName ) $urlSecret }} - {{- end }} + {{- $userSecret := include "tc.v1.common.lib.cnpg.secret.user" (dict "values" $cnpgValues "dbPass" $dbPass ) | fromYaml }} + {{- if $userSecret }} + {{- $_ := set $.Values.secret ( printf "cnpg-%s-user" $cnpgValues.shortName ) $userSecret }} + {{- end }} - {{- $_ := set $cnpgValues.creds "password" ( $dbPass | quote ) }} - {{- $_ := set $cnpgValues.creds "std" $std }} - {{- $_ := set $cnpgValues.creds "nossl" $nossl }} - {{- $_ := set $cnpgValues.creds "porthost" $porthost }} - {{- $_ := set $cnpgValues.creds "host" $host }} - {{- $_ := set $cnpgValues.creds "jdbc" $jdbc }} + {{- $urlSecret := include "tc.v1.common.lib.cnpg.secret.urls" (dict "std" $std "nossl" $nossl "porthost" $porthost "host" $host "jdbc" $jdbc) | fromYaml }} + {{- if $urlSecret }} + {{- $_ := set $.Values.secret ( printf "cnpg-%s-urls" $cnpgValues.shortName ) $urlSecret }} + {{- end }} - {{- if $cnpgValues.monitoring }} - {{- if $cnpgValues.monitoring.enablePodMonitor }} - {{- $poolermetrics := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" ( printf "%s-rw" $cnpgValues.name) ) | fromYaml }} + {{- $_ := set $cnpgValues.creds "password" ( $dbPass | quote ) }} + {{- $_ := set $cnpgValues.creds "std" $std }} + {{- $_ := set $cnpgValues.creds "nossl" $nossl }} + {{- $_ := set $cnpgValues.creds "porthost" $porthost }} + {{- $_ := set $cnpgValues.creds "host" $host }} + {{- $_ := set $cnpgValues.creds "jdbc" $jdbc }} - {{- $_ := set $.Values.metrics ( printf "cnpg-%s-rw" $cnpgValues.shortName ) $poolermetrics }} - {{- if $cnpgValues.acceptRO }} - {{- $poolermetricsRO := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" ( printf "%s-ro" $cnpgValues.name) ) | fromYaml }} - {{- $_ := set $.Values.metrics ( printf "cnpg-%s-ro" $cnpgValues.shortName ) $poolermetricsRO }} + {{- if $cnpgValues.monitoring }} + {{- if $cnpgValues.monitoring.enablePodMonitor }} + {{- $poolermetrics := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" ( printf "%s-rw" $cnpgValues.name) ) | fromYaml }} + + {{- $_ := set $.Values.metrics ( printf "cnpg-%s-rw" $cnpgValues.shortName ) $poolermetrics }} + {{- if $cnpgValues.acceptRO }} + {{- $poolermetricsRO := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" ( printf "%s-ro" $cnpgValues.name) ) | fromYaml }} + {{- $_ := set $.Values.metrics ( printf "cnpg-%s-ro" $cnpgValues.shortName ) $poolermetricsRO }} + {{- end }} {{- end }} {{- end }} - {{- end }} {{- end }} {{- end }}