-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OPSEXP-1862: named templates to help chart plumbing (#93)
- Loading branch information
Showing
4 changed files
with
92 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{{/* | ||
Read from either a Configmap entry or a value (in this order) | ||
Usage: include "alfresco-common.read.cm.then.value" (dict "ns" "" "key" "" "context" (dict "existingConfigMap" (dict "name" "" "keys" dict ...))) | ||
*/}} | ||
{{- define "alfresco-common.read.cm.then.value" -}} | ||
{{- $ns := .ns }} | ||
{{- $key := .key }} | ||
{{- with .context }} | ||
{{- if .existingConfigMap.name }} | ||
{{- $defaultLookup := (dict "data" dict) }} | ||
{{- $lookup := lookup "v1" "ConfigMap" $ns .existingConfigMap.name | default $defaultLookup }} | ||
{{- get $lookup.data (index .existingConfigMap.keys $key) }} | ||
{{- else -}} | ||
{{- index . $key }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end -}} | ||
|
||
{{/* | ||
Read from either a Configmap entry or a value (in this order) and fail if returns empty | ||
Usage: include "alfresco-common.reqRead.cm.then.value" (dict "ns" "" "key" "" "context" (dict "existingConfigMap" (dict "name" "" "keys" dict ...))) | ||
*/}} | ||
{{- define "alfresco-common.reqRead.cm.then.value" -}} | ||
{{- $ns := .ns }} | ||
{{- $key := .key }} | ||
{{- $result := include "alfresco-common.read.cm.then.value" . }} | ||
{{- required (printf "key %s not found in provided context neither in ConfigMap %s/%s" $key $ns .context.existingConfigMap.name) $result }} | ||
{{- end -}} | ||
|
||
{{/* | ||
Check whether a secret has a specific entry (don't read it). Return "true" if entry is present in secret or value, otherwise "false" | ||
Usage: include "alfresco-common.haskey.secret" (dict "ns" "" "key" "" "context" (dict "existingSecret" (dict "name" "" "keys" (dict ...)))) | ||
*/}} | ||
{{- define "alfresco-common.haskey.secret" -}} | ||
{{- $ns := .ns }} | ||
{{- $key := .key }} | ||
{{- with .context }} | ||
{{- if .existingSecret.name }} | ||
{{- $defaultLookup := (dict "data" dict) }} | ||
{{- $lookup := lookup "v1" "Secret" $ns .existingSecret.name | default $defaultLookup }} | ||
{{- hasKey $lookup.data (index .existingSecret.keys $key) }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end -}} | ||
{{/* | ||
Compute Secret checksum whether it's read from values or from secrets | ||
Usage: include "alfresco-common.secret-checksum" (dict "ns" "" "configKey" "somekey" "context" (dict "somekey" (dict "existingConfigMap" (dict "keys" dict))(dict "existingSecret" (dict "keys" dict))...) "configKey" "some-key") | ||
*/}} | ||
{{- define "alfresco-common.checksum.config" -}} | ||
{{- $ns := required "template needs to be given the release namepace" .ns }} | ||
{{- $configCtx := index .context .configKey }} | ||
{{- $lookedup_secret := "" }} | ||
{{- $lookedup_cm := "" }} | ||
{{- $defaultLookup := dict "data" dict -}} | ||
{{/* If configmap is given, checksum & concat its keys otherwise checksum & concat values */}} | ||
{{- with $configCtx }} | ||
{{- if .existingConfigMap.name }} | ||
{{- $lookup := lookup "v1" "ConfigMap" $ns .existingConfigMap.name | default $defaultLookup }} | ||
{{- range $k := (keys .existingConfigMap.keys | sortAlpha) }} | ||
{{- $lookedup_cm = cat $lookedup_cm (pick $lookup.data (index $configCtx "existingConfigMap" "keys" $k) | toJson | sha256sum) }} | ||
{{- end }} | ||
{{- else }} | ||
{{- range $k := (keys .existingConfigMap.keys | sortAlpha) }} | ||
{{- $lookedup_cm = cat $lookedup_cm (index $configCtx $k | toJson | sha256sum) }} | ||
{{- end }} | ||
{{- end -}} | ||
{{/* If secret is given, checksum & concat its keys otherwise checksum & concat values */}} | ||
{{- if .existingSecret.name }} | ||
{{- $lookup := lookup "v1" "Secret" $ns .existingSecret.name | default $defaultLookup }} | ||
{{- range $k := (keys .existingSecret.keys | sortAlpha) }} | ||
{{- $lookedup_secret = cat $lookedup_secret (pick $lookup.data (index $configCtx "existingSecret" "keys" $k) | toJson | sha256sum) }} | ||
{{- end }} | ||
{{- else }} | ||
{{- range $k := (keys .existingSecret.keys | sortAlpha) }} | ||
{{- $lookedup_secret = cat $lookedup_secret (index $configCtx (index $configCtx "existingSecret" "keys" $k) | toJson | sha256sum) }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end -}} | ||
{{/* Finaly checksums both concatenated hashes */}} | ||
checksum.config.alfresco.org/{{ $.configKey }}: {{- cat $lookedup_cm $lookedup_secret | trim | sha256sum | indent 1 }} | ||
{{- end -}} |