3 SPDX-License-Identifier: APACHE-2.0
6 {{/* vim: set filetype=mustache: */}}
8 Print instructions to get a secret value.
10 {{ include "common.utils.secret.getvalue" (dict "secret" "secret-name" "field" "secret-value-field" "context" $) }}
12 {{- define "common.utils.secret.getvalue" -}}
13 {{- $varname := include "common.utils.fieldToEnvVar" . -}}
14 export {{ $varname }}=$(kubectl get secret --namespace {{ include "common.names.namespace" .context | quote }} {{ .secret }} -o jsonpath="{.data.{{ .field }}}" | base64 -d)
18 Build env var name given a field
20 {{ include "common.utils.fieldToEnvVar" dict "field" "my-password" }}
22 {{- define "common.utils.fieldToEnvVar" -}}
23 {{- $fieldNameSplit := splitList "-" .field -}}
24 {{- $upperCaseFieldNameSplit := list -}}
26 {{- range $fieldNameSplit -}}
27 {{- $upperCaseFieldNameSplit = append $upperCaseFieldNameSplit ( upper . ) -}}
30 {{ join "_" $upperCaseFieldNameSplit }}
34 Gets a value from .Values given
36 {{ include "common.utils.getValueFromKey" (dict "key" "path.to.key" "context" $) }}
38 {{- define "common.utils.getValueFromKey" -}}
39 {{- $splitKey := splitList "." .key -}}
41 {{- $latestObj := $.context.Values -}}
42 {{- range $splitKey -}}
43 {{- if not $latestObj -}}
44 {{- printf "please review the entire path of '%s' exists in values" $.key | fail -}}
46 {{- $value = ( index $latestObj . ) -}}
47 {{- $latestObj = $value -}}
49 {{- printf "%v" (default "" $value) -}}
53 Returns first .Values key with a defined value or first of the list if all non-defined
55 {{ include "common.utils.getKeyFromList" (dict "keys" (list "path.to.key1" "path.to.key2") "context" $) }}
57 {{- define "common.utils.getKeyFromList" -}}
58 {{- $key := first .keys -}}
59 {{- $reverseKeys := reverse .keys }}
60 {{- range $reverseKeys }}
61 {{- $value := include "common.utils.getValueFromKey" (dict "key" . "context" $.context ) }}
66 {{- printf "%s" $key -}}
70 Checksum a template at "path" containing a *single* resource (ConfigMap,Secret) for use in pod annotations, excluding the metadata (see #18376).
72 {{ include "common.utils.checksumTemplate" (dict "path" "/configmap.yaml" "context" $) }}
74 {{- define "common.utils.checksumTemplate" -}}
75 {{- $obj := include (print .context.Template.BasePath .path) .context | fromYaml -}}
76 {{ omit $obj "apiVersion" "kind" "metadata" | toYaml | sha256sum }}