diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index 0027efd9..716846a2 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: ~19.0.0 + version: ~19.1.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 1ca5dfc2..d8a38ebf 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,7 +15,7 @@ maintainers: name: common sources: null type: library -version: 19.0.0 +version: 19.1.0 annotations: artifacthub.io/category: "integration-delivery" artifacthub.io/license: "BUSL-1.1" diff --git a/library/common/templates/class/cnpg/_cluster.tpl b/library/common/templates/class/cnpg/_cluster.tpl index 38104434..9f42493d 100644 --- a/library/common/templates/class/cnpg/_cluster.tpl +++ b/library/common/templates/class/cnpg/_cluster.tpl @@ -132,6 +132,17 @@ {{- $walAccessModes = . -}} {{- end -}} + {{/* Ensure version and container tracking */}} + {{- $imageType := camelcase ( $objectData.type | default "postgres" ) }} + {{- if eq $imageType "Postgres" }} + {{- $imageType = "" }} + {{- end }} + {{- $imageKey := printf "postgres%v%vImage" $imageType $objectData.pgversion }} + {{- $imageValue := fromJson (include "tc.v1.common.lib.container.imageSelector" (dict "rootCtx" $rootCtx "objectData" (dict "imageSelector" $imageKey))) }} + {{- $formatImage := printf "%s:%s" $imageValue.repository $imageValue.tag }} + + {{- $imageName := $objectData.cluster.imageName | default $formatImage }} + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "clusters.postgresql.cnpg.io" "missing" "CloudNative-PG") }} --- @@ -154,6 +165,7 @@ metadata: {{- . | nindent 4 }} {{- end }} spec: + imageName: {{ $imageName }} enableSuperuserAccess: {{ $enableSuperUser }} primaryUpdateStrategy: {{ $primaryUpdateStrategy }} primaryUpdateMethod: {{ $primaryUpdateMethod }} diff --git a/library/common/templates/lib/cnpg/_clusterName.tpl b/library/common/templates/lib/cnpg/_clusterName.tpl deleted file mode 100644 index e756b2c2..00000000 --- a/library/common/templates/lib/cnpg/_clusterName.tpl +++ /dev/null @@ -1,20 +0,0 @@ -{{- define "tc.v1.common.lib.cnpg.clusterName" -}} - {{- $objectData := .objectData -}} - - {{- if not $objectData.version -}} - {{- $_ := set $objectData "version" "legacy" -}} - {{- end -}} - - {{- $clusterName := $objectData.name -}} - {{/* Append version to the cluster name if available */}} - {{- if ne $objectData.version "legacy" -}} - {{- $clusterName = printf "%s-%v" $objectData.name $objectData.version -}} - {{- end -}} - - {{/* Append the recovery string to the cluster name if available */}} - {{- if $objectData.recValue -}} - {{- $clusterName = printf "%s-%s" $clusterName $objectData.recValue -}} - {{- end -}} - - {{- $clusterName -}} -{{- end -}} diff --git a/library/common/templates/lib/cnpg/_pgVersion.tpl b/library/common/templates/lib/cnpg/_pgVersion.tpl new file mode 100644 index 00000000..b5ea961c --- /dev/null +++ b/library/common/templates/lib/cnpg/_pgVersion.tpl @@ -0,0 +1,6 @@ +{{- define "tc.v1.common.lib.cnpg.configmap.pgversion" -}} +{{- $major := .major -}} +enabled: true +data: + major: {{ $major }} +{{- end -}} diff --git a/library/common/templates/lib/cnpg/_recoveryValue.tpl b/library/common/templates/lib/cnpg/_recoveryValue.tpl deleted file mode 100644 index fde6c442..00000000 --- a/library/common/templates/lib/cnpg/_recoveryValue.tpl +++ /dev/null @@ -1,7 +0,0 @@ -{{- define "tc.v1.common.lib.cnpg.configmap.recoverystring" -}} - {{- $recoveryString := .recoveryString -}} - {{- $recoveryKey := .recoveryKey -}} -enabled: true -data: - {{ $recoveryKey }}: {{ $recoveryString }} -{{- end -}} diff --git a/library/common/templates/lib/cnpg/cluster/_validation.tpl b/library/common/templates/lib/cnpg/cluster/_validation.tpl index e6e05c97..98f08c4d 100644 --- a/library/common/templates/lib/cnpg/cluster/_validation.tpl +++ b/library/common/templates/lib/cnpg/cluster/_validation.tpl @@ -9,8 +9,8 @@ {{- end -}} {{- if (hasKey $objectData "version") -}} - {{- $validVersions := (list "legacy") -}} - {{- if not (mustHas $objectData.version $validVersions) -}} + {{- $validVersions := (list "15" "16") -}} + {{- if not (mustHas ( toString $objectData.version ) $validVersions) -}} {{- fail (printf "CNPG - Expected [version] to be one of [%s], but got [%s]" (join ", " $validVersions) $objectData.version) -}} {{- end -}} {{- end -}} @@ -35,7 +35,7 @@ {{- end -}} {{- if (hasKey $objectData "type") -}} - {{- $validTypes := (list "postgresql" "postgis" "timescaledb") -}} + {{- $validTypes := (list "postgres" "postgis" "timescaledb") -}} {{- if not (mustHas $objectData.type $validTypes) -}} {{- fail (printf "CNPG Cluster - Expected [type] to be one of [%s], but got [%s]" (join ", " $validTypes) $objectData.type) -}} {{- end -}} diff --git a/library/common/templates/spawner/_cnpg.tpl b/library/common/templates/spawner/_cnpg.tpl index fa437ff3..31b13ba9 100644 --- a/library/common/templates/spawner/_cnpg.tpl +++ b/library/common/templates/spawner/_cnpg.tpl @@ -19,32 +19,31 @@ {{/* Short name is the one that defined on the chart*/}} {{- $_ := set $objectData "shortName" $name -}} {{/* Set the cluster name */}} - {{- $_ := set $objectData "clusterName" (include "tc.v1.common.lib.cnpg.clusterName" (dict "objectData" $objectData)) -}} - - {{/* Handle recovery string */}} - {{- $recoveryValue := "" -}} - {{- $recoveryKey := "recovery-string" -}} - {{- $recoveryConfigMapName := printf "cnpg-%s-%s" $objectData.shortName $recoveryKey -}} - - {{/* If there are previous configmap, fetch value */}} - {{- with (lookup "v1" "ConfigMap" $.Release.Namespace $recoveryConfigMapName) -}} - {{- $recoveryValue = (index .data $recoveryKey) -}} - {{- end -}} - - {{/* If forced recovery is requested... */}} - {{- if $objectData.forceRecovery -}} - {{- $recoveryValue = randAlphaNum 5 -}} - {{- end -}} - - {{/* Recreate the configmap if there is a recovery value */}} - {{- if $recoveryValue -}} - {{- $_ := set $objectData "recoveryValue" $recoveryValue -}} - {{- $recConfig := include "tc.v1.common.lib.cnpg.configmap.recoverystring" (dict "recoveryString" $recoveryValue "recoveryKey" $recoveryKey) | fromYaml -}} - {{- $_ := set $.Values.configmap $recoveryConfigMapName $recConfig -}} - {{- end -}} + {{- $_ := set $objectData "clusterName" $objectData.name -}} {{- if eq $enabled "true" -}} + {{/* Handle version string */}} + {{- $pgversion := toString ( $objectData.version | default $.Values.global.fallbackDefaults.pgversion ) -}} + {{- $versionConfigMapName := printf "cnpg-%s-pgversion" $objectData.shortName -}} + + {{/* If there are previous configmap, fetch value */}} + {{- with (lookup "v1" "ConfigMap" $.Release.Namespace $versionConfigMapName) -}} + {{/* If a new major is set and upgrade is enabled, upgrade */}} + {{- if and ( ne $pgversion .data.major ) $objectData.upgradeMajor -}} + {{/* TODO handle postgresql major updates here */}} + {{- else if .data.major -}} + {{- $pgversion = ( toString .data.major ) -}} + {{- end -}} + {{- end -}} + + {{/* append the pg (major) version to objectData */}} + {{- $_ := set $objectData "pgversion" $pgversion -}} + + {{/* ensure configmap with pg version is updated */}} + {{- $verConfig := include "tc.v1.common.lib.cnpg.configmap.pgversion" (dict "major" $pgversion ) | fromYaml -}} + {{- $_ := set $.Values.configmap $versionConfigMapName $verConfig -}} + {{- include "tc.v1.common.lib.util.metaListToDict" (dict "objectData" $objectData) -}} {{/* Handle Backups/ScheduledBackups */}} diff --git a/library/common/values.yaml b/library/common/values.yaml index 870e947f..3af1d6d7 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -7,6 +7,11 @@ global: # -- Set a global namespace # TODO: Currently some objects do not support this namespace: "" + fallbackDefaults: + # -- Define a postgresql version for CNPG + # will be used for all CNPG objects + # Can be overruled per CNPG objects + pgversion: 16 metallb: # -- Adds metalLB annotations to services addServiceAnnotations: true @@ -504,6 +509,36 @@ mongodbClientImage: tag: v1.1.0@sha256:9268e23927c4abd9bd031ef62a8a36c58e15361cf3f617906029fa4b6f25c71c pullPolicy: IfNotPresent +postgres15Image: + repository: ghcr.io/cloudnative-pg/postgresql + tag: '15.6' + pullPolicy: IfNotPresent + +postgres16Image: + repository: ghcr.io/cloudnative-pg/postgresql + tag: '16.2' + pullPolicy: IfNotPresent + +postgresPostgis15Image: + repository: ghcr.io/cloudnative-pg/postgis + tag: "15-3.4" + pullPolicy: IfNotPresent + +postgresPostgis16Image: + repository: ghcr.io/cloudnative-pg/postgis + tag: "16-3.4" + pullPolicy: IfNotPresent + +postgresVectors15Image: + repository: ghcr.io/tensorchord/cloudnative-pgvecto.rs + tag: "15.6-v0.2.1" + pullPolicy: IfNotPresent + +postgresVectors16Image: + repository: ghcr.io/tensorchord/cloudnative-pgvecto.rs + tag: "16.2-v0.2.1" + pullPolicy: IfNotPresent + # -- OpenVPN specific configuration # @default -- See below openvpnImage: @@ -1043,20 +1078,17 @@ cnpg: labels: {} annotations: {} - # -- Destroys the current cluster to forge a new cluster or recovery operation - # ABSOLUTELY DESTRUCTIVE - forceRecovery: false - # Type of the CNPG database. Available types: - # * `postgresql` + # * `postgres` # * `postgis` # * `timescaledb` - type: postgresql + # * `vectors` + type: postgres # Version of Postgresql to use, changes cluster naming scheme - # * `legacy` - # TODO: allow for selecting other versions - version: legacy + # * `15` + # * `16` + version: 16 # Cluster mode of operation. Available modes: # * `standalone` - default mode. Creates new or updates an existing CNPG cluster.