github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/kafka/charts/common/templates/_affinities.tpl (about) 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 - {{ . | quote }} 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 - {{ . | quote }} 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" "extraMatchLabels" .Values.extraMatchLabels "context" $) -}} 51 */}} 52 {{- define "common.affinities.pods.soft" -}} 53 {{- $component := default "" .component -}} 54 {{- $extraMatchLabels := default (dict) .extraMatchLabels -}} 55 preferredDuringSchedulingIgnoredDuringExecution: 56 - podAffinityTerm: 57 labelSelector: 58 matchLabels: {{- (include "common.labels.matchLabels" .context) | nindent 10 }} 59 {{- if not (empty $component) }} 60 {{ printf "app.kubernetes.io/component: %s" $component }} 61 {{- end }} 62 {{- range $key, $value := $extraMatchLabels }} 63 {{ $key }}: {{ $value | quote }} 64 {{- end }} 65 namespaces: 66 - {{ include "common.names.namespace" .context | quote }} 67 topologyKey: kubernetes.io/hostname 68 weight: 1 69 {{- end -}} 70 71 {{/* 72 Return a hard podAffinity/podAntiAffinity definition 73 {{ include "common.affinities.pods.hard" (dict "component" "FOO" "extraMatchLabels" .Values.extraMatchLabels "context" $) -}} 74 */}} 75 {{- define "common.affinities.pods.hard" -}} 76 {{- $component := default "" .component -}} 77 {{- $extraMatchLabels := default (dict) .extraMatchLabels -}} 78 requiredDuringSchedulingIgnoredDuringExecution: 79 - labelSelector: 80 matchLabels: {{- (include "common.labels.matchLabels" .context) | nindent 8 }} 81 {{- if not (empty $component) }} 82 {{ printf "app.kubernetes.io/component: %s" $component }} 83 {{- end }} 84 {{- range $key, $value := $extraMatchLabels }} 85 {{ $key }}: {{ $value | quote }} 86 {{- end }} 87 namespaces: 88 - {{ include "common.names.namespace" .context | quote }} 89 topologyKey: kubernetes.io/hostname 90 {{- end -}} 91 92 {{/* 93 Return a podAffinity/podAntiAffinity definition 94 {{ include "common.affinities.pods" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}} 95 */}} 96 {{- define "common.affinities.pods" -}} 97 {{- if eq .type "soft" }} 98 {{- include "common.affinities.pods.soft" . -}} 99 {{- else if eq .type "hard" }} 100 {{- include "common.affinities.pods.hard" . -}} 101 {{- end -}} 102 {{- end -}}