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