[vFW_CNF_CDS] Update of python-sdk for vFW_CNF use case
[demo.git] / tutorials / ApacheCNF / templates / cba / Templates / k8s-configs / deployment-config / charts / common / templates / _affinities.tpl
1 {{/* vim: set filetype=mustache: */}}
2
3 {{/*
4 Return a soft nodeAffinity definition 
5 {{ include "common.affinities.nodes.soft" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
6 */}}
7 {{- define "common.affinities.nodes.soft" -}}
8 preferredDuringSchedulingIgnoredDuringExecution:
9   - preference:
10       matchExpressions:
11         key: {{ .key }}
12         operator: In
13         values:
14           {{- range .values }}
15           - {{ . }}
16           {{- end }}
17     weight: 1
18 {{- end -}}
19
20 {{/*
21 Return a hard nodeAffinity definition
22 {{ include "common.affinities.nodes.hard" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
23 */}}
24 {{- define "common.affinities.nodes.hard" -}}
25 requiredDuringSchedulingIgnoredDuringExecution:
26   nodeSelectorTerms:
27     - matchExpressions:
28         key: {{ .key }}
29         operator: In
30         values:
31           {{- range .values }}
32           - {{ . }}
33           {{- end }}
34 {{- end -}}
35
36 {{/*
37 Return a nodeAffinity definition
38 {{ include "common.affinities.nodes" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
39 */}}
40 {{- define "common.affinities.nodes" -}}
41   {{- if eq .type "soft" }}
42     {{- include "common.affinities.nodes.soft" . -}}
43   {{- else if eq .type "hard" }}
44     {{- include "common.affinities.nodes.hard" . -}}
45   {{- end -}}
46 {{- end -}}
47
48 {{/*
49 Return a soft podAffinity/podAntiAffinity definition
50 {{ include "common.affinities.pods.soft" (dict "component" "FOO" "context" $) -}}
51 */}}
52 {{- define "common.affinities.pods.soft" -}}
53 {{- $component := default "" .component -}}
54 preferredDuringSchedulingIgnoredDuringExecution:
55   - podAffinityTerm:
56       labelSelector:
57         matchLabels: {{- (include "common.labels.matchLabels" .context) | nindent 10 }}
58           {{- if not (empty $component) }}
59           {{ printf "app.kubernetes.io/component: %s" $component }}
60           {{- end }}
61       namespaces:
62         - {{ .context.Release.Namespace }}
63       topologyKey: kubernetes.io/hostname
64     weight: 1
65 {{- end -}}
66
67 {{/*
68 Return a hard podAffinity/podAntiAffinity definition
69 {{ include "common.affinities.pods.hard" (dict "component" "FOO" "context" $) -}}
70 */}}
71 {{- define "common.affinities.pods.hard" -}}
72 {{- $component := default "" .component -}}
73 requiredDuringSchedulingIgnoredDuringExecution:
74   - labelSelector:
75       matchLabels: {{- (include "common.labels.matchLabels" .context) | nindent 8 }}
76         {{- if not (empty $component) }}
77         {{ printf "app.kubernetes.io/component: %s" $component }}
78         {{- end }}
79     namespaces:
80       - {{ .context.Release.Namespace }}
81     topologyKey: kubernetes.io/hostname
82 {{- end -}}
83
84 {{/*
85 Return a podAffinity/podAntiAffinity definition
86 {{ include "common.affinities.pods" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
87 */}}
88 {{- define "common.affinities.pods" -}}
89   {{- if eq .type "soft" }}
90     {{- include "common.affinities.pods.soft" . -}}
91   {{- else if eq .type "hard" }}
92     {{- include "common.affinities.pods.hard" . -}}
93   {{- end -}}
94 {{- end -}}