From 69b13f07d6520fc2811a0ca82dc3172bea24187f Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:33:41 +0200 Subject: [PATCH] chore(common): check helm version before everything (#683) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # Adds a pre-flight check for helm version. By default the restriction is set to `>3.9.4` which is know to not work with parts of this library. If the annotation `truecharts.org/min_helm_version` is found then the restriction becomes `>=` + the version defined in the annotation. Currently we can't really "unit test" this, because there is no way to manipulate annotations in the test suites. But we are at least testing that it does not "fail", because if it would, all unittests would fail. --- Additionally updated the upper bound of helm version we run the tests on, and also updated the unittest plugin version. Adjusted some "matchers" in the unittest files to follow the semantic changes in from the unittest plugins. **⚙️ Type of change** - [ ] ⚙️ 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:** - [x] ⚖️ My code follows the style guidelines of this project - [x] 👀 I have performed a self-review of my own code - [x] #️⃣ 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 - [ ] 🧪 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 **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ 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._ --- .github/workflows/common_library_tests.yaml | 20 ++++++++++--------- library/common-test/Chart.yaml | 4 +++- .../tests/container/resources_test.yaml | 6 +++--- .../tests/initContainer/data_test.yaml | 2 +- .../initContainer/data_upgrade_test.yaml | 2 +- .../tests/pod/runtime_class_name_test.yaml | 6 +++--- library/common/Chart.yaml | 2 +- .../lib/chart/_check_capabitilies.tpl | 20 +++++++++++++++++++ .../lib/cnpg/scheduledBackup/_validation.tpl | 2 +- library/common/templates/loader/_init.tpl | 2 ++ 10 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 library/common/templates/lib/chart/_check_capabitilies.tpl diff --git a/.github/workflows/common_library_tests.yaml b/.github/workflows/common_library_tests.yaml index db17f638..21b96450 100644 --- a/.github/workflows/common_library_tests.yaml +++ b/.github/workflows/common_library_tests.yaml @@ -23,7 +23,7 @@ jobs: matrix: helm-version: - v3.12.3 - - v3.13.3 + - v3.14.0 steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 @@ -56,13 +56,13 @@ jobs: name: Unit Tests runs-on: ubuntu-22.04 env: - helmUnitVersion: 0.3.0 + helmUnitVersion: 0.4.1 strategy: fail-fast: false matrix: helm-version: - v3.12.3 - - v3.13.3 + - v3.14.0 steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 @@ -110,7 +110,7 @@ jobs: # We run tests on Helm version of latest SCALE, fluxcd and latest helm release helm-version: - v3.12.3 - - v3.13.3 + - v3.14.0 values: - basic-values.yaml - configmap-values.yaml @@ -215,7 +215,8 @@ jobs: fi if [[ "${{ matrix.values }}" =~ ingress.*-values.yaml ]]; then helm install cert-manager oci://tccr.io/truecharts/cert-manager --namespace cert-manager --create-namespace --wait - helm install traefik oci://tccr.io/truecharts/traefik --namespace traefik --create-namespace --wait + helm install traefik oci://tccr.io/truecharts/traefik --namespace traefik --create-namespace --wait \ + --set service.main.type=ClusterIP --set service.tcp.type=ClusterIP fi - name: Run chart-testing (install) @@ -257,7 +258,7 @@ jobs: # # We run tests on Helm version of latest SCALE release # helm-version: # - v3.12.3 -# - v3.13.3 +# - v3.14.0 # values: # - basic-values.yaml # - configmap-values.yaml @@ -321,7 +322,7 @@ jobs: # # We run tests on Helm version of latest SCALE release # helm-version: # - v3.12.3 -# - v3.13.3 +# - v3.14.0 # values: # - ingress-values.yaml # - metrics-values.yaml @@ -342,7 +343,8 @@ jobs: # run: | # helm install prometheus-operator oci://tccr.io/truecharts/prometheus-operator --namespace prometheus-operator --create-namespace --wait # helm install cloudnative-pg oci://tccr.io/truecharts/cloudnative-pg --namespace cloudnative-pg --create-namespace --wait -# helm install traefik oci://tccr.io/truecharts/traefik --namespace traefik --create-namespace --wait +# helm install traefik oci://tccr.io/truecharts/traefik --namespace traefik --create-namespace --wait \ +# --set service.main.type=ClusterIP --set service.tcp.type=ClusterIP # # - name: Checkout # uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 @@ -379,7 +381,7 @@ jobs: # # We run tests on Helm version of latest SCALE release # helm-version: # - v3.12.3 -# - v3.13.3 +# - v3.14.0 # values: # - vpn-gluetun-values.yaml # - vpn-tailscale-values.yaml diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index dd961968..97e52e85 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -13,7 +13,7 @@ keywords: - truecharts - common - test -kubeVersion: '>=1.16.0-0' +kubeVersion: '>=1.24.0-0' maintainers: - email: info@truecharts.org name: TrueCharts @@ -23,3 +23,5 @@ sources: - https://github.com/truecharts/apps/tree/master/charts/library/common-test type: application version: 1.0.0 +annotations: + truecharts.org/min_helm_version: "3.12" diff --git a/library/common-test/tests/container/resources_test.yaml b/library/common-test/tests/container/resources_test.yaml index faa506b9..583b1aef 100644 --- a/library/common-test/tests/container/resources_test.yaml +++ b/library/common-test/tests/container/resources_test.yaml @@ -424,7 +424,7 @@ tests: isAPIVersion: of: apps/v1 - documentIndex: *otherDeploymentDoc - isNull: + isNullOrEmpty: path: spec.template.spec.runtimeClassName - documentIndex: *otherDeploymentDoc isSubset: @@ -488,7 +488,7 @@ tests: isAPIVersion: of: apps/v1 - documentIndex: *deploymentDoc - isNull: + isNullOrEmpty: path: spec.template.spec.runtimeClassName - documentIndex: *deploymentDoc isSubset: @@ -620,7 +620,7 @@ tests: isAPIVersion: of: apps/v1 - documentIndex: *otherDeploymentDoc - isNull: + isNullOrEmpty: path: spec.template.spec.runtimeClassName - documentIndex: *otherDeploymentDoc isSubset: diff --git a/library/common-test/tests/initContainer/data_test.yaml b/library/common-test/tests/initContainer/data_test.yaml index c8b489fe..87223e9b 100644 --- a/library/common-test/tests/initContainer/data_test.yaml +++ b/library/common-test/tests/initContainer/data_test.yaml @@ -229,7 +229,7 @@ tests: isAPIVersion: of: apps/v1 - documentIndex: *deploymentDoc - isNull: + isNullOrEmpty: path: spec.template.spec.initContainers - it: should add NVIDIA_VISIBLE_DEVICES=void to init container without GPU diff --git a/library/common-test/tests/initContainer/data_upgrade_test.yaml b/library/common-test/tests/initContainer/data_upgrade_test.yaml index aafffc79..c7a837c1 100644 --- a/library/common-test/tests/initContainer/data_upgrade_test.yaml +++ b/library/common-test/tests/initContainer/data_upgrade_test.yaml @@ -230,7 +230,7 @@ tests: isAPIVersion: of: apps/v1 - documentIndex: *deploymentDoc - isNull: + isNullOrEmpty: path: spec.template.spec.initContainers - it: should add NVIDIA_VISIBLE_DEVICES=void to init container without GPU diff --git a/library/common-test/tests/pod/runtime_class_name_test.yaml b/library/common-test/tests/pod/runtime_class_name_test.yaml index 58e79b8a..e1fda1d6 100644 --- a/library/common-test/tests/pod/runtime_class_name_test.yaml +++ b/library/common-test/tests/pod/runtime_class_name_test.yaml @@ -20,7 +20,7 @@ tests: isKind: of: Deployment - documentIndex: *deploymentDoc - isNull: + isNullOrEmpty: path: spec.template.spec.runtimeClassName - it: should pass with runtimeClassName from "global" @@ -148,7 +148,7 @@ tests: podSpec: {} asserts: - documentIndex: *deploymentDoc - isNull: + isNullOrEmpty: path: spec.template.spec.runtimeClassName - it: should pass with runtimeClassName from ixChartContext without targetSelector (on primary workload) @@ -186,7 +186,7 @@ tests: isKind: of: CronJob - documentIndex: *cronJobDoc - isNull: + isNullOrEmpty: path: spec.jobTemplate.spec.template.spec.runtimeClassName - it: should pass with runtimeClassName not set from ixChartContext without gpu value diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index e6431e53..b9a35702 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -7,7 +7,7 @@ keywords: - truecharts - library-chart - common -kubeVersion: '>=1.16.0-0' +kubeVersion: '>=1.24.0-0' maintainers: - email: info@truecharts.org name: TrueCharts diff --git a/library/common/templates/lib/chart/_check_capabitilies.tpl b/library/common/templates/lib/chart/_check_capabitilies.tpl new file mode 100644 index 00000000..e4f5170f --- /dev/null +++ b/library/common/templates/lib/chart/_check_capabitilies.tpl @@ -0,0 +1,20 @@ +{{- define "tc.v1.common.check.capabilities" -}} + {{- $helmVersion := .Capabilities.HelmVersion.Version -}} + {{- $helmVerCond := ">3.9.4" -}} + + {{- if .Chart.Annotations -}} + {{- $min := index .Chart.Annotations "truecharts.org/min_helm_version" -}} + {{- if $min -}} + {{/* Apply a relaxed version check */}} + {{- $helmVerCond = printf ">=%s" $min -}} + {{- end -}} + {{- end -}} + + {{- if not (semverCompare $helmVerCond $helmVersion) -}} + {{- if .Values.global.ixChartContext -}} + {{- fail (printf "Expected helm version [%s], but found [%s]. Upgrade TrueNAS SCALE OS" $helmVerCond $helmVersion) -}} + {{- else -}} + {{- fail (printf "Expected helm version [%s], but found [%s]. Upgrade helm cli tool." $helmVerCond $helmVersion) -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/library/common/templates/lib/cnpg/scheduledBackup/_validation.tpl b/library/common/templates/lib/cnpg/scheduledBackup/_validation.tpl index 17e477a5..8138b86a 100644 --- a/library/common/templates/lib/cnpg/scheduledBackup/_validation.tpl +++ b/library/common/templates/lib/cnpg/scheduledBackup/_validation.tpl @@ -12,7 +12,7 @@ {{- if (hasKey $objectData.schedData "backupOwnerReference") -}} {{- $validOwnerRefs := (list "none" "self" "cluster") -}} {{- if not (mustHas $objectData.schedData.backupOwnerReference $validOwnerRefs) -}} - {{- fail (printf "CNPG Scheduled Backup - Expected [backupOwnerReference] in [backups.scheduledBackups] entry to be one of [%s], but got [%s] " (join ", " $validOwnerRefs) $objectData.schedData.backupOwnerReference) -}} + {{- fail (printf "CNPG Scheduled Backup - Expected [backupOwnerReference] in [backups.scheduledBackups] entry to be one of [%s], but got [%s]" (join ", " $validOwnerRefs) $objectData.schedData.backupOwnerReference) -}} {{- end -}} {{- end -}} diff --git a/library/common/templates/loader/_init.tpl b/library/common/templates/loader/_init.tpl index aff423a4..5f9f72ac 100644 --- a/library/common/templates/loader/_init.tpl +++ b/library/common/templates/loader/_init.tpl @@ -1,6 +1,8 @@ {{/* Initialiaze values of the chart */}} {{- define "tc.v1.common.loader.init" -}} + {{- include "tc.v1.common.check.capabilities" . -}} + {{/* Merge chart values and the common chart defaults */}} {{- include "tc.v1.common.values.init" . -}}