|
| 1 | +{{/* affinity - https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ */}} |
| 2 | + |
| 3 | +{{- define "nodeaffinity" }} |
| 4 | + nodeAffinity: |
| 5 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 6 | + {{- include "nodeAffinityRequiredDuringScheduling" . }} |
| 7 | + preferredDuringSchedulingIgnoredDuringExecution: |
| 8 | + {{- include "nodeAffinityPreferredDuringScheduling" . }} |
| 9 | +{{- end }} |
| 10 | + |
| 11 | +{{- define "nodeAffinityRequiredDuringScheduling" }} |
| 12 | + nodeSelectorTerms: |
| 13 | + - matchExpressions: |
| 14 | + - key: kubernetes.io/arch |
| 15 | + operator: In |
| 16 | + values: |
| 17 | + {{- range $key, $val := .global.arch }} |
| 18 | + {{- if gt ($val | int) 0 }} |
| 19 | + - {{ $key | quote }} |
| 20 | + {{- end }} |
| 21 | + {{- end }} |
| 22 | + {{- $nodeSelector := default .global.defaultNodeSelector .nodeSelector -}} |
| 23 | + {{- range $key, $val := $nodeSelector }} |
| 24 | + - key: {{ $key }} |
| 25 | + operator: In |
| 26 | + values: |
| 27 | + - {{ $val | quote }} |
| 28 | + {{- end }} |
| 29 | +{{- end }} |
| 30 | + |
| 31 | +{{- define "nodeAffinityPreferredDuringScheduling" }} |
| 32 | + {{- range $key, $val := .global.arch }} |
| 33 | + {{- if gt ($val | int) 0 }} |
| 34 | + - weight: {{ $val | int }} |
| 35 | + preference: |
| 36 | + matchExpressions: |
| 37 | + - key: kubernetes.io/arch |
| 38 | + operator: In |
| 39 | + values: |
| 40 | + - {{ $key | quote }} |
| 41 | + {{- end }} |
| 42 | + {{- end }} |
| 43 | +{{- end }} |
| 44 | + |
| 45 | +{{- define "podAntiAffinity" }} |
| 46 | +{{- if or .podAntiAffinityLabelSelector .podAntiAffinityTermLabelSelector}} |
| 47 | + podAntiAffinity: |
| 48 | + {{- if .podAntiAffinityLabelSelector }} |
| 49 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 50 | + {{- include "podAntiAffinityRequiredDuringScheduling" . }} |
| 51 | + {{- end }} |
| 52 | + {{- if .podAntiAffinityTermLabelSelector }} |
| 53 | + preferredDuringSchedulingIgnoredDuringExecution: |
| 54 | + {{- include "podAntiAffinityPreferredDuringScheduling" . }} |
| 55 | + {{- end }} |
| 56 | +{{- end }} |
| 57 | +{{- end }} |
| 58 | + |
| 59 | +{{- define "podAntiAffinityRequiredDuringScheduling" }} |
| 60 | + {{- range $index, $item := .podAntiAffinityLabelSelector }} |
| 61 | + - labelSelector: |
| 62 | + matchExpressions: |
| 63 | + - key: {{ $item.key }} |
| 64 | + operator: {{ $item.operator }} |
| 65 | + {{- if $item.values }} |
| 66 | + values: |
| 67 | + {{- $vals := split "," $item.values }} |
| 68 | + {{- range $i, $v := $vals }} |
| 69 | + - {{ $v | quote }} |
| 70 | + {{- end }} |
| 71 | + {{- end }} |
| 72 | + topologyKey: {{ $item.topologyKey }} |
| 73 | + {{- end }} |
| 74 | +{{- end }} |
| 75 | + |
| 76 | +{{- define "podAntiAffinityPreferredDuringScheduling" }} |
| 77 | + {{- range $index, $item := .podAntiAffinityTermLabelSelector }} |
| 78 | + - podAffinityTerm: |
| 79 | + labelSelector: |
| 80 | + matchExpressions: |
| 81 | + - key: {{ $item.key }} |
| 82 | + operator: {{ $item.operator }} |
| 83 | + {{- if $item.values }} |
| 84 | + values: |
| 85 | + {{- $vals := split "," $item.values }} |
| 86 | + {{- range $i, $v := $vals }} |
| 87 | + - {{ $v | quote }} |
| 88 | + {{- end }} |
| 89 | + {{- end }} |
| 90 | + topologyKey: {{ $item.topologyKey }} |
| 91 | + weight: 100 |
| 92 | + {{- end }} |
| 93 | +{{- end }} |
0 commit comments