From 30781eb54ce910392b66445fe46c9034bae48d54 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Mon, 7 Apr 2025 22:19:42 +0200 Subject: [PATCH] feat(common): BREAKING CHANGE allow gitops cnpg recovery without editing values (#33786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** Currently CNPG requires backup and recovery revision to be different As CNPG errors out when you try to backup towards a target that was used by an old instance of the cluster/app. This patch adds an annotation that disables this check on the CNPG level. Which means CNPG-backed applications can be recovered and backed-up in a gitops compatible way, just like volsync. Just configure backup and restore to the same settings and let it rip. If users want extra security, as this feature disables a security precaution, users should think about enabling s3 snapshots as well. **โš™๏ธ Type of change** - [x] โš™๏ธ Feature/App addition - [ ] ๐Ÿช› Bugfix - [x] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [x] ๐Ÿ”ƒ Refactor of current code - [ ] ๐Ÿ“œ Documentation Changes **๐Ÿงช How Has This Been Tested?** **๐Ÿ“ƒ Notes:** It also moves around the pgVersion fallbackDefault, which is technically a breaking change **โœ”๏ธ Checklist:** - [ ] โš–๏ธ My code follows the style guidelines of this project - [ ] ๐Ÿ‘€ I have performed a self-review of my own code - [ ] #๏ธโƒฃ I have commented my code, particularly in hard-to-understand areas - [ ] ๐Ÿ“„ I have made changes to the documentation - [ ] ๐Ÿงช I have added tests to this description that prove my fix is effective or that my feature works - [ ] โฌ†๏ธ I increased versions for any altered app according to semantic versioning - [ ] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):`, `chore(chart-name):`, `docs(chart-name):` or `fix(docs):` **โž• App addition** If this PR is an app addition please make sure you have done the following. - [ ] ๐Ÿ–ผ๏ธ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Signed-off-by: Kjeld Schouten --- .../library/common-test/tests/cnpg/cluster_spec_test.yaml | 3 ++- charts/library/common/templates/class/cnpg/_cluster.tpl | 6 ++++++ charts/library/common/templates/spawner/_cnpg.tpl | 2 +- charts/library/common/values.yaml | 8 +++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/charts/library/common-test/tests/cnpg/cluster_spec_test.yaml b/charts/library/common-test/tests/cnpg/cluster_spec_test.yaml index ce0f4dd929b..d633c04242c 100644 --- a/charts/library/common-test/tests/cnpg/cluster_spec_test.yaml +++ b/charts/library/common-test/tests/cnpg/cluster_spec_test.yaml @@ -147,7 +147,8 @@ tests: tag: "15.6" global: fallbackDefaults: - pgVersion: 15 + cnpg: + pgVersion: 15 vctAccessModes: - ReadWriteMany - ReadWriteOnce diff --git a/charts/library/common/templates/class/cnpg/_cluster.tpl b/charts/library/common/templates/class/cnpg/_cluster.tpl index a949fff4cdd..ffc1b6ef6b0 100644 --- a/charts/library/common/templates/class/cnpg/_cluster.tpl +++ b/charts/library/common/templates/class/cnpg/_cluster.tpl @@ -24,6 +24,7 @@ {{- $logLevel := "info" -}} {{- $accessModes := $rootCtx.Values.global.fallbackDefaults.vctAccessModes -}} {{- $walAccessModes := $rootCtx.Values.global.fallbackDefaults.vctAccessModes -}} + {{- $skipEmptyWalArchiveCheck := $rootCtx.Values.global.fallbackDefaults.cnpg.skipEmptyWalArchiveCheck -}} {{/* Make sure keys exist before try to access any sub keys */}} {{- if not (hasKey $objectData "cluster") -}} @@ -140,6 +141,10 @@ {{- $walAccessModes = . -}} {{- end -}} + {{- with $objectData.cluster.skipEmptyWalArchiveCheck -}} + {{- $skipEmptyWalArchiveCheck = . -}} + {{- end -}} + {{- $imageName := $objectData.cluster.imageName -}} {{- if not $imageName -}} {{/* Ensure version and container tracking */}} @@ -171,6 +176,7 @@ metadata: annotations: cnpg.io/hibernation: {{ $hibernation | quote }} checksum/secrets: {{ toJson $rootCtx.Values.secret | sha256sum }} + cnpg.io/skipEmptyWalArchiveCheck: $skipEmptyWalArchiveCheck {{- $annotations := (mustMerge $clusterAnnotations (include "tc.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }} {{- . | nindent 4 }} diff --git a/charts/library/common/templates/spawner/_cnpg.tpl b/charts/library/common/templates/spawner/_cnpg.tpl index 0387f079160..40a0b11533e 100644 --- a/charts/library/common/templates/spawner/_cnpg.tpl +++ b/charts/library/common/templates/spawner/_cnpg.tpl @@ -24,7 +24,7 @@ {{- if eq $enabled "true" -}} {{/* Handle version string */}} - {{- $pgVersion := ($objectData.pgVersion | default $.Values.global.fallbackDefaults.pgVersion) | toString -}} + {{- $pgVersion := ($objectData.pgVersion | default $.Values.global.fallbackDefaults.cnpg.pgVersion) | toString -}} {{/* Set the updated pgVersion version to objectData */}} {{- $_ := set $objectData "pgVersion" $pgVersion -}} diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index 84bfe163674..dedad3616dd 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -56,10 +56,13 @@ global: # -- Define a postgresql version for CNPG # will be used for all CNPG objects # Can be overruled per CNPG objects - pgVersion: 16 + # -- Define a topologyKey for default topologySpreadConstraints # Will be used when defaultSpread: true topologyKey: kubernetes.io/hostname + cnpg: + pgVersion: 16 + skipEmptyWalArchiveCheck: true metallb: # -- Adds metalLB annotations to services addServiceAnnotations: true @@ -1051,6 +1054,9 @@ cnpg: # set to true on single-node clusters to allow PVCs to be kept on instance restart singleNode: false + + ## set to configure the skipEmptyWalArchiveCheck annotation + # skipEmptyWalArchiveCheck: true # # -- storage size for the data pvc's # # Follows the same spec as .Values.Persistence type=PVC # storage: