From b090b8b28321a47c16fb6cc149ca33f79e35a63a Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Sat, 16 Mar 2024 12:54:51 +0100 Subject: [PATCH] feat(common): add a temporary failsafe to filter dragonfish and cobia SCALE users that forgot to follow instructions (#751) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** This is a **TEMPORARY** hotfix to ensure SCALE users that forgot setting their `storageClass` to `SCALE-ZFS`, loose data on update to dragonfish. This will be removed in the future, likely together with support for SCALE storageClasses all-together. **โš™๏ธ Type of change** - [x] โš™๏ธ Feature/App addition - [ ] ๐Ÿช› 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:** - [ ] โš–๏ธ 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 corresponding changes to the documentation - [ ] โš ๏ธ My changes generate no new warnings - [ ] ๐Ÿงช 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 **โž• 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._ --------- Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Co-authored-by: Stavros kois --- library/common-test/Chart.yaml | 2 +- .../tests/persistence/pvc_data_test.yaml | 2 ++ .../tests/persistence/validation_test.yaml | 16 ++------------ .../volumeClaimTemplate/validation_test.yaml | 22 ++----------------- .../volumeClaimTemplate/vct_data_test.yaml | 2 ++ library/common/Chart.yaml | 2 +- .../lib/storage/_storageClassName.tpl | 18 +++++++++++---- 7 files changed, 24 insertions(+), 40 deletions(-) diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index 661093ca0..a6c64f313 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: ~20.1.0 + version: ~20.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-test/tests/persistence/pvc_data_test.yaml b/library/common-test/tests/persistence/pvc_data_test.yaml index 41e96949b..f90f1a2fb 100644 --- a/library/common-test/tests/persistence/pvc_data_test.yaml +++ b/library/common-test/tests/persistence/pvc_data_test.yaml @@ -202,6 +202,8 @@ tests: namespace: ix-namespace ixChartContext: storageClassName: ix-storage-class-releasename + ci: + storageClass: true some_storage_class: "SCALE-ZFS" persistence: my-volume1: diff --git a/library/common-test/tests/persistence/validation_test.yaml b/library/common-test/tests/persistence/validation_test.yaml index 734d9a81a..78f39df47 100644 --- a/library/common-test/tests/persistence/validation_test.yaml +++ b/library/common-test/tests/persistence/validation_test.yaml @@ -56,26 +56,14 @@ tests: - failedTemplate: errorMessage: PVC - Expected [accessModes] entry to be one of [ReadWriteOnce, ReadOnlyMany, ReadWriteMany, ReadWriteOncePod], but got [not-an-access-mode] - - it: should fail without storageClassName in ixChartContext - set: - global: - namespace: ix-namespace - ixChartContext: - storageClassName: "" - persistence: - volume1: - enabled: true - type: pvc - asserts: - - failedTemplate: - errorMessage: PVC - Expected non-empty [global.ixChartContext.storageClassName] - - it: should fail without storageClassName in ixChartContext with SCALE-ZFS explicitly set set: global: namespace: ix-namespace ixChartContext: storageClassName: "" + ci: + storageClass: true persistence: volume1: enabled: true diff --git a/library/common-test/tests/volumeClaimTemplate/validation_test.yaml b/library/common-test/tests/volumeClaimTemplate/validation_test.yaml index 36b158bc5..9ea7c2149 100644 --- a/library/common-test/tests/volumeClaimTemplate/validation_test.yaml +++ b/library/common-test/tests/volumeClaimTemplate/validation_test.yaml @@ -56,32 +56,14 @@ tests: - failedTemplate: errorMessage: Persistence - Expected [targetSelector] to be [dict], but got [string] - - it: should fail without storageClassName in ixChartContext - set: - global: - namespace: ix-namespace - ixChartContext: - storageClassName: "" - persistence: - volume1: - enabled: true - type: vct - workload: - main: - enabled: true - primary: true - type: StatefulSet - podSpec: {} - asserts: - - failedTemplate: - errorMessage: PVC - Expected non-empty [global.ixChartContext.storageClassName] - - it: should fail without storageClassName in ixChartContext with SCALE-ZFS explicitly set set: global: namespace: ix-namespace ixChartContext: storageClassName: "" + ci: + storageClass: true persistence: volume1: enabled: true diff --git a/library/common-test/tests/volumeClaimTemplate/vct_data_test.yaml b/library/common-test/tests/volumeClaimTemplate/vct_data_test.yaml index 4ca20ee8e..0cbf7595b 100644 --- a/library/common-test/tests/volumeClaimTemplate/vct_data_test.yaml +++ b/library/common-test/tests/volumeClaimTemplate/vct_data_test.yaml @@ -278,6 +278,8 @@ tests: namespace: ix-namespace ixChartContext: storageClassName: ix-storage-class-releasename + ci: + storageClass: true some_storage_class: "SCALE-ZFS" persistence: my-volume1: diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index dce910c4b..0860699f2 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,7 +15,7 @@ maintainers: name: common sources: null type: library -version: 20.1.5 +version: 20.2.0 annotations: artifacthub.io/category: "integration-delivery" artifacthub.io/license: "BUSL-1.1" diff --git a/library/common/templates/lib/storage/_storageClassName.tpl b/library/common/templates/lib/storage/_storageClassName.tpl index 6a50dd522..03ab001d7 100644 --- a/library/common/templates/lib/storage/_storageClassName.tpl +++ b/library/common/templates/lib/storage/_storageClassName.tpl @@ -37,11 +37,21 @@ objectData: The object data of the pvc {{- $className = tpl $storageClass $rootCtx -}} {{- end -}} - {{- else if $rootCtx.Values.global.ixChartContext -}} - {{- if not $rootCtx.Values.global.ixChartContext.storageClassName -}} - {{- fail (printf "%s - Expected non-empty [global.ixChartContext.storageClassName]" $caller) -}} + {{/* On Cobia -> Dragonfish update the ixChartContext should still be there, for existing apps so we can reference it */}} + {{- else if and $rootCtx.Values.global.ixChartContext $rootCtx.Values.global.ixChartContext.storageClassName -}} + {{- $scaleClassFound := false -}} + {{- with (lookup "v1" "StorageClass" "" $rootCtx.Values.global.ixChartContext.storageClassName) -}} + {{/* Check if there is an actually valid storageClass found */}} + {{- if .provisioner -}} + {{- $scaleClassFound = true -}} + {{- end -}} + {{- end -}} + + {{- if or $scaleClassFound (and $rootCtx.Values.global.ixChartContext.ci $rootCtx.Values.global.ixChartContext.ci.storageClass) -}} + {{- $className = tpl $rootCtx.Values.global.ixChartContext.storageClassName $rootCtx -}} + {{- else if $rootCtx.Values.global.fallbackDefaults.storageClass -}} + {{- $className = tpl $rootCtx.Values.global.fallbackDefaults.storageClass $rootCtx -}} {{- end -}} - {{- $className = tpl $rootCtx.Values.global.ixChartContext.storageClassName $rootCtx -}} {{- else if $rootCtx.Values.global.fallbackDefaults.storageClass -}}