diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index 832e4b6f..8686baeb 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -3,7 +3,7 @@ appVersion: "" dependencies: - name: common repository: file://../common - version: ~12.1.0 + version: ~12.2.0 deprecated: false description: Helper chart to test different use cases of the common library home: https://github.com/truecharts/apps/tree/master/charts/library/common-test diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 0750be71..3214ccfc 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 12.1.0 +version: 12.2.0 diff --git a/library/common/templates/class/_cnpgCluster.tpl b/library/common/templates/class/_cnpgCluster.tpl index b96b6821..0095707a 100644 --- a/library/common/templates/class/_cnpgCluster.tpl +++ b/library/common/templates/class/_cnpgCluster.tpl @@ -31,8 +31,18 @@ spec: superuserSecret: name: {{ $cnpgClusterName }}-superuser + {{- $basename := include "tc.v1.common.lib.chart.names.fullname" $ -}} + {{- $fetchname := printf "%s-dbcreds" $basename -}} + {{- $olddbprevious1 := lookup "v1" "Secret" .Release.Namespace $fetchname }} + {{- $olddbprevious2 := lookup "v1" "Secret" .Release.Namespace "dbcreds" }} + bootstrap: + {{- if and $.Values.postgresql.enabled ( or $olddbprevious1 $olddbprevious2 ) $.Release.IsUpgrade }} + pg_basebackup: + source: old-db + {{- else }} initdb: + {{- end }} database: {{ $values.database | default "app" }} owner: {{ $values.user | default "app" }} secret: @@ -69,4 +79,15 @@ spec: inProgress: false reusePVC: on + externalClusters: + {{- if and $.Values.postgresql.enabled ( or $olddbprevious1 $olddbprevious2 ) $.Release.IsUpgrade }} + - name: old-db + connectionParameters: + host: {{ (printf "%v-%v" .Release.Name "postgresql" ) }} + user: postgres + password: + name: {{ $cnpgClusterName }}-superuser + key: password + {{- end }} + {{- end -}} diff --git a/library/common/templates/spawner/_cnpg.tpl b/library/common/templates/spawner/_cnpg.tpl index 90bc0fd5..9123805b 100644 --- a/library/common/templates/spawner/_cnpg.tpl +++ b/library/common/templates/spawner/_cnpg.tpl @@ -26,11 +26,21 @@ {{- include "tc.v1.common.class.cnpg.pooler" $ -}} {{- end }} + {{- $basename := include "tc.v1.common.lib.chart.names.fullname" $ -}} + {{- $fetchname := printf "%s-dbcreds" $basename -}} + {{- $olddbprevious1 := lookup "v1" "Secret" $.Release.Namespace $fetchname }} + {{- $olddbprevious2 := lookup "v1" "Secret" $.Release.Namespace "dbcreds" }} + + {{/* Inject the required secrets */}} {{- $dbPass := "" }} {{- $dbprevious := lookup "v1" "Secret" $.Release.Namespace ( printf "%s-user" $cnpgValues.name ) }} {{- if $dbprevious }} {{- $dbPass = ( index $dbprevious.data "user-password" ) | b64dec }} + {{- else if and $.Values.postgresql.enabled $olddbprevious1 $.Release.IsUpgrade }} + {{- $dbPass = ( index $olddbprevious1.data "postgresql-password" ) | b64dec }} + {{- else if and $.Values.postgresql.enabled $olddbprevious2 $.Release.IsUpgrade }} + {{- $dbPass = ( index $olddbprevious2.data "postgresql-password" ) | b64dec }} {{- else }} {{- $dbPass = $cnpgValues.password | default ( randAlphaNum 62 ) }} {{- end }} @@ -39,6 +49,10 @@ {{- $pgprevious := lookup "v1" "Secret" $.Release.Namespace ( printf "%s-superuser" $cnpgValues.name ) }} {{- if $pgprevious }} {{- $pgPass = ( index $dbprevious.data "superuser-password" ) | b64dec }} + {{- else if and $.Values.postgresql.enabled $olddbprevious1 $.Release.IsUpgrade }} + {{- $pgPass = ( index $olddbprevious1.data "postgresql-postgres-password" ) | b64dec }} + {{- else if and $.Values.postgresql.enabled $olddbprevious2 $.Release.IsUpgrade }} + {{- $pgPass = ( index $olddbprevious2.data "postgresql-postgres-password" ) | b64dec }} {{- else }} {{- $pgPass = $cnpgValues.superUserPassword | default ( randAlphaNum 62 ) }} {{- end }}