_labels.tpl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. {{/*
  2. Copyright Broadcom, Inc. All Rights Reserved.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{/* vim: set filetype=mustache: */}}
  6. {{/*
  7. Kubernetes standard labels
  8. {{ include "common.labels.standard" (dict "customLabels" .Values.commonLabels "context" $) -}}
  9. */}}
  10. {{- define "common.labels.standard" -}}
  11. {{- if and (hasKey . "customLabels") (hasKey . "context") -}}
  12. {{- $default := dict "app.kubernetes.io/name" (include "common.names.name" .context) "helm.sh/chart" (include "common.names.chart" .context) "app.kubernetes.io/instance" .context.Release.Name "app.kubernetes.io/managed-by" .context.Release.Service -}}
  13. {{- with .context.Chart.AppVersion -}}
  14. {{- $_ := set $default "app.kubernetes.io/version" . -}}
  15. {{- end -}}
  16. {{ template "common.tplvalues.merge" (dict "values" (list .customLabels $default) "context" .context) }}
  17. {{- else -}}
  18. app.kubernetes.io/name: {{ include "common.names.name" . }}
  19. helm.sh/chart: {{ include "common.names.chart" . }}
  20. app.kubernetes.io/instance: {{ .Release.Name }}
  21. app.kubernetes.io/managed-by: {{ .Release.Service }}
  22. {{- with .Chart.AppVersion }}
  23. app.kubernetes.io/version: {{ . | quote }}
  24. {{- end -}}
  25. {{- end -}}
  26. {{- end -}}
  27. {{/*
  28. Labels used on immutable fields such as deploy.spec.selector.matchLabels or svc.spec.selector
  29. {{ include "common.labels.matchLabels" (dict "customLabels" .Values.podLabels "context" $) -}}
  30. We don't want to loop over custom labels appending them to the selector
  31. since it's very likely that it will break deployments, services, etc.
  32. However, it's important to overwrite the standard labels if the user
  33. overwrote them on metadata.labels fields.
  34. */}}
  35. {{- define "common.labels.matchLabels" -}}
  36. {{- if and (hasKey . "customLabels") (hasKey . "context") -}}
  37. {{ merge (pick (include "common.tplvalues.render" (dict "value" .customLabels "context" .context) | fromYaml) "app.kubernetes.io/name" "app.kubernetes.io/instance") (dict "app.kubernetes.io/name" (include "common.names.name" .context) "app.kubernetes.io/instance" .context.Release.Name ) | toYaml }}
  38. {{- else -}}
  39. app.kubernetes.io/name: {{ include "common.names.name" . }}
  40. app.kubernetes.io/instance: {{ .Release.Name }}
  41. {{- end -}}
  42. {{- end -}}