Skip to content

Commit

Permalink
feat: support some custom labels on "common.labels.matchLabels"
Browse files Browse the repository at this point in the history
Signed-off-by: juan131 <[email protected]>
  • Loading branch information
juan131 committed Aug 4, 2023
1 parent 81bd30d commit 2b1138c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bitnami/common/templates/_labels.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ app.kubernetes.io/managed-by: {{ .context.Release.Service }}
Labels used on immutable fields such as deploy.spec.selector.matchLabels or svc.spec.selector
{{ include "common.labels.matchLabels" (dict "customLabels" .Values.podLabels "context" $) -}}

We don't want to loop over custom labels appending them to the selector
since it's very likely that it will break deployments, services, etc.
However, it's important to overwrite the standard labels if the user
overwrote them on metadata.labels fields.
We want to avoid including standard labels that are likely to mutate
since they will break deployments, services, etc.
On the other hand, it's important to overwrite the immutable standard labels
if the user overwrote them on metadata.labels fields.
*/}}
{{- define "common.labels.matchLabels" -}}
{{- $customLabels := default (dict) .customLabels -}}
app.kubernetes.io/name: {{ ternary (get $customLabels "app.kubernetes.io/name") (include "common.names.name" .context) (hasKey $customLabels "app.kubernetes.io/name") }}
app.kubernetes.io/instance: {{ ternary (get $customLabels "app.kubernetes.io/instance") .context.Release.Name (hasKey $customLabels "app.kubernetes.io/instance") }}
{{- $filteredLabels := omit $customLabels "app.kubernetes.io/name" "app.kubernetes.io/instance" "app.kubernetes.io/managed-by" "helm.sh/chart" -}}
{{- range $key, $value := $filteredLabels }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end -}}

0 comments on commit 2b1138c

Please sign in to comment.