Skip to content

Commit

Permalink
chore(common): check helm version before everything (#683)
Browse files Browse the repository at this point in the history
**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

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?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ 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._
  • Loading branch information
stavros-k authored Jan 21, 2024
1 parent 4d9e6cb commit 69b13f0
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 20 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/common_library_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion library/common-test/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ keywords:
- truecharts
- common
- test
kubeVersion: '>=1.16.0-0'
kubeVersion: '>=1.24.0-0'
maintainers:
- email: [email protected]
name: TrueCharts
Expand All @@ -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"
6 changes: 3 additions & 3 deletions library/common-test/tests/container/resources_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ tests:
isAPIVersion:
of: apps/v1
- documentIndex: *otherDeploymentDoc
isNull:
isNullOrEmpty:
path: spec.template.spec.runtimeClassName
- documentIndex: *otherDeploymentDoc
isSubset:
Expand Down Expand Up @@ -488,7 +488,7 @@ tests:
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
isNull:
isNullOrEmpty:
path: spec.template.spec.runtimeClassName
- documentIndex: *deploymentDoc
isSubset:
Expand Down Expand Up @@ -620,7 +620,7 @@ tests:
isAPIVersion:
of: apps/v1
- documentIndex: *otherDeploymentDoc
isNull:
isNullOrEmpty:
path: spec.template.spec.runtimeClassName
- documentIndex: *otherDeploymentDoc
isSubset:
Expand Down
2 changes: 1 addition & 1 deletion library/common-test/tests/initContainer/data_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions library/common-test/tests/pod/runtime_class_name_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tests:
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isNull:
isNullOrEmpty:
path: spec.template.spec.runtimeClassName

- it: should pass with runtimeClassName from "global"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords:
- truecharts
- library-chart
- common
kubeVersion: '>=1.16.0-0'
kubeVersion: '>=1.24.0-0'
maintainers:
- email: [email protected]
name: TrueCharts
Expand Down
20 changes: 20 additions & 0 deletions library/common/templates/lib/chart/_check_capabitilies.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

Expand Down
2 changes: 2 additions & 0 deletions library/common/templates/loader/_init.tpl
Original file line number Diff line number Diff line change
@@ -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" . -}}

Expand Down

0 comments on commit 69b13f0

Please sign in to comment.