Skip to content
Open
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
76 changes: 76 additions & 0 deletions .ci/test_redis_ha_topology.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion charts/redis-ha/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions charts/redis-ha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `""` |

Expand Down
3 changes: 3 additions & 0 deletions charts/redis-ha/templates/redis-ha-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" . }}
Expand Down
3 changes: 3 additions & 0 deletions charts/redis-ha/templates/redis-haproxy-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions charts/redis-ha/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down