chore(common): use the expandName template in more places - also fixes a small quote bug on Certificate (#630)

**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  #623

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [ ] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] 🔃 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
- [ ] 🧪 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._
This commit is contained in:
Stavros Kois
2023-12-09 01:22:41 +02:00
committed by GitHub
parent 7455e67f87
commit a2fc0f8217
15 changed files with 116 additions and 82 deletions

View File

@@ -21,6 +21,7 @@ tests:
enabled: true
hosts:
- host2
- "*.host2.com"
certificateIssuer: some-other-issuer
certificateSecretTemplate:
labels:
@@ -72,6 +73,7 @@ tests:
secretName: certificate-issuer-my-certificate2
dnsNames:
- host2
- "*.host2.com"
issuerRef:
name: some-other-issuer
kind: ClusterIssuer

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 16.2.3
version: 16.2.4

View File

@@ -33,7 +33,7 @@ spec:
secretName: {{ $objectData.name }}
dnsNames:
{{- range $h := $objectData.hosts }}
- {{ tpl $h $rootCtx }}
- {{ (tpl $h $rootCtx) | quote }}
{{- end }}
privateKey:
algorithm: ECDSA

View File

@@ -18,11 +18,15 @@
{{/* Create a copy of the configmap */}}
{{- $objectData := (mustDeepCopy $configmap) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "ConfigMap"
"key" "configmap")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}} {{/* Configmaps have a max name length of 253 */}}

View File

@@ -7,36 +7,25 @@
{{- $fullname := include "tc.v1.common.lib.chart.names.fullname" $ -}}
{{- range $name, $pdb := .Values.podDisruptionBudget -}}
{{- $enabled := false -}}
{{- if hasKey $pdb "enabled" -}}
{{- if not (kindIs "invalid" $pdb.enabled) -}}
{{- $enabled = $pdb.enabled -}}
{{- else -}}
{{- fail (printf "Pod Disruption Budget - Expected the defined key [enabled] in [podDisruptionBudget.%s] to not be empty" $name) -}}
{{- end -}}
{{- end -}}
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
"rootCtx" $ "objectData" $pdb
"name" $name "caller" "Pod Disruption Budget"
"key" "podDistruptionBudget")) -}}
{{- 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 poddisruptionbudget */}}
{{- $objectData := (mustDeepCopy $pdb) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Pod Disruption Budget"
"key" "podDistruptionBudget")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}}

View File

@@ -18,11 +18,15 @@
{{/* Create a copy of the priorityclass */}}
{{- $objectData := (mustDeepCopy $priorityclass) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Priority Class"
"key" "priorityClass")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}} {{/* priorityclasss have a max name length of 253 */}}

View File

@@ -17,11 +17,15 @@
{{/* Create a copy of the secret */}}
{{- $objectData := (mustDeepCopy $secret) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Secret"
"key" "secret")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}} {{/* Secrets have a max name length of 253 */}}

View File

@@ -18,11 +18,15 @@
{{/* Create a copy of the storageclass */}}
{{- $objectData := (mustDeepCopy $storageclass) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Storage Class"
"key" "storageClass")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}} {{/* Configmaps have a max name length of 253 */}}

View File

@@ -18,11 +18,15 @@
{{/* Create a copy of the volumesnapshot */}}
{{- $objectData := (mustDeepCopy $volumesnapshot) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Volume Snapshot"
"key" "volumeSnapshots")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}} {{/* volumesnapshots have a max name length of 253 */}}

View File

@@ -18,11 +18,15 @@
{{/* Create a copy of the volumesnapshotclass */}}
{{- $objectData := (mustDeepCopy $volumesnapshotclass) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Volume Snapshot Class"
"key" "volumeSnapshotClass")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}} {{/* volumesnapshotclasss have a max name length of 253 */}}

View File

@@ -18,11 +18,15 @@
{{/* Create a copy of the mutatingWebhookConfiguration */}}
{{- $objectData := (mustDeepCopy $mutatingWebhookConfiguration) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Webhook"
"key" "webhook")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}}

View File

@@ -15,11 +15,15 @@
{{- if eq $enabled "true" -}}
{{- $objectData := (mustDeepCopy $cert) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Cert Manager Certificate"
"key" "certificate")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* If a certificateSecretTemplate is defined, adjust name */}}

View File

@@ -17,12 +17,15 @@
{{/* Create a copy of the backupstoragelocation */}}
{{- $objectData := (mustDeepCopy $backupStorageLoc) -}}
{{- $objectName := $name -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Velero Backup Storage Location"
"key" "backupStorageLocation")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Set namespace to velero location or itself, just in case its used from within velero */}}

View File

@@ -17,11 +17,15 @@
{{/* Create a copy of the schedule */}}
{{- $objectData := (mustDeepCopy $schedule) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Velero Schedule"
"key" "schedules")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Perform validations */}} {{/* schedules have a max name length of 253 */}}

View File

@@ -18,11 +18,15 @@
{{/* Create a copy of the volumesnapshotlocation */}}
{{- $objectData := (mustDeepCopy $volSnapLoc) -}}
{{- $objectName := (printf "%s-%s" $fullname $name) -}}
{{- if hasKey $objectData "expandObjectName" -}}
{{- if not $objectData.expandObjectName -}}
{{- $objectName = $name -}}
{{- end -}}
{{- $objectName := $name -}}
{{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict
"rootCtx" $ "objectData" $objectData
"name" $name "caller" "Velero Volume Snapshot Location"
"key" "volumeSnapshotLocation")) -}}
{{- if eq $expandName "true" -}}
{{- $objectName = (printf "%s-%s" $fullname $name) -}}
{{- end -}}
{{/* Set namespace to velero location or itself, just in case its used from within velero */}}