fix(storageClass): fix storage class and add tests (#767)

**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)-->

**⚙️ 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?**
<!--
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
- [ ] #️⃣ 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._
This commit is contained in:
Stavros Kois
2024-03-27 01:16:42 +02:00
committed by GitHub
parent 5e8d220dba
commit cec6a4cd3e
5 changed files with 49 additions and 4 deletions

View File

@@ -52,6 +52,7 @@ tests:
g_annotation1: global_annotation1
g_annotation2: global_annotation2
some-annotation: some-value
storageclass.kubernetes.io/is-default-class: "false"
- documentIndex: *storageClassDoc
equal:
path: metadata.labels

View File

@@ -34,6 +34,28 @@ tests:
equal:
path: volumeBindingMode
value: Immediate
- documentIndex: *storageClassDoc
equal:
path: metadata.annotations
value:
storageclass.kubernetes.io/is-default-class: "false"
- it: should generate correct spec with isDefault set
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
isDefault: true
asserts:
- documentIndex: *storageClassDoc
isKind:
of: StorageClass
- documentIndex: *storageClassDoc
equal:
path: metadata.annotations
value:
storageclass.kubernetes.io/is-default-class: "true"
- it: should generate correct spec with non-default reclaim policy
set:
@@ -153,7 +175,7 @@ tests:
- option1
- option2=value2
# Failures
# Failures
- it: should fail without provisioner
set:
storageClass:
@@ -185,3 +207,14 @@ tests:
asserts:
- failedTemplate:
errorMessage: Storage Class - Expected [volumeBindingMode] to be one of [WaitForFirstConsumer, Immediate], but got [invalid]
- it: should fail with isDefault not a boolean
set:
storageClass:
example1:
enabled: true
provisioner: some.provisioner.io
isDefault: invalid
asserts:
- failedTemplate:
errorMessage: Storage Class - Expected [isDefault] to be [boolean], but got [string]

View File

@@ -15,7 +15,7 @@ maintainers:
name: common
sources: null
type: library
version: 20.2.7
version: 20.2.8
annotations:
artifacthub.io/category: "integration-delivery"
artifacthub.io/license: "BUSL-1.1"

View File

@@ -14,11 +14,15 @@ objectData:
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $isDefaultClass := false -}}
{{- if (hasKey $objectData "isDefault") -}}
{{- $isDefaultClass = $objectData.isDefault -}}
{{- end -}}
{{- $allowVolExpand := true -}}
{{- if not (kindIs "invalid" $objectData.allowVolumeExpansion) -}}
{{- $allowVolExpand = $objectData.allowVolumeExpansion -}}
{{- end }}
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
@@ -29,7 +33,8 @@ metadata:
labels:
{{- . | nindent 4 }}
{{- end -}}
{{- $annotations := (mustMerge ($objectData.annotations | default dict) ( dict 'storageclass.kubernetes.io/is-default-class' ( $objectData.isDefaultClass | default "false" ) ) (include "tc.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
{{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "tc.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
{{- $_ := set $annotations "storageclass.kubernetes.io/is-default-class" ($isDefaultClass | toString) -}}
{{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
annotations:
{{- . | nindent 4 }}

View File

@@ -6,6 +6,12 @@
{{- fail "Storage Class - Expected non-empty [provisioner]" -}}
{{- end -}}
{{- if (hasKey $objectData "isDefault") -}}
{{- if not (kindIs "bool" $objectData.isDefault) -}}
{{- fail (printf "Storage Class - Expected [isDefault] to be [boolean], but got [%s]" (kindOf $objectData.isDefault)) -}}
{{- end -}}
{{- end -}}
{{- $validPolicies := (list "Retain" "Delete") -}}
{{- if $objectData.reclaimPolicy -}}
{{- if not (mustHas $objectData.reclaimPolicy $validPolicies) -}}