From 7758f93fdbdf16d01a56180b8d15cab0cfe073dd Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:30:01 +0300 Subject: [PATCH] chore(credentials): expand checks (#828) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes #813 **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [x] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ 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):` **➕ 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._ --- .../tests/cnpg/credentials_test.yaml | 29 +++++++++++++++++++ library/common/Chart.yaml | 2 +- .../cnpg/providers/_providerSecretSpawner.tpl | 6 ++++ .../lib/ingress/integrations/_traefik.tpl | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/library/common-test/tests/cnpg/credentials_test.yaml b/library/common-test/tests/cnpg/credentials_test.yaml index 321650a1..e2614a7d 100644 --- a/library/common-test/tests/cnpg/credentials_test.yaml +++ b/library/common-test/tests/cnpg/credentials_test.yaml @@ -157,3 +157,32 @@ tests: equal: path: stringData.password value: test-password + # Failures + - it: should fail with no credentials on recovery + set: + cnpg: + my-pg: + enabled: true + user: test-user + database: test-db + password: test-password + mode: recovery + recovery: + method: object_store + asserts: + - failedTemplate: + errorMessage: CNPG Recovery Provider Secret Spawner - Expected [recovery.credentials] to be defined on [recovery] mode + - it: should fail with no credentials on backup + set: + cnpg: + my-pg: + enabled: true + user: test-user + database: test-db + password: test-password + mode: backup + backups: + enabled: true + asserts: + - failedTemplate: + errorMessage: CNPG Recovery Provider Secret Spawner - Expected [backups.credentials] to be defined on [backup] mode diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 2ec1da0e..8230b9c9 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,7 +15,7 @@ maintainers: name: common sources: null type: library -version: 24.0.1 +version: 24.0.2 annotations: artifacthub.io/category: "integration-delivery" artifacthub.io/license: "BUSL-1.1" diff --git a/library/common/templates/lib/cnpg/providers/_providerSecretSpawner.tpl b/library/common/templates/lib/cnpg/providers/_providerSecretSpawner.tpl index e8c521a0..3e2db806 100644 --- a/library/common/templates/lib/cnpg/providers/_providerSecretSpawner.tpl +++ b/library/common/templates/lib/cnpg/providers/_providerSecretSpawner.tpl @@ -10,11 +10,17 @@ {{- $provider := "" -}} {{- $creds := dict -}} {{- if eq $type "backup" -}} + {{- if not $objectData.backups.credentials -}} + {{- fail "CNPG Recovery Provider Secret Spawner - Expected [backups.credentials] to be defined on [backup] mode" -}} + {{- end -}} {{/* Get the creds defined in backup.$provider */}} {{- $creds = (get $rootCtx.Values.credentials $objectData.backups.credentials) -}} {{- include "tc.v1.common.lib.credentials.validation" (dict "rootCtx" $rootCtx "caller" "CNPG Backup" "credName" $objectData.backups.credentials) -}} {{- $provider = $creds.type -}} {{- else if eq $type "recovery" -}} + {{- if not $objectData.recovery.credentials -}} + {{- fail "CNPG Recovery Provider Secret Spawner - Expected [recovery.credentials] to be defined on [recovery] mode" -}} + {{- end -}} {{/* Get the creds defined in recovery.$provider */}} {{- $creds = (get $rootCtx.Values.credentials $objectData.recovery.credentials) -}} {{- include "tc.v1.common.lib.credentials.validation" (dict "rootCtx" $rootCtx "caller" "CNPG Backup" "credName" $objectData.recovery.credentials) -}} diff --git a/library/common/templates/lib/ingress/integrations/_traefik.tpl b/library/common/templates/lib/ingress/integrations/_traefik.tpl index 4b79e091..8c602e68 100644 --- a/library/common/templates/lib/ingress/integrations/_traefik.tpl +++ b/library/common/templates/lib/ingress/integrations/_traefik.tpl @@ -102,7 +102,7 @@ {{- end -}} {{/* Format middleware */}} - {{- $formattedMiddlewares = mustAppend $formattedMiddlewares (printf "%s-%s@kubernetescrd" $midNamespace $mid.name ) -}} + {{- $formattedMiddlewares = mustAppend $formattedMiddlewares (printf "%s-%s@kubernetescrd" $midNamespace $mid.name) -}} {{- end -}} {{- if $formattedMiddlewares -}}