From 751ea034fa2dd96374600eb9511ae56c58ca9641 Mon Sep 17 00:00:00 2001 From: Matthias Winzeler Date: Wed, 14 Oct 2026 08:15:16 +0200 Subject: [PATCH] helm: add topologySpreadConstraints (fix #1208) --- script/helm/garage/complex-values.yaml | 9 +++++++ script/helm/garage/templates/workload.yaml | 4 +++ script/helm/garage/tests/complex_test.yaml | 4 +++ script/helm/garage/tests/workload_test.yaml | 27 +++++++++++++++++++++ script/helm/garage/values.yaml | 4 +++ 5 files changed, 48 insertions(+) diff --git a/script/helm/garage/complex-values.yaml b/script/helm/garage/complex-values.yaml index e749cd1e..fae8bc90 100644 --- a/script/helm/garage/complex-values.yaml +++ b/script/helm/garage/complex-values.yaml @@ -278,6 +278,15 @@ affinity: app.kubernetes.io/name: garage topologyKey: kubernetes.io/hostname +# -- Example: place each replica in a separate zone +topologySpreadConstraints: + - maxSkew: 1 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: DoNotSchedule + labelSelector: + matchLabels: + app.kubernetes.io/name: garage + # -- Optional priority class name to assign to the pods. # See https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/ # This is expected to reference a PriorityClass you define yourself. diff --git a/script/helm/garage/templates/workload.yaml b/script/helm/garage/templates/workload.yaml index e032a6b9..26e8baee 100644 --- a/script/helm/garage/templates/workload.yaml +++ b/script/helm/garage/templates/workload.yaml @@ -136,6 +136,10 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + {{- with .Values.topologySpreadConstraints }} + topologySpreadConstraints: + {{- toYaml . | nindent 8 }} + {{- end }} {{- if and .Values.persistence.enabled (eq .Values.deployment.kind "StatefulSet") }} volumeClaimTemplates: - metadata: diff --git a/script/helm/garage/tests/complex_test.yaml b/script/helm/garage/tests/complex_test.yaml index c51ef061..418bc5f9 100644 --- a/script/helm/garage/tests/complex_test.yaml +++ b/script/helm/garage/tests/complex_test.yaml @@ -47,6 +47,10 @@ tests: equal: path: spec.volumeClaimTemplates[0].spec.storageClassName value: fast-ssd + - template: templates/workload.yaml + equal: + path: spec.template.spec.topologySpreadConstraints[0].topologyKey + value: topology.kubernetes.io/zone - template: templates/workload.yaml contains: path: spec.template.spec.imagePullSecrets diff --git a/script/helm/garage/tests/workload_test.yaml b/script/helm/garage/tests/workload_test.yaml index 7620a879..9e652988 100644 --- a/script/helm/garage/tests/workload_test.yaml +++ b/script/helm/garage/tests/workload_test.yaml @@ -212,3 +212,30 @@ tests: - equal: path: spec.template.spec.serviceAccountName value: default + + - it: omits topologySpreadConstraints by default + template: templates/workload.yaml + asserts: + - isNull: + path: spec.template.spec.topologySpreadConstraints + + - it: sets topologySpreadConstraints when configured + template: templates/workload.yaml + set: + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: DoNotSchedule + labelSelector: + matchLabels: + app.kubernetes.io/name: garage + asserts: + - equal: + path: spec.template.spec.topologySpreadConstraints + value: + - maxSkew: 1 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: DoNotSchedule + labelSelector: + matchLabels: + app.kubernetes.io/name: garage diff --git a/script/helm/garage/values.yaml b/script/helm/garage/values.yaml index e1909e1b..1489c52a 100644 --- a/script/helm/garage/values.yaml +++ b/script/helm/garage/values.yaml @@ -252,6 +252,10 @@ tolerations: [] affinity: {} +# -- Topology spread constraints for the pods, e.g. to place each node in a separate zone. +# See https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/ +topologySpreadConstraints: [] + # -- Optional priority class name to assign to the pods. # See [the k8s pod-priority doc](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/) priorityClassName: ""