Skip to content

Commit 00f9cfa

Browse files
committed
[bitnami/common] Option to add "app.kubernetes.io/component" label
Signed-off-by: Dmytro Bondar <[email protected]>
1 parent dafa15f commit 00f9cfa

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

bitnami/common/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ annotations:
66
licenses: Apache-2.0
77
apiVersion: v2
88
# Please make sure that version and appVersion are always the same.
9-
appVersion: 2.29.0
9+
appVersion: 2.30.0
1010
description: A Library Helm Chart for grouping common logic between bitnami charts. This chart is not deployable by itself.
1111
home: https://bitnami.com
1212
icon: https://bitnami.com/downloads/logos/bitnami-mark.png
@@ -23,4 +23,4 @@ name: common
2323
sources:
2424
- https://github.com/bitnami/charts/tree/main/bitnami/common
2525
type: library
26-
version: 2.29.0
26+
version: 2.30.0

bitnami/common/templates/_affinities.tpl

+6-18
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,23 @@ Return a soft podAffinity/podAntiAffinity definition
7171
preferredDuringSchedulingIgnoredDuringExecution:
7272
- podAffinityTerm:
7373
labelSelector:
74-
matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" .context )) | nindent 10 }}
75-
{{- if not (empty $component) }}
76-
{{ printf "app.kubernetes.io/component: %s" $component }}
77-
{{- end }}
74+
matchLabels: {{- (include "common.labels.matchLabels" (dict "customLabels" $customLabels "context" .context "component" $component)) | nindent 10 }}
7875
{{- range $key, $value := $extraMatchLabels }}
7976
{{ $key }}: {{ $value | quote }}
8077
{{- end }}
8178
{{- if $extraNamespaces }}
8279
namespaces:
8380
- {{ .context.Release.Namespace }}
8481
{{- with $extraNamespaces }}
85-
{{ include "common.tplvalues.render" (dict "value" . "context" $) | nindent 8 }}
82+
{{- include "common.tplvalues.render" (dict "value" . "context" $) | nindent 8 }}
8683
{{- end }}
8784
{{- end }}
8885
topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }}
8986
weight: 1
9087
{{- range $extraPodAffinityTerms }}
9188
- podAffinityTerm:
9289
labelSelector:
93-
matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" $.context )) | nindent 10 }}
94-
{{- if not (empty $component) }}
95-
{{ printf "app.kubernetes.io/component: %s" $component }}
96-
{{- end }}
90+
matchLabels: {{- (include "common.labels.matchLabels" (dict "customLabels" $customLabels "context" $.context "component" $component)) | nindent 10 }}
9791
{{- range $key, $value := .extraMatchLabels }}
9892
{{ $key }}: {{ $value | quote }}
9993
{{- end }}
@@ -114,27 +108,21 @@ Return a hard podAffinity/podAntiAffinity definition
114108
{{- $extraNamespaces := default (list) .extraNamespaces -}}
115109
requiredDuringSchedulingIgnoredDuringExecution:
116110
- labelSelector:
117-
matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" .context )) | nindent 8 }}
118-
{{- if not (empty $component) }}
119-
{{ printf "app.kubernetes.io/component: %s" $component }}
120-
{{- end }}
111+
matchLabels: {{- (include "common.labels.matchLabels" (dict "customLabels" $customLabels "context" .context "component" $component)) | nindent 8 }}
121112
{{- range $key, $value := $extraMatchLabels }}
122113
{{ $key }}: {{ $value | quote }}
123114
{{- end }}
124115
{{- if $extraNamespaces }}
125116
namespaces:
126117
- {{ .context.Release.Namespace }}
127118
{{- with $extraNamespaces }}
128-
{{ include "common.tplvalues.render" (dict "value" . "context" $) | nindent 8 }}
119+
{{- include "common.tplvalues.render" (dict "value" . "context" $) | nindent 8 }}
129120
{{- end }}
130121
{{- end }}
131122
topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }}
132123
{{- range $extraPodAffinityTerms }}
133124
- labelSelector:
134-
matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" $.context )) | nindent 8 }}
135-
{{- if not (empty $component) }}
136-
{{ printf "app.kubernetes.io/component: %s" $component }}
137-
{{- end }}
125+
matchLabels: {{- (include "common.labels.matchLabels" (dict "customLabels" $customLabels "context" $.context "component" $component)) | nindent 8 }}
138126
{{- range $key, $value := .extraMatchLabels }}
139127
{{ $key }}: {{ $value | quote }}
140128
{{- end }}

bitnami/common/templates/_labels.tpl

+38-19
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,59 @@ SPDX-License-Identifier: APACHE-2.0
77

88
{{/*
99
Kubernetes standard labels
10-
{{ include "common.labels.standard" (dict "customLabels" .Values.commonLabels "context" $) -}}
10+
{{- include "common.labels.standard" $ }}
11+
{{- include "common.labels.standard" (dict "customLabels" .Values.commonLabels "context" $) }}
12+
{{- include "common.labels.standard" (dict "customLabels" .Values.commonLabels "context" $ "component" "FOO") }}
1113
*/}}
1214
{{- define "common.labels.standard" -}}
13-
{{- if and (hasKey . "customLabels") (hasKey . "context") -}}
14-
{{- $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 -}}
15-
{{- with .context.Chart.AppVersion -}}
16-
{{- $_ := set $default "app.kubernetes.io/version" . -}}
17-
{{- end -}}
18-
{{ template "common.tplvalues.merge" (dict "values" (list .customLabels $default) "context" .context) }}
19-
{{- else -}}
20-
app.kubernetes.io/name: {{ include "common.names.name" . }}
21-
helm.sh/chart: {{ include "common.names.chart" . }}
22-
app.kubernetes.io/instance: {{ .Release.Name }}
23-
app.kubernetes.io/managed-by: {{ .Release.Service }}
24-
{{- with .Chart.AppVersion }}
25-
app.kubernetes.io/version: {{ . | quote }}
15+
{{- $context := default . .context -}}
16+
{{- $default := dict
17+
"app.kubernetes.io/instance" $context.Release.Name
18+
"app.kubernetes.io/managed-by" $context.Release.Service
19+
"app.kubernetes.io/name" (include "common.names.name" $context)
20+
"helm.sh/chart" (include "common.names.chart" $context)
21+
-}}
22+
{{- with $context.Chart.AppVersion -}}
23+
{{- $_ := set $default "app.kubernetes.io/version" . -}}
2624
{{- end -}}
25+
{{- $component := dict -}}
26+
{{- with .component -}}
27+
{{- $_ := set $component "app.kubernetes.io/component" . -}}
2728
{{- end -}}
29+
{{- /* If "component" key is present it will overwrite label from .customLabels for compatibility with selector */ -}}
30+
{{- include "common.tplvalues.merge" (dict "values" (compact (list $component .customLabels $default)) "context" $context) }}
2831
{{- end -}}
2932

3033
{{/*
3134
Labels used on immutable fields such as deploy.spec.selector.matchLabels or svc.spec.selector
32-
{{ include "common.labels.matchLabels" (dict "customLabels" .Values.podLabels "context" $) -}}
35+
{{- include "common.labels.matchLabels" $ }}
36+
{{- include "common.labels.matchLabels" (dict "customLabels" .Values.podLabels "context" $) }}
37+
{{- include "common.labels.matchLabels" (dict "customLabels" .Values.podLabels "context" $ "component" "FOO") }}
3338

3439
We don't want to loop over custom labels appending them to the selector
3540
since it's very likely that it will break deployments, services, etc.
3641
However, it's important to overwrite the standard labels if the user
3742
overwrote them on metadata.labels fields.
3843
*/}}
3944
{{- define "common.labels.matchLabels" -}}
40-
{{- if and (hasKey . "customLabels") (hasKey . "context") -}}
41-
{{ 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 }}
45+
{{- $context := default . .context -}}
46+
{{- $default := dict
47+
"app.kubernetes.io/instance" $context.Release.Name
48+
"app.kubernetes.io/name" (include "common.names.name" $context)
49+
-}}
50+
{{- with .component -}}
51+
{{- $_ := set $default "app.kubernetes.io/component" . -}}
52+
{{- end -}}
53+
{{- if .customLabels -}}
54+
{{- merge
55+
(pick
56+
(include "common.tplvalues.render" (dict "value" .customLabels "context" $context) | fromYaml)
57+
"app.kubernetes.io/name"
58+
"app.kubernetes.io/instance"
59+
)
60+
$default | toYaml
61+
-}}
4262
{{- else -}}
43-
app.kubernetes.io/name: {{ include "common.names.name" . }}
44-
app.kubernetes.io/instance: {{ .Release.Name }}
63+
{{- $default | toYaml }}
4564
{{- end -}}
4665
{{- end -}}

0 commit comments

Comments
 (0)