helm-charts/charts/library/common/templates/lib/pod/metadata/_labels.tpl
2024-03-08 10:33:53 +01:00

36 lines
1.2 KiB
Smarty

{{- /*
Returns the value for labels
*/ -}}
{{- define "bjw-s.common.lib.pod.metadata.labels" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- /* Default labels */ -}}
{{- $labels := merge
(dict "common.bjw-s.dev/controller" $controllerObject.identifier)
-}}
{{- /* Fetch the Pod selectorLabels */ -}}
{{- $selectorLabels := include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | fromYaml -}}
{{- if not (empty $selectorLabels) -}}
{{- $labels = merge $selectorLabels $labels -}}
{{- end -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get (default dict $rootContext.Values.defaultPodOptions) "labels" -}}
{{- if not (empty $defaultOption) -}}
{{- $labels = merge $defaultOption $labels -}}
{{- end -}}
{{- /* See if a pod-specific override is set */ -}}
{{- if hasKey $controllerObject "pod" -}}
{{- $podOption := get $controllerObject.pod "labels" -}}
{{- if not (empty $podOption) -}}
{{- $labels = merge $podOption $labels -}}
{{- end -}}
{{- end -}}
{{- if not (empty $labels) -}}
{{- $labels | toYaml -}}
{{- end -}}
{{- end -}}