Skip to content

Commit

Permalink
refactor: update getKeyValue function documentation and adjust key lo…
Browse files Browse the repository at this point in the history
…okup logic; modify imagePullSecret handling in templates

On-behalf-of: @SAP angel.kafazov@sap.com
Signed-off-by: Angel Kafazov <akafazov@cst-bg.net>
  • Loading branch information
akafazov committed Nov 27, 2024
1 parent 005ec67 commit 8c897f4
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 29 deletions.
Binary file modified charts/account-operator/charts/account-operator-crds-0.1.5.tgz
Binary file not shown.
Binary file modified charts/account-operator/charts/common-0.1.5.tgz
Binary file not shown.
24 changes: 5 additions & 19 deletions charts/common/templates/_getKeyLookup.tpl
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
{{/*
Function: common.getKeyValue
Description:
Retrieves a value from the Helm chart's values.yaml file based on a prioritized key lookup.
The function searches for a value in the following order:
1. An override key (`keyPathOverride`).
2. A global key (`global.keyPath`).
3. A default key (`defaults.keyPath`).
If none of these keys exist, it returns an empty string.
Retrieves a value from values.yaml by checking keys in this order:
1. Override key, 2. Global key, 3. Default key. Returns an empty string if none exist.
Parameters:
- .key: The path to the key being retrieved.
- .Values: The values object passed to the Helm template.
Dependencies:
- Uses helper functions "common.hasNestedKey" and "common.getNestedValue" to check
the existence of nested keys and retrieve their values.
Usage:
This function is intended to prioritize overrides and global configurations
in a Helm chart's values.yaml file while providing default fallback values.
- .key: Key path to lookup.
- .Values: Values object.
*/}}

{{- define "common.getKeyValue" -}}
{{- $keyPath := .key -}}
{{- $values := .Values -}}

{{- $overrideKey := printf "%sOverride" $keyPath -}}
{{- $globalKey := printf "global.%s" $keyPath -}}
{{- $defaultKey := printf "defaults.%s" $keyPath -}}
{{- $defaultKey := printf "common.defaults.%s" $keyPath -}}

{{- $value := "" -}}
{{- if eq (include "common.hasNestedKey" (dict "Values" $values "key" $overrideKey)) "true" }}
Expand Down
4 changes: 1 addition & 3 deletions charts/common/templates/_imagePullSecret.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{{- define "common.imagePullSecret" }}
{{- if or .Values.imagePullSecret ((.Values).global).imagePullSecret }}
imagePullSecrets:
- name: {{ default .Values.imagePullSecret (.Values.global).imagePullSecret }}
{{- end }}
- name: {{ include "common.certManagerEnabled" (dict "Values" .Values "key" "imagePullSecret") }}
{{- end -}}
Binary file modified charts/common/test-chart/charts/common-0.1.5.tgz
Binary file not shown.
4 changes: 2 additions & 2 deletions charts/common/test-chart/tests/hasNestedKey_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ tests:
- it: nested key found in defaults
template: testHasNestedKey.yaml
set:
inputKey: "defaults.certManager.enabled"
inputKey: "certManager.enabled"
asserts:
- equal:
path: spec.check
value: true
value: false
- it: key Override configured
template: testHasNestedKey.yaml
set:
Expand Down
3 changes: 0 additions & 3 deletions charts/common/test-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
defaults:
certManager:
enabled: false
4 changes: 4 additions & 0 deletions charts/common/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaults:
certManager:
enabled: false
imagePullSecret: "github"
Binary file modified charts/extension-manager-operator/charts/common-0.1.5.tgz
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ operator match the snapshot:
terminationGracePeriodSeconds: 10
4: |
apiVersion: v1
imagePullSecrets:
- name: github
kind: ServiceAccount
metadata:
name: extension-manager-operator
4 changes: 2 additions & 2 deletions charts/extension-manager-operator/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ tests:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: IfNotPresent
- it: configure imagePullSecret
- it: override imagePullSecret
template: service-account.yaml
set:
imagePullSecret: my-secret
imagePullSecretOverride: my-secret
asserts:
- equal:
path: imagePullSecrets
Expand Down
Binary file modified charts/portal/charts/common-0.1.5.tgz
Binary file not shown.

0 comments on commit 8c897f4

Please sign in to comment.