Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/helm_lib/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
type: library
name: deckhouse_lib_helm
version: 1.68.0
version: 1.68.1
description: "Helm utils template definitions for Deckhouse modules."
19 changes: 4 additions & 15 deletions charts/helm_lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
| [_helm_lib_additional_tolerations_storage_problems](#_helm_lib_additional_tolerations_storage_problems) |
| [_helm_lib_additional_tolerations_no_csi](#_helm_lib_additional_tolerations_no_csi) |
| [_helm_lib_additional_tolerations_cloud_provider_uninitialized](#_helm_lib_additional_tolerations_cloud_provider_uninitialized) |
| [helm_lib_affinity_arch_require](#helm_lib_affinity_arch_require) |
| **Pod Disruption Budget** |
| [helm_lib_pdb_daemonset](#helm_lib_pdb_daemonset) |
| **Priority Class** |
Expand All @@ -140,7 +139,7 @@
| [helm_lib_container_kube_rbac_proxy_resources](#helm_lib_container_kube_rbac_proxy_resources) |
| **Spec For High Availability** |
| [helm_lib_pod_anti_affinity_for_ha](#helm_lib_pod_anti_affinity_for_ha) |
| [helm_lib_affinity_ha_with_arch_require](#helm_lib_affinity_ha_with_arch_require) |
| [helm_lib_pod_affinity](#helm_lib_pod_affinity) |
| [helm_lib_deployment_on_master_strategy_and_replicas_for_ha](#helm_lib_deployment_on_master_strategy_and_replicas_for_ha) |
| [helm_lib_deployment_on_master_custom_strategy_and_replicas_for_ha](#helm_lib_deployment_on_master_custom_strategy_and_replicas_for_ha) |
| [helm_lib_deployment_strategy_and_replicas_for_ha](#helm_lib_deployment_strategy_and_replicas_for_ha) |
Expand Down Expand Up @@ -1427,16 +1426,6 @@ list:
`{{ include "helm_lib_tolerations" (tuple . "any-node" "with-cloud-provider-uninitialized") }} `



### helm_lib_affinity_arch_require

Returns nodeAffinity that schedules pods only on specified architectures.

#### Usage

`{{- include "helm_lib_affinity_arch_require" (list . (list "amd64" "arm64")) `


## Pod Disruption Budget

### helm_lib_pdb_daemonset
Expand Down Expand Up @@ -1573,13 +1562,13 @@ list:
- Match labels for podAntiAffinity label selector


### helm_lib_affinity_ha_with_arch_require
### helm_lib_pod_affinity

Returns affinity spec for HA components that combines: podAntiAffinity by provided labels (same as helm_lib_pod_anti_affinity_for_ha) and nodeAffinity that schedules pods only on specified architectures. If the list of architectures is not provided, defaults to ["amd64"].
Returns affinity spec that combines: podAntiAffinity by provided labels when HA is enabled and optional nodeAffinity that schedules pods only on specified architectures. If the list of architectures is not provided or empty, node affinity is not rendered.

#### Usage

`{{- include "helm_lib_affinity_ha_with_arch_require" (list . (dict "app" "test") (list "amd64")) }} `
`{{- include "helm_lib_pod_affinity" (list . (dict "app" "test") (list "amd64")) }} `

#### Arguments

Expand Down
18 changes: 0 additions & 18 deletions charts/helm_lib/templates/_node_affinity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,3 @@ tolerations:
operator: Exists
{{- end }}
{{- end }}

{{- /* Returns nodeAffinity that schedules pods only on specified architectures.*/ -}}
{{- /* Usage: {{- include "helm_lib_affinity_arch_require" (list . (list "amd64" "arm64")) */ -}}
{{- define "helm_lib_affinity_arch_require" -}}
{{- $context := index . 0 -}}
{{- $allowedArchs := index . 1 -}}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/arch
operator: In
values:
{{- range $allowedArchs }}
- {{ . | quote }}
{{- end }}
{{- end -}}
27 changes: 18 additions & 9 deletions charts/helm_lib/templates/_spec_for_high_availability.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ affinity:
{{- end }}
{{- end }}

{{- /* Usage: {{- include "helm_lib_affinity_ha_with_arch_require" (list . (dict "app" "test") (list "amd64")) }} */}}
{{- /* Returns affinity spec for HA components that combines: podAntiAffinity by provided labels (same as helm_lib_pod_anti_affinity_for_ha) and nodeAffinity that schedules pods only on specified architectures. If the list of architectures is not provided, defaults to ["amd64"]. */ -}}
{{- define "helm_lib_affinity_ha_with_arch_require" }}
{{- /* Usage: {{- include "helm_lib_pod_affinity" (list . (dict "app" "test") (list "amd64")) }} */}}
{{- /* Returns affinity spec that combines: podAntiAffinity by provided labels when HA is enabled and optional nodeAffinity that schedules pods only on specified architectures. If the list of architectures is not provided or empty, node affinity is not rendered. */ -}}
{{- define "helm_lib_pod_affinity" }}
{{- $context := index . 0 -}} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $labels := index . 1 }} {{- /* Match labels for podAntiAffinity label selector */ -}}
{{- $allowedArchs := list "amd64" -}}
{{- $labels := dict -}} {{- /* Match labels for podAntiAffinity label selector */ -}}
{{- if ge (len .) 2 }}
{{- $labels = index . 1 }}
{{- end }}
{{- $allowedArchs := list -}} {{- /* List of supported architectures */ -}}
{{- if ge (len .) 3 }}
{{- $allowedArchs = index . 2 }}
{{- end }}
{{- if (include "helm_lib_ha_enabled" $context) }}
{{- $haEnabled := (include "helm_lib_ha_enabled" $context) -}}
{{- $hasArch := gt (len $allowedArchs) 0 -}}
{{- if or $haEnabled $hasArch }}
affinity:
{{- if $haEnabled }}
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
Expand All @@ -35,18 +41,21 @@ affinity:
{{ $key }}: {{ $value | quote }}
{{- end }}
topologyKey: kubernetes.io/hostname
{{- end }}
{{- if $hasArch }}
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/arch
operator: In
values:
- key: kubernetes.io/arch
operator: In
values:
{{- range $allowedArchs }}
- {{ . | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{- /* Usage: {{ include "helm_lib_deployment_on_master_strategy_and_replicas_for_ha" }} */ -}}
{{- /* returns deployment strategy and replicas for ha components running on master nodes */ -}}
Expand Down
4 changes: 0 additions & 4 deletions tests/templates/helm_lib_affinity_arch_require.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions tests/templates/helm_lib_affinity_ha_with_arch_require.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions tests/templates/helm_lib_pod_affinity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- $noArch := include "helm_lib_pod_affinity" (list . (dict "app" "test")) }}
resultNoArch: {{ $noArch | toString | quote }}
{{- $withArch := include "helm_lib_pod_affinity" (list . (dict "app" "test") (list "amd64" "ppc64le")) }}
resultWithArch: {{ $withArch | toString | quote }}
50 changes: 0 additions & 50 deletions tests/tests/helm_lib_affinity_arch_require_test.yaml

This file was deleted.

64 changes: 0 additions & 64 deletions tests/tests/helm_lib_affinity_ha_with_arch_require_test.yaml

This file was deleted.

74 changes: 74 additions & 0 deletions tests/tests/helm_lib_pod_affinity_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
suite: helm_lib_pod_affinity definition
templates:
- helm_lib_pod_affinity.yaml
tests:
- it: renders only pod anti-affinity when HA is enabled and architectures are not provided
set:
Chart:
Name: "testModule"
global:
highAvailability: true
asserts:
- matchRegex:
path: resultNoArch
pattern: "podAntiAffinity"
- matchRegex:
path: resultNoArch
pattern: "kubernetes.io/hostname"
- notMatchRegex:
path: resultNoArch
pattern: "nodeAffinity"
- it: renders pod anti-affinity and node affinity when HA is enabled and architectures are provided
set:
Chart:
Name: "testModule"
global:
highAvailability: true
asserts:
- matchRegex:
path: resultWithArch
pattern: "podAntiAffinity"
- matchRegex:
path: resultWithArch
pattern: "nodeAffinity"
- matchRegex:
path: resultWithArch
pattern: "operator:\\s*In"
- notMatchRegex:
path: resultWithArch
pattern: "operator:\\s*NotIn"
- matchRegex:
path: resultWithArch
pattern: "-\\s*\"amd64\""
- matchRegex:
path: resultWithArch
pattern: "-\\s*\"ppc64le\""
- it: renders only node affinity when HA is disabled but architectures are provided
set:
Chart:
Name: "testModule"
global:
highAvailability: false
asserts:
- matchRegex:
path: resultWithArch
pattern: "nodeAffinity"
- notMatchRegex:
path: resultWithArch
pattern: "podAntiAffinity"
- matchRegex:
path: resultWithArch
pattern: "-\\s*\"amd64\""
- matchRegex:
path: resultWithArch
pattern: "-\\s*\"ppc64le\""
- it: renders empty string when HA is disabled and architectures are not provided
set:
Chart:
Name: "testModule"
global:
highAvailability: false
asserts:
- equal:
path: resultNoArch
value: ""