Helm-Toolkit: Document and fix the anti-affinity function
This PS document use of and fixes the anti-affinity function to properly support hard anti affinity. Change-Id: I2ec643d7720036b34fc249a2e230b3bed3aac41f Signed-off-by: Pete Birley <pete@port.direct>
This commit is contained in:
parent
7d3bda1307
commit
be7b01d798
@ -14,6 +14,51 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/}}
|
*/}}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
abstract: |
|
||||||
|
Renders kubernetes anti affinity rules, this function supports both hard
|
||||||
|
'requiredDuringSchedulingIgnoredDuringExecution' and soft
|
||||||
|
'preferredDuringSchedulingIgnoredDuringExecution' types.
|
||||||
|
values: |
|
||||||
|
pod:
|
||||||
|
affinity:
|
||||||
|
anti:
|
||||||
|
topologyKey:
|
||||||
|
default: kubernetes.io/hostname
|
||||||
|
type:
|
||||||
|
default: requiredDuringSchedulingIgnoredDuringExecution
|
||||||
|
usage: |
|
||||||
|
{{ tuple . "appliction_x" "component_y" | include "helm-toolkit.snippets.kubernetes_pod_anti_affinity" }}
|
||||||
|
return: |
|
||||||
|
podAntiAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
- key: release_group
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- RELEASE-NAME
|
||||||
|
- key: application
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- appliction_x
|
||||||
|
- key: component
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- component_y
|
||||||
|
topologyKey: kubernetes.io/hostname
|
||||||
|
*/}}
|
||||||
|
|
||||||
|
{{- define "helm-toolkit.snippets.kubernetes_pod_anti_affinity._match_expressions" -}}
|
||||||
|
{{- $envAll := index . "envAll" -}}
|
||||||
|
{{- $application := index . "application" -}}
|
||||||
|
{{- $component := index . "component" -}}
|
||||||
|
{{- $expressionRelease := dict "key" "release_group" "operator" "In" "values" ( list ( $envAll.Values.release_group | default $envAll.Release.Name ) ) -}}
|
||||||
|
{{- $expressionApplication := dict "key" "application" "operator" "In" "values" ( list $application ) -}}
|
||||||
|
{{- $expressionComponent := dict "key" "component" "operator" "In" "values" ( list $component ) -}}
|
||||||
|
{{- list $expressionRelease $expressionApplication $expressionComponent | toYaml }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "helm-toolkit.snippets.kubernetes_pod_anti_affinity" -}}
|
{{- define "helm-toolkit.snippets.kubernetes_pod_anti_affinity" -}}
|
||||||
{{- $envAll := index . 0 -}}
|
{{- $envAll := index . 0 -}}
|
||||||
{{- $application := index . 1 -}}
|
{{- $application := index . 1 -}}
|
||||||
@ -21,22 +66,20 @@ limitations under the License.
|
|||||||
{{- $antiAffinityType := index $envAll.Values.pod.affinity.anti.type $component | default $envAll.Values.pod.affinity.anti.type.default }}
|
{{- $antiAffinityType := index $envAll.Values.pod.affinity.anti.type $component | default $envAll.Values.pod.affinity.anti.type.default }}
|
||||||
{{- $antiAffinityKey := index $envAll.Values.pod.affinity.anti.topologyKey $component | default $envAll.Values.pod.affinity.anti.topologyKey.default }}
|
{{- $antiAffinityKey := index $envAll.Values.pod.affinity.anti.topologyKey $component | default $envAll.Values.pod.affinity.anti.topologyKey.default }}
|
||||||
podAntiAffinity:
|
podAntiAffinity:
|
||||||
|
{{- $matchExpressions := include "helm-toolkit.snippets.kubernetes_pod_anti_affinity._match_expressions" ( dict "envAll" $envAll "application" $application "component" $component ) -}}
|
||||||
|
{{- if eq $antiAffinityType "preferredDuringSchedulingIgnoredDuringExecution" }}
|
||||||
{{ $antiAffinityType }}:
|
{{ $antiAffinityType }}:
|
||||||
- podAffinityTerm:
|
- podAffinityTerm:
|
||||||
labelSelector:
|
labelSelector:
|
||||||
matchExpressions:
|
matchExpressions:
|
||||||
- key: release_group
|
{{ $matchExpressions | indent 10 }}
|
||||||
operator: In
|
|
||||||
values:
|
|
||||||
- {{ $envAll.Values.release_group | default $envAll.Release.Name }}
|
|
||||||
- key: application
|
|
||||||
operator: In
|
|
||||||
values:
|
|
||||||
- {{ $application }}
|
|
||||||
- key: component
|
|
||||||
operator: In
|
|
||||||
values:
|
|
||||||
- {{ $component }}
|
|
||||||
topologyKey: {{ $antiAffinityKey }}
|
topologyKey: {{ $antiAffinityKey }}
|
||||||
weight: 10
|
weight: 10
|
||||||
|
{{- else if eq $antiAffinityType "requiredDuringSchedulingIgnoredDuringExecution" }}
|
||||||
|
{{ $antiAffinityType }}:
|
||||||
|
- labelSelector:
|
||||||
|
matchExpressions:
|
||||||
|
{{ $matchExpressions | indent 8 }}
|
||||||
|
topologyKey: {{ $antiAffinityKey }}
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user