Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / mongodb / common / templates / _affinities.tpl
1 {{/*
2 Copyright VMware, Inc.
3 SPDX-License-Identifier: APACHE-2.0
4 */}}
5
6 {{/* vim: set filetype=mustache: */}}
7
8 {{/*
9 Return a soft nodeAffinity definition
10 {{ include "common.affinities.nodes.soft" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
11 */}}
12 {{- define "common.affinities.nodes.soft" -}}
13 preferredDuringSchedulingIgnoredDuringExecution:
14   - preference:
15       matchExpressions:
16         - key: {{ .key }}
17           operator: In
18           values:
19             {{- range .values }}
20             - {{ . | quote }}
21             {{- end }}
22     weight: 1
23 {{- end -}}
24
25 {{/*
26 Return a hard nodeAffinity definition
27 {{ include "common.affinities.nodes.hard" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
28 */}}
29 {{- define "common.affinities.nodes.hard" -}}
30 requiredDuringSchedulingIgnoredDuringExecution:
31   nodeSelectorTerms:
32     - matchExpressions:
33         - key: {{ .key }}
34           operator: In
35           values:
36             {{- range .values }}
37             - {{ . | quote }}
38             {{- end }}
39 {{- end -}}
40
41 {{/*
42 Return a nodeAffinity definition
43 {{ include "common.affinities.nodes" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
44 */}}
45 {{- define "common.affinities.nodes" -}}
46   {{- if eq .type "soft" }}
47     {{- include "common.affinities.nodes.soft" . -}}
48   {{- else if eq .type "hard" }}
49     {{- include "common.affinities.nodes.hard" . -}}
50   {{- end -}}
51 {{- end -}}
52
53 {{/*
54 Return a topologyKey definition
55 {{ include "common.affinities.topologyKey" (dict "topologyKey" "BAR") -}}
56 */}}
57 {{- define "common.affinities.topologyKey" -}}
58 {{ .topologyKey | default "kubernetes.io/hostname" -}}
59 {{- end -}}
60
61 {{/*
62 Return a soft podAffinity/podAntiAffinity definition
63 {{ include "common.affinities.pods.soft" (dict "component" "FOO" "customLabels" .Values.podLabels "extraMatchLabels" .Values.extraMatchLabels "topologyKey" "BAR" "extraPodAffinityTerms" .Values.extraPodAffinityTerms "context" $) -}}
64 */}}
65 {{- define "common.affinities.pods.soft" -}}
66 {{- $component := default "" .component -}}
67 {{- $customLabels := default (dict) .customLabels -}}
68 {{- $extraMatchLabels := default (dict) .extraMatchLabels -}}
69 {{- $extraPodAffinityTerms := default (list) .extraPodAffinityTerms -}}
70 preferredDuringSchedulingIgnoredDuringExecution:
71   - podAffinityTerm:
72       labelSelector:
73         matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" .context )) | nindent 10 }}
74           {{- if not (empty $component) }}
75           {{ printf "app.kubernetes.io/component: %s" $component }}
76           {{- end }}
77           {{- range $key, $value := $extraMatchLabels }}
78           {{ $key }}: {{ $value | quote }}
79           {{- end }}
80       topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }}
81     weight: 1
82   {{- range $extraPodAffinityTerms }}
83   - podAffinityTerm:
84       labelSelector:
85         matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" $.context )) | nindent 10 }}
86           {{- if not (empty $component) }}
87           {{ printf "app.kubernetes.io/component: %s" $component }}
88           {{- end }}
89           {{- range $key, $value := .extraMatchLabels }}
90           {{ $key }}: {{ $value | quote }}
91           {{- end }}
92       topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }}
93     weight: {{ .weight | default 1 -}}
94   {{- end -}}
95 {{- end -}}
96
97 {{/*
98 Return a hard podAffinity/podAntiAffinity definition
99 {{ include "common.affinities.pods.hard" (dict "component" "FOO" "customLabels" .Values.podLabels "extraMatchLabels" .Values.extraMatchLabels "topologyKey" "BAR" "extraPodAffinityTerms" .Values.extraPodAffinityTerms "context" $) -}}
100 */}}
101 {{- define "common.affinities.pods.hard" -}}
102 {{- $component := default "" .component -}}
103 {{- $customLabels := default (dict) .customLabels -}}
104 {{- $extraMatchLabels := default (dict) .extraMatchLabels -}}
105 {{- $extraPodAffinityTerms := default (list) .extraPodAffinityTerms -}}
106 requiredDuringSchedulingIgnoredDuringExecution:
107   - labelSelector:
108       matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" .context )) | nindent 8 }}
109         {{- if not (empty $component) }}
110         {{ printf "app.kubernetes.io/component: %s" $component }}
111         {{- end }}
112         {{- range $key, $value := $extraMatchLabels }}
113         {{ $key }}: {{ $value | quote }}
114         {{- end }}
115     topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }}
116   {{- range $extraPodAffinityTerms }}
117   - labelSelector:
118       matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" $.context )) | nindent 8 }}
119         {{- if not (empty $component) }}
120         {{ printf "app.kubernetes.io/component: %s" $component }}
121         {{- end }}
122         {{- range $key, $value := .extraMatchLabels }}
123         {{ $key }}: {{ $value | quote }}
124         {{- end }}
125     topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }}
126   {{- end -}}
127 {{- end -}}
128
129 {{/*
130 Return a podAffinity/podAntiAffinity definition
131 {{ include "common.affinities.pods" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
132 */}}
133 {{- define "common.affinities.pods" -}}
134   {{- if eq .type "soft" }}
135     {{- include "common.affinities.pods.soft" . -}}
136   {{- else if eq .type "hard" }}
137     {{- include "common.affinities.pods.hard" . -}}
138   {{- end -}}
139 {{- end -}}