From 8dc3b8e67d15ef016a1d163b14e0c5e43854e2c1 Mon Sep 17 00:00:00 2001 From: Matthieu Simon Date: Tue, 12 Nov 2024 14:48:01 +0100 Subject: [PATCH] feat(common): handle separately backup compression & encryption (#29139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** Currently compression is only enabled for backups and wal if the encryption is enabled This PR allows to set encryption and compression parameters separately **โš™๏ธ Type of change** - [x] โš™๏ธ Feature/App addition - [x] ๐Ÿ”ƒ Refactor of current code **๐Ÿงช How Has This Been Tested?** - Ran the updated tests - Checked on a live cluster with the different combinations **๐Ÿ“ƒ Notes:** I checked if it would impact charts using cnpg with encrypted backups enabled but didn't find any **โœ”๏ธ Checklist:** - [x] โš–๏ธ My code follows the style guidelines of this project - [x] ๐Ÿ‘€ I have performed a self-review of my own code - [ ] #๏ธโƒฃ I have commented my code, particularly in hard-to-understand areas - [ ] ๐Ÿ“„ I have made corresponding changes to the documentation - [x] โš ๏ธ My changes generate no new warnings - [x] ๐Ÿงช I have added tests to this description that prove my fix is effective or that my feature works - [x] โฌ†๏ธ I increased versions for any altered app according to semantic versioning - [x] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):` or `chore(chart-name):` --- --------- Signed-off-by: Kjeld Schouten Signed-off-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Signed-off-by: Matthieu Simon Co-authored-by: Kjeld Schouten Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> --- charts/library/common-test/Chart.yaml | 2 +- .../tests/cnpg/cluster_backup_spec_test.yaml | 82 ++++++++++++++++++- charts/library/common/Chart.yaml | 2 +- .../templates/lib/cnpg/cluster/_backup.tpl | 30 +++++-- 4 files changed, 106 insertions(+), 10 deletions(-) diff --git a/charts/library/common-test/Chart.yaml b/charts/library/common-test/Chart.yaml index e2260a7b767..6e87c23a5de 100644 --- a/charts/library/common-test/Chart.yaml +++ b/charts/library/common-test/Chart.yaml @@ -7,7 +7,7 @@ apiVersion: v2 appVersion: unknown dependencies: - name: common - version: ~25.1.0 + version: ~25.2.0 repository: file://../common/ condition: "" alias: "" diff --git a/charts/library/common-test/tests/cnpg/cluster_backup_spec_test.yaml b/charts/library/common-test/tests/cnpg/cluster_backup_spec_test.yaml index d97e784cdcc..9e4f7247d87 100644 --- a/charts/library/common-test/tests/cnpg/cluster_backup_spec_test.yaml +++ b/charts/library/common-test/tests/cnpg/cluster_backup_spec_test.yaml @@ -61,6 +61,7 @@ tests: backup: barmanObjectStore: data: + compression: bzip2 jobs: 2 destinationPath: some-path endpointURL: some-url @@ -72,6 +73,8 @@ tests: key: ACCESS_SECRET_KEY name: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds serverName: test-release-name-common-test-cnpg-my-pg + wal: + compression: bzip2 retentionPolicy: 10d target: primary @@ -126,6 +129,7 @@ tests: backup: barmanObjectStore: data: + compression: bzip2 jobs: 2 destinationPath: some-path endpointURL: some-url @@ -137,6 +141,8 @@ tests: key: ACCESS_SECRET_KEY name: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds serverName: test-release-name-common-test-cnpg-my-pg-rsome-revision + wal: + compression: bzip2 retentionPolicy: 10d target: primary @@ -191,6 +197,7 @@ tests: backup: barmanObjectStore: data: + compression: bzip2 jobs: 2 destinationPath: some-path endpointURL: some-url @@ -202,6 +209,8 @@ tests: key: ACCESS_SECRET_KEY name: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds serverName: some-server-name + wal: + compression: bzip2 retentionPolicy: 10d target: primary @@ -257,6 +266,7 @@ tests: backup: barmanObjectStore: data: + compression: bzip2 jobs: 2 destinationPath: some-path endpointURL: some-url @@ -268,6 +278,8 @@ tests: key: ACCESS_SECRET_KEY name: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds serverName: some-server-name-r1 + wal: + compression: bzip2 retentionPolicy: 10d target: primary @@ -323,7 +335,7 @@ tests: backup: barmanObjectStore: data: - compression: gzip + compression: bzip2 encryption: AES256 jobs: 2 destinationPath: some-path @@ -337,7 +349,73 @@ tests: name: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds serverName: test-release-name-common-test-cnpg-my-pg wal: - compression: gzip + compression: bzip2 encryption: AES256 retentionPolicy: 10d target: primary + + - it: should disable compression when set to false + set: + credentials: + test: *test + cnpg: + my-pg: + enabled: true + user: test-user + database: test-db + password: test-password + backups: + enabled: true + target: primary + retentionPolicy: 10d + credentials: test + destinationPath: some-path + compression: + enabled: false + asserts: + - documentIndex: *secretDoc + isKind: + of: Secret + - documentIndex: *secretDoc + isAPIVersion: + of: v1 + - documentIndex: *secretDoc + equal: + path: metadata.name + value: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds + - documentIndex: *secretDoc + equal: + path: stringData + value: + ACCESS_KEY_ID: some-access-key + ACCESS_SECRET_KEY: some-secret-key + - documentIndex: &clusterDoc 0 + isKind: + of: Cluster + - documentIndex: *clusterDoc + isAPIVersion: + of: postgresql.cnpg.io/v1 + - documentIndex: *clusterDoc + equal: + path: metadata.name + value: test-release-name-common-test-cnpg-my-pg + - documentIndex: *clusterDoc + isSubset: + path: spec + content: + backup: + barmanObjectStore: + data: + jobs: 2 + destinationPath: some-path + endpointURL: some-url + s3Credentials: + accessKeyId: + key: ACCESS_KEY_ID + name: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds + secretAccessKey: + key: ACCESS_SECRET_KEY + name: test-release-name-common-test-cnpg-my-pg-provider-backup-s3-creds + serverName: test-release-name-common-test-cnpg-my-pg + retentionPolicy: 10d + target: primary diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index a32c7832cbb..a82ce35ceda 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -48,4 +48,4 @@ sources: - https://hub.docker.com/r/mikefarah/yq - https://hub.docker.com/r/traefik/whoami type: library -version: 25.1.7 +version: 25.2.0 diff --git a/charts/library/common/templates/lib/cnpg/cluster/_backup.tpl b/charts/library/common/templates/lib/cnpg/cluster/_backup.tpl index 79171c561b7..72874801234 100644 --- a/charts/library/common/templates/lib/cnpg/cluster/_backup.tpl +++ b/charts/library/common/templates/lib/cnpg/cluster/_backup.tpl @@ -1,6 +1,16 @@ {{- define "tc.v1.common.lib.cnpg.cluster.backup" -}} {{- $rootCtx := .rootCtx -}} {{- $objectData := .objectData -}} + + {{- $compression := "bzip2" -}} + {{- if and $objectData.backups.compression (not $objectData.backups.compression.enabled) -}} + {{- $compression = "" -}} + {{- end -}} + + {{- $encryption := "" -}} + {{- if and $objectData.backups.encryption $objectData.backups.encryption.enabled -}} + {{- $encryption = "AES256" -}} + {{- end }} backup: {{- with $objectData.backups.target }} target: {{ . }} @@ -9,13 +19,21 @@ backup: barmanObjectStore: data: jobs: {{ $objectData.backups.jobs | default 2 }} - {{- if and $objectData.backups.encryption $objectData.backups.encryption.enabled }} - compression: "gzip" - encryption: "AES256" + {{- with $compression }} + compression: {{ . }} + {{- end -}} + {{- with $encryption }} + encryption: {{ . }} + {{- end -}} + {{- if or $compression $encryption }} wal: - compression: "gzip" - encryption: "AES256" - {{- end -}} + {{- with $compression }} + compression: {{ . }} + {{- end -}} + {{- with $encryption }} + encryption: {{ . }} + {{- end -}} + {{- end -}} {{/* Fetch provider data */}} {{/* Get the creds defined in backup.$provider */}} {{- $creds := (get $rootCtx.Values.credentials $objectData.backups.credentials) -}}