f2bd1a11410dc5ab5ee9d13441787115f8666736
[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 app: {{ include "common.name" $dot }}
30 {{ if not .ignoreHelmChart }}
31 helm.sh/chart: {{ include "common.chart" $dot }}
32 {{- end }}
33 app.kubernetes.io/instance: {{ include "common.release" $dot }}
34 app.kubernetes.io/managed-by: {{ $dot.Release.Service }}
35 {{ if .labels }}
36 {{- include "common.tplValue" (dict "value" .labels "context" $dot) }}
37 {{- end }}
38 {{- end -}}
39
40 {{/*
41 Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
42 The function takes several arguments (inside a dictionary):
43      - .dot : environment (.)
44      - .matchLabels: selectors/matchlLabels to add (dict)
45 */}}
46 {{- define "common.matchLabels" -}}
47 {{- $dot := default . .dot -}}
48 {{- $matchLabels := default (dict) .matchLabels -}}
49 {{- if not $matchLabels.nameNoMatch -}}
50 app.kubernetes.io/name: {{ include "common.name" $dot }}
51 {{- end }}
52 app.kubernetes.io/instance: {{ include "common.release" $dot }}
53 {{- if $matchLabels }}
54 {{$_ := unset $matchLabels "nameNoMatch"}}
55 {{- include "common.tplValue" (dict "value" $matchLabels "context" $dot) }}
56 {{- end }}
57 {{- end -}}
58
59 {{/*
60   Generate "top" metadata for Deployment / StatefulSet / ...
61   The function takes several arguments (inside a dictionary):
62      - .dot : environment (.)
63      - .labels: labels to add (dict)
64      - .suffix: suffix to name
65
66 */}}
67 {{- define "common.resourceMetadata" -}}
68 {{- $dot := default . .dot -}}
69 {{- $suffix := default "" .suffix -}}
70 {{- $labels := default (dict) .labels -}}
71 {{- $annotations := default (dict) .annotations -}}
72 name: {{ include "common.fullname" (dict "suffix" $suffix "dot" $dot )}}
73 namespace: {{ include "common.namespace" $dot }}
74 labels: {{- include "common.labels" (dict "labels" $labels "ignoreHelmChart" .ignoreHelmChart "dot" $dot ) | nindent 2 }}
75 {{- if $annotations }}
76 annotations:  {{- include "common.tplValue" (dict "value" $annotations "context" $dot) | nindent 2}}
77 {{- end }}
78 {{- end -}}
79
80 {{/*
81   Generate selectors for Deployment / StatefulSet / ...
82     The function takes several arguments (inside a dictionary):
83      - .dot : environment (.)
84      - .matchLabels: labels to add (dict)
85 */}}
86 {{- define "common.selectors" -}}
87 {{- $dot := default . .dot -}}
88 {{- $matchLabels := default (dict) .matchLabels -}}
89 matchLabels: {{- include "common.matchLabels" (dict "matchLabels" $matchLabels "dot" $dot) | nindent 2 }}
90 {{- end -}}
91
92 {{/*
93   Generate "template" metadata for Deployment / StatefulSet / ...
94     The function takes several arguments (inside a dictionary)
95      - .dot : environment (.)
96      - .labels: labels to add (dict)
97 */}}
98 {{- define "common.templateMetadata" -}}
99 {{- $dot := default . .dot -}}
100 {{- $labels := default (dict) .labels -}}
101 {{- if $dot.Values.podAnnotations }}
102 annotations: {{- include "common.tplValue" (dict "value" $dot.Values.podAnnotations "context" $dot) | nindent 2 }}
103 {{- end }}
104 labels: {{- include "common.labels" (dict "labels" $labels "ignoreHelmChart" .ignoreHelmChart "dot" $dot) | nindent 2 }}
105 name: {{ include "common.name" $dot }}
106 {{- end -}}