@@ -7,40 +7,59 @@ SPDX-License-Identifier: APACHE-2.0
7
7
8
8
{ {/*
9
9
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" ) } }
11
13
*/}}
12
14
{ {- 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" . -} }
26
24
{ {- end -} }
25
+ { {- $component := dict -} }
26
+ { {- with .component -} }
27
+ { {- $_ := set $component " app.kubernetes.io/component" . -} }
27
28
{ {- 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 ) } }
28
31
{ {- end -} }
29
32
30
33
{ {/*
31
34
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" ) } }
33
38
34
39
We don't want to loop over custom labels appending them to the selector
35
40
since it's very likely that it will break deployments, services, etc.
36
41
However, it's important to overwrite the standard labels if the user
37
42
overwrote them on metadata.labels fields.
38
43
*/}}
39
44
{ {- 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
+ -} }
42
62
{ {- else -} }
43
- app.kubernetes.io/name: { { include " common.names.name" . } }
44
- app.kubernetes.io/instance: { { .Release.Name } }
63
+ { {- $default | toYaml } }
45
64
{ {- end -} }
46
65
{ {- end -} }
0 commit comments