Merge "[DMAAP] DMaaP ServiceMesh compatibility"
[oom.git] / kubernetes / common / common / templates / _labels.tpl
1 {{/*
2 # Copyright © 2019 Orange
3 # Modifications Copyright (C) 2022 Bell Canada
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 */}}
17
18
19
20 {{/*
21 Common labels
22 The function takes several arguments (inside a dictionary):
23      - .dot : environment (.)
24      - .labels : labels to add (dict)
25 */}}
26 {{- define "common.labels" -}}
27 {{- $dot := default . .dot -}}
28 app.kubernetes.io/name: {{ include "common.name" $dot }}
29 {{ if not .ignoreHelmChart }}
30 helm.sh/chart: {{ include "common.chart" $dot }}
31 {{- end }}
32 app.kubernetes.io/instance: {{ include "common.release" $dot }}
33 app.kubernetes.io/managed-by: {{ $dot.Release.Service }}
34 {{ if .labels }}
35 {{- include "common.tplValue" (dict "value" .labels "context" $dot) }}
36 {{- end }}
37 {{- end -}}
38
39 {{/*
40 Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
41 The function takes several arguments (inside a dictionary):
42      - .dot : environment (.)
43      - .matchLabels: selectors/matchlLabels to add (dict)
44 */}}
45 {{- define "common.matchLabels" -}}
46 {{- $dot := default . .dot -}}
47 {{- $matchLabels := default (dict) .matchLabels -}}
48 {{- if not $matchLabels.nameNoMatch -}}
49 app.kubernetes.io/name: {{ include "common.name" $dot }}
50 {{- end }}
51 app.kubernetes.io/instance: {{ include "common.release" $dot }}
52 {{- if $matchLabels }}
53 {{$_ := unset $matchLabels "nameNoMatch"}}
54 {{- include "common.tplValue" (dict "value" $matchLabels "context" $dot) }}
55 {{- end }}
56 {{- end -}}
57
58 {{/*
59   Generate "top" metadata for Deployment / StatefulSet / ...
60   The function takes several arguments (inside a dictionary):
61      - .dot : environment (.)
62      - .labels: labels to add (dict)
63      - .suffix: suffix to name
64
65 */}}
66 {{- define "common.resourceMetadata" -}}
67 {{- $dot := default . .dot -}}
68 {{- $suffix := default "" .suffix -}}
69 {{- $labels := default (dict) .labels -}}
70 {{- $annotations := default (dict) .annotations -}}
71 name: {{ include "common.fullname" (dict "suffix" $suffix "dot" $dot )}}
72 namespace: {{ include "common.namespace" $dot }}
73 labels: {{- include "common.labels" (dict "labels" $labels "ignoreHelmChart" .ignoreHelmChart "dot" $dot ) | nindent 2 }}
74 {{- if $annotations }}
75 annotations:  {{- include "common.tplValue" (dict "value" $annotations "context" $dot) | nindent 2}}
76 {{- end }}
77 {{- end -}}
78
79 {{/*
80   Generate selectors for Deployment / StatefulSet / ...
81     The function takes several arguments (inside a dictionary):
82      - .dot : environment (.)
83      - .matchLabels: labels to add (dict)
84 */}}
85 {{- define "common.selectors" -}}
86 {{- $dot := default . .dot -}}
87 {{- $matchLabels := default (dict) .matchLabels -}}
88 matchLabels: {{- include "common.matchLabels" (dict "matchLabels" $matchLabels "dot" $dot) | nindent 2 }}
89 {{- end -}}
90
91 {{/*
92   Generate "template" metadata for Deployment / StatefulSet / ...
93     The function takes several arguments (inside a dictionary)
94      - .dot : environment (.)
95      - .labels: labels to add (dict)
96 */}}
97 {{- define "common.templateMetadata" -}}
98 {{- $dot := default . .dot -}}
99 {{- $labels := default (dict) .labels -}}
100 {{- if $dot.Values.podAnnotations }}
101 annotations: {{- include "common.tplValue" (dict "value" $dot.Values.podAnnotations "context" $dot) | nindent 2 }}
102 {{- end }}
103 labels: {{- include "common.labels" (dict "labels" $labels "ignoreHelmChart" .ignoreHelmChart "dot" $dot) | nindent 2 }}
104 name: {{ include "common.name" $dot }}
105 {{- end -}}