Merge "[AAI] Uses new tpls for repos / images"
[oom.git] / kubernetes / common / common / templates / _affinities.tpl
1 {{/* vim: set filetype=mustache: */}}
2 {{/*
3 # Copyright © 2020 Bitnami, Orange
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 Return a soft nodeAffinity definition
20 {{ include "common.affinities.nodes.soft" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
21 */}}
22 {{- define "common.affinities.nodes.soft" -}}
23 preferredDuringSchedulingIgnoredDuringExecution:
24   - preference:
25       matchExpressions:
26         key: {{ .key }}
27         operator: In
28         values:
29           {{- range .values }}
30           - {{ . }}
31           {{- end }}
32     weight: 1
33 {{- end -}}
34
35 {{/*
36 Return a hard nodeAffinity definition
37 {{ include "common.affinities.nodes.hard" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
38 */}}
39 {{- define "common.affinities.nodes.hard" -}}
40 requiredDuringSchedulingIgnoredDuringExecution:
41   nodeSelectorTerms:
42     - matchExpressions:
43         key: {{ .key }}
44         operator: In
45         values:
46           {{- range .values }}
47           - {{ . }}
48           {{- end }}
49 {{- end -}}
50
51 {{/*
52 Return a nodeAffinity definition
53 {{ include "common.affinities.nodes" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
54 */}}
55 {{- define "common.affinities.nodes" -}}
56   {{- if eq .type "soft" }}
57     {{- include "common.affinities.nodes.soft" . -}}
58   {{- else if eq .type "hard" }}
59     {{- include "common.affinities.nodes.hard" . -}}
60   {{- end -}}
61 {{- end -}}
62
63 {{/*
64 Return a soft podAffinity/podAntiAffinity definition
65 {{ include "common.affinities.pods.soft" (dict "component" "FOO" "context" $) -}}
66 */}}
67 {{- define "common.affinities.pods.soft" -}}
68 {{- $component := default "" .component -}}
69 preferredDuringSchedulingIgnoredDuringExecution:
70   - podAffinityTerm:
71       labelSelector:
72         matchLabels: {{- (include "common.matchLabels" (dict "dot" .context "matchLabels" (dict))) | nindent 10 }}
73           {{- if not (empty $component) }}
74           {{ printf "app.kubernetes.io/component: %s" $component }}
75           {{- end }}
76       namespaces:
77         - {{ include "common.namespace" .context }}
78       topologyKey: kubernetes.io/hostname
79     weight: 1
80 {{- end -}}
81
82 {{/*
83 Return a hard podAffinity/podAntiAffinity definition
84 {{ include "common.affinities.pods.hard" (dict "component" "FOO" "context" $) -}}
85 */}}
86 {{- define "common.affinities.pods.hard" -}}
87 {{- $component := default "" .component -}}
88 requiredDuringSchedulingIgnoredDuringExecution:
89   - labelSelector:
90       matchLabels: {{- (include "common.matchLabels" (dict "dot" .context "matchLabels" (dict))) | nindent 8 }}
91         {{- if not (empty $component) }}
92         {{ printf "app.kubernetes.io/component: %s" $component }}
93         {{- end }}
94     namespaces:
95       - {{ include "common.namespace" .context }}
96     topologyKey: kubernetes.io/hostname
97 {{- end -}}
98
99 {{/*
100 Return a podAffinity/podAntiAffinity definition
101 {{ include "common.affinities.pods" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
102 */}}
103 {{- define "common.affinities.pods" -}}
104   {{- if eq .type "soft" }}
105     {{- include "common.affinities.pods.soft" . -}}
106   {{- else if eq .type "hard" }}
107     {{- include "common.affinities.pods.hard" . -}}
108   {{- end -}}
109 {{- end -}}