helm-charts/charts/library/common/templates/lib/pod/metadata/_annotations.tpl
Bernd Schorgers e68b41ed0a
feat(common): Release common library 3.6.0 (#364)
Signed-off-by: solidDoWant <fred.heinecke@yahoo.com>
Co-authored-by: solidDoWant <fred.heinecke@yahoo.com>
2024-12-26 10:29:00 +00:00

82 lines
2.8 KiB
Smarty

{{- /*
Returns the value for annotations
*/ -}}
{{- define "bjw-s.common.lib.pod.metadata.annotations" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- /* Default annotations */ -}}
{{- $annotations := merge
(dict)
-}}
{{- /* Include global annotations if specified */ -}}
{{- if $rootContext.Values.global.propagateGlobalMetadataToPods -}}
{{- $annotations = merge
(include "bjw-s.common.lib.metadata.globalAnnotations" $rootContext | fromYaml)
$annotations
-}}
{{- end -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get (default dict $rootContext.Values.defaultPodOptions) "annotations" -}}
{{- if not (empty $defaultOption) -}}
{{- $annotations = merge $defaultOption $annotations -}}
{{- end -}}
{{- /* See if a pod-specific override is set */ -}}
{{- if hasKey $controllerObject "pod" -}}
{{- $podOption := get $controllerObject.pod "annotations" -}}
{{- if not (empty $podOption) -}}
{{- $annotations = merge $podOption $annotations -}}
{{- end -}}
{{- end -}}
{{- /* Add configMaps checksum */ -}}
{{- $configMapsFound := dict -}}
{{- range $name, $configmap := $rootContext.Values.configMaps -}}
{{- $configMapEnabled := true -}}
{{- if hasKey $configmap "enabled" -}}
{{- $configMapEnabled = $configmap.enabled -}}
{{- end -}}
{{- $configMapIncludeInChecksum := true -}}
{{- if hasKey $configmap "includeInChecksum" -}}
{{- $configMapIncludeInChecksum = $configmap.includeInChecksum -}}
{{- end -}}
{{- if and $configMapEnabled $configMapIncludeInChecksum -}}
{{- $_ := set $configMapsFound $name (toYaml $configmap.data | sha256sum) -}}
{{- end -}}
{{- end -}}
{{- if $configMapsFound -}}
{{- $annotations = merge
(dict "checksum/configMaps" (toYaml $configMapsFound | sha256sum))
$annotations
-}}
{{- end -}}
{{- /* Add Secrets checksum */ -}}
{{- $secretsFound := dict -}}
{{- range $name, $secret := $rootContext.Values.secrets -}}
{{- $secretEnabled := true -}}
{{- if hasKey $secret "enabled" -}}
{{- $secretEnabled = $secret.enabled -}}
{{- end -}}
{{- $secretIncludeInChecksum := true -}}
{{- if hasKey $secret "includeInChecksum" -}}
{{- $secretIncludeInChecksum = $secret.includeInChecksum -}}
{{- end -}}
{{- if and $secretEnabled $secretIncludeInChecksum -}}
{{- $_ := set $secretsFound $name (toYaml $secret.stringData | sha256sum) -}}
{{- end -}}
{{- end -}}
{{- if $secretsFound -}}
{{- $annotations = merge
(dict "checksum/secrets" (toYaml $secretsFound | sha256sum))
$annotations
-}}
{{- end -}}
{{- if not (empty $annotations) -}}
{{- $annotations | toYaml -}}
{{- end -}}
{{- end -}}