Merge "Eliminate unnecessary node ports"
[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 {{- if not .matchLabels.nameNoMatch -}}
45 app.kubernetes.io/name: {{ include "common.name" $dot }}
46 {{- end }}
47 app.kubernetes.io/instance: {{ include "common.release" $dot }}
48 {{ if .matchLabels }}
49 {{$_ := unset .matchLabels "nameNoMatch"}}
50 {{- include "common.tplValue" (dict "value" .matchLabels "context" $dot) }}
51 {{- end -}}
52 {{- end -}}
53
54 {{/*
55   Generate "top" metadata for Deployment / StatefulSet / ...
56   The function takes several arguments (inside a dictionary):
57      - .dot : environment (.)
58      - .labels: labels to add (dict)
59      - .suffix: suffix to name
60
61 */}}
62 {{- define "common.resourceMetadata" -}}
63 {{- $dot := default . .dot -}}
64 {{- $suffix := default "" .suffix -}}
65 {{- $labels := default (dict) .labels -}}
66
67 name: {{ include "common.fullname" (dict "suffix" $suffix "dot" $dot )}}
68 namespace: {{ include "common.namespace" $dot }}
69 labels: {{- include "common.labels" (dict "labels" $labels "dot" $dot ) | nindent 2 }}
70 {{- end -}}
71
72 {{/*
73   Generate selectors for Deployment / StatefulSet / ...
74     The function takes several arguments (inside a dictionary):
75      - .dot : environment (.)
76      - .matchLabels: labels to add (dict)
77 */}}
78 {{- define "common.selectors" -}}
79 {{- $dot := default . .dot -}}
80 {{- $matchLabels := default (dict) .matchLabels -}}
81 matchLabels: {{- include "common.matchLabels" (dict "matchLabels" $matchLabels "dot" $dot) | nindent 2 }}
82 {{- end -}}
83
84 {{/*
85   Generate "template" metadata for Deployment / StatefulSet / ...
86     The function takes several arguments (inside a dictionary)
87      - .dot : environment (.)
88      - .labels: labels to add (dict)
89 */}}
90 {{- define "common.templateMetadata" -}}
91 {{- $dot := default . .dot -}}
92 {{- $labels := default (dict) .labels -}}
93 {{- if $dot.Values.podAnnotations }}
94 annotations: {{- include "common.tplValue" (dict "value" $dot.Values.podAnnotations "context" $) | nindent 2 }}
95 {{- end }}
96 labels: {{- include "common.labels" (dict "labels" $labels "dot" $dot) | nindent 2 }}
97 name: {{ include "common.name" $dot }}
98 {{- end -}}