From f6631dbdb434d7860eb1cf707ff6bfb3a33ea6b7 Mon Sep 17 00:00:00 2001 From: Karen Tu <305012119+karen-tu-2@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:40:48 +0000 Subject: [PATCH] Support nodeTaintsPolicy in topology spread constraints Signed-off-by: Karen Tu <305012119+karen-tu-2@users.noreply.github.com> --- .ci/test_redis_ha_topology.py | 76 +++++++++++++++++++ .github/workflows/test.yaml | 5 ++ charts/redis-ha/Chart.yaml | 2 +- charts/redis-ha/README.md | 1 + .../templates/redis-ha-statefulset.yaml | 3 + .../templates/redis-haproxy-deployment.yaml | 3 + charts/redis-ha/values.yaml | 2 + 7 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 .ci/test_redis_ha_topology.py diff --git a/.ci/test_redis_ha_topology.py b/.ci/test_redis_ha_topology.py new file mode 100644 index 00000000..8dfefcfe --- /dev/null +++ b/.ci/test_redis_ha_topology.py @@ -0,0 +1,76 @@ +import copy +from pathlib import Path +import subprocess +import unittest + +import yaml + + +CHART = Path(__file__).resolve().parents[1] / "charts" / "redis-ha" + + +class TopologySpreadConstraintsTest(unittest.TestCase): + def render(self, enabled=True, **constraints): + values = { + "haproxy": {"enabled": True}, + "topologySpreadConstraints": constraints, + } + if enabled is not None: + values["topologySpreadConstraints"]["enabled"] = enabled + result = subprocess.run( + [ + "helm", "template", "test", str(CHART), "--values", "-", + "--show-only", "templates/redis-ha-statefulset.yaml", + "--show-only", "templates/redis-haproxy-deployment.yaml", + ], + input=yaml.safe_dump(values), + text=True, + capture_output=True, + check=True, + ) + workloads = list(yaml.safe_load_all(result.stdout)) + self.assertEqual([w["kind"] for w in workloads], ["StatefulSet", "Deployment"]) + return workloads + + def test_constraints_disabled_by_default(self): + for workload in self.render(enabled=None): + with self.subTest(kind=workload["kind"]): + self.assertNotIn("topologySpreadConstraints", workload["spec"]["template"]["spec"]) + + def test_policy_omitted_by_default(self): + for workload in self.render(): + with self.subTest(kind=workload["kind"]): + constraint = workload["spec"]["template"]["spec"]["topologySpreadConstraints"][0] + self.assertNotIn("nodeTaintsPolicy", constraint) + self.assertEqual(constraint["maxSkew"], 1) + self.assertEqual(constraint["topologyKey"], "topology.kubernetes.io/zone") + self.assertEqual(constraint["whenUnsatisfiable"], "ScheduleAnyway") + + def test_empty_or_null_policy_preserves_defaults(self): + baseline = self.render() + for policy in ("", None): + with self.subTest(policy=policy): + self.assertEqual(self.render(nodeTaintsPolicy=policy), baseline) + + def test_explicit_policy_only_adds_requested_field(self): + for enforcement in ("ScheduleAnyway", "DoNotSchedule"): + baseline = self.render(whenUnsatisfiable=enforcement) + for policy in ("Honor", "Ignore"): + expected = copy.deepcopy(baseline) + for workload in expected: + constraint = workload["spec"]["template"]["spec"]["topologySpreadConstraints"][0] + constraint["nodeTaintsPolicy"] = policy + with self.subTest(enforcement=enforcement, policy=policy): + self.assertEqual( + self.render(whenUnsatisfiable=enforcement, nodeTaintsPolicy=policy), + expected, + ) + + def test_disabled_constraints_remain_absent(self): + for workload in self.render(enabled=False, nodeTaintsPolicy="Honor"): + with self.subTest(kind=workload["kind"]): + self.assertNotIn("topologySpreadConstraints", workload["spec"]["template"]["spec"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b500ba69..b7ce6bff 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,6 +31,11 @@ jobs: with: python-version: '3.13' + - name: Test redis-ha topology spread rendering + run: | + python -m pip install PyYAML + python -m unittest discover --start-directory .ci --pattern test_redis_ha_topology.py -v + - name: Set up chart-testing uses: helm/chart-testing-action@v2.0.1 diff --git a/charts/redis-ha/Chart.yaml b/charts/redis-ha/Chart.yaml index d4e21a86..5c4e920a 100644 --- a/charts/redis-ha/Chart.yaml +++ b/charts/redis-ha/Chart.yaml @@ -5,7 +5,7 @@ keywords: - redis - keyvalue - database -version: 4.39.0 +version: 4.40.0 appVersion: 8.8.0 description: This Helm chart provides a highly available Redis implementation with a master/slave configuration and uses Sentinel sidecars for failover management icon: https://img.icons8.com/external-tal-revivo-shadow-tal-revivo/24/external-redis-an-in-memory-data-structure-project-implementing-a-distributed-logo-shadow-tal-revivo.png diff --git a/charts/redis-ha/README.md b/charts/redis-ha/README.md index 56eaf46b..75fe300c 100644 --- a/charts/redis-ha/README.md +++ b/charts/redis-ha/README.md @@ -192,6 +192,7 @@ The following table lists the configurable parameters of the Redis chart and the | `tolerations` | | list | `[]` | | `topologySpreadConstraints.enabled` | Enable topology spread constraints | bool | `false` | | `topologySpreadConstraints.maxSkew` | Max skew of pods tolerated | string | `""` | +| `topologySpreadConstraints.nodeTaintsPolicy` | Node taint inclusion policy (Honor or Ignore); empty preserves the Kubernetes default | string | `""` | | `topologySpreadConstraints.topologyKey` | Topology key for spread constraints | string | `""` | | `topologySpreadConstraints.whenUnsatisfiable` | Enforcement policy, hard or soft | string | `""` | diff --git a/charts/redis-ha/templates/redis-ha-statefulset.yaml b/charts/redis-ha/templates/redis-ha-statefulset.yaml index bab5ea73..d99a1702 100644 --- a/charts/redis-ha/templates/redis-ha-statefulset.yaml +++ b/charts/redis-ha/templates/redis-ha-statefulset.yaml @@ -100,6 +100,9 @@ spec: - maxSkew: {{ .Values.topologySpreadConstraints.maxSkew | default 1 }} topologyKey: {{ .Values.topologySpreadConstraints.topologyKey | default "topology.kubernetes.io/zone" }} whenUnsatisfiable: {{ .Values.topologySpreadConstraints.whenUnsatisfiable | default "ScheduleAnyway" }} + {{- with .Values.topologySpreadConstraints.nodeTaintsPolicy }} + nodeTaintsPolicy: {{ . | quote }} + {{- end }} labelSelector: matchLabels: app: {{ template "redis-ha.name" . }} diff --git a/charts/redis-ha/templates/redis-haproxy-deployment.yaml b/charts/redis-ha/templates/redis-haproxy-deployment.yaml index 64a8bc03..405231fc 100644 --- a/charts/redis-ha/templates/redis-haproxy-deployment.yaml +++ b/charts/redis-ha/templates/redis-haproxy-deployment.yaml @@ -99,6 +99,9 @@ spec: - maxSkew: {{ .Values.topologySpreadConstraints.maxSkew | default 1 }} topologyKey: {{ .Values.topologySpreadConstraints.topologyKey | default "topology.kubernetes.io/zone" }} whenUnsatisfiable: {{ .Values.topologySpreadConstraints.whenUnsatisfiable | default "ScheduleAnyway" }} + {{- with .Values.topologySpreadConstraints.nodeTaintsPolicy }} + nodeTaintsPolicy: {{ . | quote }} + {{- end }} labelSelector: matchLabels: app: {{ template "redis-ha.name" . }}-haproxy diff --git a/charts/redis-ha/values.yaml b/charts/redis-ha/values.yaml index 95ad969f..de3abbd1 100644 --- a/charts/redis-ha/values.yaml +++ b/charts/redis-ha/values.yaml @@ -738,6 +738,8 @@ topologySpreadConstraints: enabled: false # -- Max skew of pods tolerated maxSkew: "" + # -- Node taint inclusion policy (Honor or Ignore); empty preserves the Kubernetes default + nodeTaintsPolicy: "" # -- Topology key for spread constraints topologyKey: "" # -- Enforcement policy, hard or soft