chore(utils): use template for "enabled" with tpl support (#618)

**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
- [ ] 🪛 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:**

- [ ] ⚖️ 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 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._
This commit is contained in:
Stavros Kois
2023-12-03 16:18:22 +02:00
committed by GitHub
parent 9a1f204c50
commit fc115e3e8f
21 changed files with 126 additions and 214 deletions

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 15.3.1
version: 15.3.2

View File

@@ -0,0 +1,28 @@
{{- define "tc.v1.common.lib.util.enabled" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $key := .key -}}
{{- $name := (.name | toString) -}}
{{- $caller := .caller -}}
{{- $enabled := false -}}
{{- if hasKey $objectData "enabled" -}}
{{- if not (kindIs "invalid" $objectData.enabled) -}}
{{- $enabled = $objectData.enabled -}}
{{- else -}}
{{- fail (printf "%s - Expected the defined key [enabled] in [%s.%s] to not be empty" $caller $key $name) -}}
{{- end -}}
{{- end -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $rootCtx -}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{/* NOTE: Always treat the returned result as string */}}
{{- $enabled -}}
{{- end -}}

View File

@@ -8,28 +8,12 @@
{{- range $name, $configmap := .Values.configmap -}}
{{- $enabled := false -}}
{{- if hasKey $configmap "enabled" -}}
{{- if not (kindIs "invalid" $configmap.enabled) -}}
{{- $enabled = $configmap.enabled -}}
{{- else -}}
{{- fail (printf "ConfigMap - Expected the defined key [enabled] in [configmap.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $configmap
"name" $name "caller" "ConfigMap"
"key" "configmap")) -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the configmap */}}
{{- $objectData := (mustDeepCopy $configmap) -}}

View File

@@ -8,7 +8,12 @@
{{- range $name, $imgPullSecret := .Values.imagePullSecret -}}
{{- if $imgPullSecret.enabled -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $imgPullSecret
"name" $name "caller" "Image Pull Secret"
"key" "imagePullSecret")) -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the configmap */}}
{{- $objectData := (mustDeepCopy $imgPullSecret) -}}

View File

@@ -5,7 +5,13 @@
{{- define "tc.v1.common.spawner.portal" -}}
{{- range $name, $portal := .Values.portal -}}
{{- if $portal.enabled -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $portal
"name" $name "caller" "Portal"
"key" "portal")) -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the portal */}}
{{- $objectData := (mustDeepCopy $portal) -}}

View File

@@ -8,28 +8,12 @@
{{- range $name, $priorityclass := .Values.priorityClass -}}
{{- $enabled := false -}}
{{- if hasKey $priorityclass "enabled" -}}
{{- if not (kindIs "invalid" $priorityclass.enabled) -}}
{{- $enabled = $priorityclass.enabled -}}
{{- else -}}
{{- fail (printf "Priority Class - Expected the defined key [enabled] in [priorityclass.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $priorityclass
"name" $name "caller" "Priority Class"
"key" "priorityClass")) -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the priorityclass */}}
{{- $objectData := (mustDeepCopy $priorityclass) -}}

View File

@@ -7,7 +7,12 @@
{{- range $name, $persistence := .Values.persistence -}}
{{- if $persistence.enabled -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $persistence
"name" $name "caller" "Persistence"
"key" "persistence")) -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the persistence */}}
{{- $objectData := (mustDeepCopy $persistence) -}}

View File

@@ -10,8 +10,12 @@
{{- include "tc.v1.common.lib.rbac.primaryValidation" $ -}}
{{- range $name, $rbac := .Values.rbac -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $rbac
"name" $name "caller" "RBAC"
"key" "rbac")) -}}
{{- if $rbac.enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the configmap */}}
{{- $objectData := (mustDeepCopy $rbac) -}}

View File

@@ -7,8 +7,12 @@
{{- $fullname := include "tc.v1.common.lib.chart.names.fullname" $ -}}
{{- range $name, $certificate := .Values.scaleCertificate -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $certificate
"name" $name "caller" "Scale Certificate"
"key" "scaleCertificate")) -}}
{{- if $certificate.enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the certificate */}}
{{- $objectData := (mustDeepCopy $certificate) -}}

View File

@@ -7,28 +7,12 @@
{{- $fullname := include "tc.v1.common.lib.chart.names.fullname" $ -}}
{{- range $name, $secret := .Values.secret -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $secret
"name" $name "caller" "Secret"
"key" "secret")) -}}
{{- $enabled := false -}}
{{- if hasKey $secret "enabled" -}}
{{- if not (kindIs "invalid" $secret.enabled) -}}
{{- $enabled = $secret.enabled -}}
{{- else -}}
{{- fail (printf "Secret - Expected the defined key [enabled] in [secret.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the secret */}}
{{- $objectData := (mustDeepCopy $secret) -}}

View File

@@ -10,8 +10,12 @@
{{- include "tc.v1.common.lib.service.primaryValidation" $ -}}
{{- range $name, $service := .Values.service -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $service
"name" $name "caller" "Service"
"key" "service")) -}}
{{- if $service.enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the configmap */}}
{{- $objectData := (mustDeepCopy $service) -}}

View File

@@ -10,8 +10,12 @@
{{- include "tc.v1.common.lib.serviceAccount.primaryValidation" $ -}}
{{- range $name, $serviceAccount := .Values.serviceAccount -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $serviceAccount
"name" $name "caller" "Service Account"
"key" "serviceAccount")) -}}
{{- if $serviceAccount.enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the configmap */}}
{{- $objectData := (mustDeepCopy $serviceAccount) -}}

View File

@@ -8,28 +8,12 @@
{{- range $name, $storageclass := .Values.storageClass -}}
{{- $enabled := false -}}
{{- if hasKey $storageclass "enabled" -}}
{{- if not (kindIs "invalid" $storageclass.enabled) -}}
{{- $enabled = $storageclass.enabled -}}
{{- else -}}
{{- fail (printf "StorageClass - Expected the defined key [enabled] in [storageclass.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $storageclass
"name" $name "caller" "Storage Class"
"key" "storageClass")) -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the storageclass */}}
{{- $objectData := (mustDeepCopy $storageclass) -}}

View File

@@ -8,27 +8,12 @@
{{- range $name, $volumesnapshot := .Values.volumeSnapshots -}}
{{- $enabled := false -}}
{{- if hasKey $volumesnapshot "enabled" -}}
{{- if not (kindIs "invalid" $volumesnapshot.enabled) -}}
{{- $enabled = $volumesnapshot.enabled -}}
{{- else -}}
{{- fail (printf "Volume Snapshot - Expected the defined key [enabled] in [volumeSnapshots.%v] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $volumesnapshot
"name" $name "caller" "Volume Snapshot"
"key" "volumeSnapshots")) -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the volumesnapshot */}}
{{- $objectData := (mustDeepCopy $volumesnapshot) -}}

View File

@@ -8,27 +8,12 @@
{{- range $name, $volumesnapshotclass := .Values.volumeSnapshotClass -}}
{{- $enabled := false -}}
{{- if hasKey $volumesnapshotclass "enabled" -}}
{{- if not (kindIs "invalid" $volumesnapshotclass.enabled) -}}
{{- $enabled = $volumesnapshotclass.enabled -}}
{{- else -}}
{{- fail (printf "Volume Snapshot Class - Expected the defined key [enabled] in [volumeSnapshotClass.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $volumesnapshotclass
"name" $name "caller" "Volume Snapshot Class"
"key" "volumeSnapshotClass")) -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the volumesnapshotclass */}}
{{- $objectData := (mustDeepCopy $volumesnapshotclass) -}}

View File

@@ -8,27 +8,12 @@
{{- range $name, $mutatingWebhookConfiguration := .Values.webhook -}}
{{- $enabled := false -}}
{{- if hasKey $mutatingWebhookConfiguration "enabled" -}}
{{- if not (kindIs "invalid" $mutatingWebhookConfiguration.enabled) -}}
{{- $enabled = $mutatingWebhookConfiguration.enabled -}}
{{- else -}}
{{- fail (printf "Webhook - Expected the defined key [enabled] in [webhook.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $mutatingWebhookConfiguration
"name" $name "caller" "Webhook"
"key" "webhook")) -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the mutatingWebhookConfiguration */}}
{{- $objectData := (mustDeepCopy $mutatingWebhookConfiguration) -}}

View File

@@ -11,7 +11,12 @@
{{- range $name, $workload := .Values.workload -}}
{{- if $workload.enabled -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $workload
"name" $name "caller" "Workload"
"key" "workload")) -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the workload */}}
{{- $objectData := (mustDeepCopy $workload) -}}

View File

@@ -8,27 +8,12 @@
{{- range $name, $backupStorageLoc := .Values.backupStorageLocation -}}
{{- $enabled := false -}}
{{- if hasKey $backupStorageLoc "enabled" -}}
{{- if not (kindIs "invalid" $backupStorageLoc.enabled) -}}
{{- $enabled = $backupStorageLoc.enabled -}}
{{- else -}}
{{- fail (printf "Backup Storage Location - Expected the defined key [enabled] in [backupStorageLocation.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $backupStorageLoc
"name" $name "caller" "Velero Backup Storage Location"
"key" "backupStorageLocation")) -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the backupstoragelocation */}}
{{- $objectData := (mustDeepCopy $backupStorageLoc) -}}

View File

@@ -8,28 +8,12 @@
{{- range $name, $schedule := .Values.schedules -}}
{{- $enabled := false -}}
{{- if hasKey $schedule "enabled" -}}
{{- if not (kindIs "invalid" $schedule.enabled) -}}
{{- $enabled = $schedule.enabled -}}
{{- else -}}
{{- fail (printf "Schedule - Expected the defined key [enabled] in [schedules.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $schedule
"name" $name "caller" "Velero Schedule"
"key" "schedules")) -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the schedule */}}
{{- $objectData := (mustDeepCopy $schedule) -}}

View File

@@ -8,27 +8,12 @@
{{- range $name, $volSnapLoc := .Values.volumeSnapshotLocation -}}
{{- $enabled := false -}}
{{- if hasKey $volSnapLoc "enabled" -}}
{{- if not (kindIs "invalid" $volSnapLoc.enabled) -}}
{{- $enabled = $volSnapLoc.enabled -}}
{{- else -}}
{{- fail (printf "Volume Snapshot Location - Expected the defined key [enabled] in [volumeSnapshotLocation.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $volSnapLoc
"name" $name "caller" "Velero Volume Snapshot Location"
"key" "volumeSnapshotLocation")) -}}
{{- if kindIs "string" $enabled -}}
{{- $enabled = tpl $enabled $ -}}
{{/* After tpl it becomes a string, not a bool */}}
{{- if eq $enabled "true" -}}
{{- $enabled = true -}}
{{- else if eq $enabled "false" -}}
{{- $enabled = false -}}
{{- end -}}
{{- end -}}
{{- if $enabled -}}
{{- if eq $enabled "true" -}}
{{/* Create a copy of the volumesnapshotlocation */}}
{{- $objectData := (mustDeepCopy $volSnapLoc) -}}

View File

@@ -690,6 +690,7 @@ webhook:
webhooks: []
priorityClass: {}
# priorityClass:
# example:
# provisioner: some.provisioner.io
@@ -700,6 +701,7 @@ webhook:
# description: "some description"
# # -- create storageClasses on demand
storageClass: {}
# storageClass:
# example:
# provisioner: some.provisioner.io