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