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