|
| 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 topologyKey definition |
| 50 | +{{ include "common.affinities.topologyKey" (dict "topologyKey" "BAR") -}} |
| 51 | +*/}} |
| 52 | +{{- define "common.affinities.topologyKey" -}} |
| 53 | +{{ .topologyKey | default "kubernetes.io/hostname" -}} |
| 54 | +{{- end -}} |
| 55 | + |
| 56 | +{{/* |
| 57 | +Return a soft podAffinity/podAntiAffinity definition |
| 58 | +{{ include "common.affinities.pods.soft" (dict "component" "FOO" "customLabels" .Values.podLabels "extraMatchLabels" .Values.extraMatchLabels "topologyKey" "BAR" "extraPodAffinityTerms" .Values.extraPodAffinityTerms "extraNamespaces" (list "namespace1" "namespace2") "context" $) -}} |
| 59 | +*/}} |
| 60 | +{{- define "common.affinities.pods.soft" -}} |
| 61 | +{{- $component := default "" .component -}} |
| 62 | +{{- $customLabels := default (dict) .customLabels -}} |
| 63 | +{{- $extraMatchLabels := default (dict) .extraMatchLabels -}} |
| 64 | +{{- $extraPodAffinityTerms := default (list) .extraPodAffinityTerms -}} |
| 65 | +{{- $extraNamespaces := default (list) .extraNamespaces -}} |
| 66 | +preferredDuringSchedulingIgnoredDuringExecution: |
| 67 | + - podAffinityTerm: |
| 68 | + labelSelector: |
| 69 | + matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" .context )) | nindent 10 }} |
| 70 | + {{- if not (empty $component) }} |
| 71 | + {{ printf "app.kubernetes.io/component: %s" $component }} |
| 72 | + {{- end }} |
| 73 | + {{- range $key, $value := $extraMatchLabels }} |
| 74 | + {{ $key }}: {{ $value | quote }} |
| 75 | + {{- end }} |
| 76 | + {{- if $extraNamespaces }} |
| 77 | + namespaces: |
| 78 | + - {{ .context.Release.Namespace }} |
| 79 | + {{- with $extraNamespaces }} |
| 80 | + {{- include "common.tplvalues.render" (dict "value" . "context" $) | nindent 8 }} |
| 81 | + {{- end }} |
| 82 | + {{- end }} |
| 83 | + topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }} |
| 84 | + weight: 1 |
| 85 | + {{- range $extraPodAffinityTerms }} |
| 86 | + - podAffinityTerm: |
| 87 | + labelSelector: |
| 88 | + matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" $.context )) | nindent 10 }} |
| 89 | + {{- if not (empty $component) }} |
| 90 | + {{ printf "app.kubernetes.io/component: %s" $component }} |
| 91 | + {{- end }} |
| 92 | + {{- range $key, $value := .extraMatchLabels }} |
| 93 | + {{ $key }}: {{ $value | quote }} |
| 94 | + {{- end }} |
| 95 | + {{- if .namespaces }} |
| 96 | + namespaces: |
| 97 | + - {{ $.context.Release.Namespace }} |
| 98 | + {{- with .namespaces }} |
| 99 | + {{- include "common.tplvalues.render" (dict "value" . "context" $) | nindent 8 }} |
| 100 | + {{- end }} |
| 101 | + {{- end }} |
| 102 | + topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }} |
| 103 | + weight: {{ .weight | default 1 -}} |
| 104 | + {{- end -}} |
| 105 | +{{- end -}} |
| 106 | + |
| 107 | +{{/* |
| 108 | +Return a hard podAffinity/podAntiAffinity definition |
| 109 | +{{ include "common.affinities.pods.hard" (dict "component" "FOO" "customLabels" .Values.podLabels "extraMatchLabels" .Values.extraMatchLabels "topologyKey" "BAR" "extraPodAffinityTerms" .Values.extraPodAffinityTerms "extraNamespaces" (list "namespace1" "namespace2") "context" $) -}} |
| 110 | +*/}} |
| 111 | +{{- define "common.affinities.pods.hard" -}} |
| 112 | +{{- $component := default "" .component -}} |
| 113 | +{{- $customLabels := default (dict) .customLabels -}} |
| 114 | +{{- $extraMatchLabels := default (dict) .extraMatchLabels -}} |
| 115 | +{{- $extraPodAffinityTerms := default (list) .extraPodAffinityTerms -}} |
| 116 | +{{- $extraNamespaces := default (list) .extraNamespaces -}} |
| 117 | +requiredDuringSchedulingIgnoredDuringExecution: |
| 118 | + - labelSelector: |
| 119 | + matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" .context )) | nindent 8 }} |
| 120 | + {{- if not (empty $component) }} |
| 121 | + {{ printf "app.kubernetes.io/component: %s" $component }} |
| 122 | + {{- end }} |
| 123 | + {{- range $key, $value := $extraMatchLabels }} |
| 124 | + {{ $key }}: {{ $value | quote }} |
| 125 | + {{- end }} |
| 126 | + {{- if $extraNamespaces }} |
| 127 | + namespaces: |
| 128 | + - {{ .context.Release.Namespace }} |
| 129 | + {{- with $extraNamespaces }} |
| 130 | + {{- include "common.tplvalues.render" (dict "value" . "context" $) | nindent 6 }} |
| 131 | + {{- end }} |
| 132 | + {{- end }} |
| 133 | + topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }} |
| 134 | + {{- range $extraPodAffinityTerms }} |
| 135 | + - labelSelector: |
| 136 | + matchLabels: {{- (include "common.labels.matchLabels" ( dict "customLabels" $customLabels "context" $.context )) | nindent 8 }} |
| 137 | + {{- if not (empty $component) }} |
| 138 | + {{ printf "app.kubernetes.io/component: %s" $component }} |
| 139 | + {{- end }} |
| 140 | + {{- range $key, $value := .extraMatchLabels }} |
| 141 | + {{ $key }}: {{ $value | quote }} |
| 142 | + {{- end }} |
| 143 | + {{- if .namespaces }} |
| 144 | + namespaces: |
| 145 | + - {{ $.context.Release.Namespace }} |
| 146 | + {{- with .namespaces }} |
| 147 | + {{- include "common.tplvalues.render" (dict "value" . "context" $) | nindent 6 }} |
| 148 | + {{- end }} |
| 149 | + {{- end }} |
| 150 | + topologyKey: {{ include "common.affinities.topologyKey" (dict "topologyKey" .topologyKey) }} |
| 151 | + {{- end -}} |
| 152 | +{{- end -}} |
| 153 | + |
| 154 | +{{/* |
| 155 | +Return a podAffinity/podAntiAffinity definition |
| 156 | +{{ include "common.affinities.pods" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}} |
| 157 | +*/}} |
| 158 | +{{- define "common.affinities.pods" -}} |
| 159 | + {{- if eq .type "soft" }} |
| 160 | + {{- include "common.affinities.pods.soft" . -}} |
| 161 | + {{- else if eq .type "hard" }} |
| 162 | + {{- include "common.affinities.pods.hard" . -}} |
| 163 | + {{- end -}} |
| 164 | +{{- end -}} |
0 commit comments