From 32455168e2355352cfecfb931ee67d3c331cd5d7 Mon Sep 17 00:00:00 2001 From: Mattia Eleuteri Date: Sun, 8 Nov 2026 19:36:44 +0100 Subject: [PATCH] fix(redis): keep three Sentinels for a zero or negative replica count The operator runs three Redis pods when the count is zero or negative, but the chart treated any count up to 1 as the single-pod case. Such a cluster got one Sentinel and no Sentinel PDB, while three Redis pods ran under it. Assisted-by: LLM Signed-off-by: Mattia Eleuteri (cherry picked from commit a7f84242d1b82398f5dd478452bc8e0ae8f891cd) Signed-off-by: Myasnikov Daniil --- packages/apps/redis/templates/_resources.tpl | 2 +- .../redis/tests/sentinel_pdb_hook_test.yaml | 20 +++++++++++++ .../redis/tests/sentinel_replicas_test.yaml | 28 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/apps/redis/templates/_resources.tpl b/packages/apps/redis/templates/_resources.tpl index 98119dbb2..45399c958 100644 --- a/packages/apps/redis/templates/_resources.tpl +++ b/packages/apps/redis/templates/_resources.tpl @@ -49,5 +49,5 @@ These presets are for basic testing and not meant to be used in production {{- end -}} {{- define "redis.sentinelReplicas" -}} -{{- ternary 1 3 (le (int .Values.replicas) 1) -}} +{{- ternary 1 3 (eq (int .Values.replicas) 1) -}} {{- end -}} diff --git a/packages/apps/redis/tests/sentinel_pdb_hook_test.yaml b/packages/apps/redis/tests/sentinel_pdb_hook_test.yaml index bc6aea706..5676f8d31 100644 --- a/packages/apps/redis/tests/sentinel_pdb_hook_test.yaml +++ b/packages/apps/redis/tests/sentinel_pdb_hook_test.yaml @@ -77,6 +77,26 @@ tests: - hasDocuments: count: 0 + # The operator runs three Redis pods for a zero or negative count, so their + # Sentinel PDB stays. + - it: renders nothing for a zero replica count + release: + upgrade: true + set: + replicas: 0 + asserts: + - hasDocuments: + count: 0 + + - it: renders nothing for a negative replica count + release: + upgrade: true + set: + replicas: -1 + asserts: + - hasDocuments: + count: 0 + # The pods' job-name label takes 63 characters at most; a 53-character # release name plus -sentinel-pdb would pass it and Kubernetes would refuse # the Job, leaving the stale PDB in place. diff --git a/packages/apps/redis/tests/sentinel_replicas_test.yaml b/packages/apps/redis/tests/sentinel_replicas_test.yaml index 012f58247..fc60d52b0 100644 --- a/packages/apps/redis/tests/sentinel_replicas_test.yaml +++ b/packages/apps/redis/tests/sentinel_replicas_test.yaml @@ -54,6 +54,34 @@ tests: - notExists: path: spec.sentinel.disablePodDisruptionBudget + # The operator turns a zero or negative count into three Redis pods, so these + # keep three Sentinels and their PDB rather than the single-pod case. + - it: "keeps three Sentinels and their PDB for a zero replica count" + set: + replicas: 0 + documentSelector: + path: kind + value: RedisFailover + asserts: + - equal: + path: spec.sentinel.replicas + value: 3 + - notExists: + path: spec.sentinel.disablePodDisruptionBudget + + - it: "keeps three Sentinels and their PDB for a negative replica count" + set: + replicas: -1 + documentSelector: + path: kind + value: RedisFailover + asserts: + - equal: + path: spec.sentinel.replicas + value: 3 + - notExists: + path: spec.sentinel.disablePodDisruptionBudget + - it: "keeps three Sentinels for three Redis pods" set: replicas: 3