Skip to content

Commit a7f8424

Browse files
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 <[email protected]>
1 parent 2541aec commit a7f8424

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

‎packages/apps/redis/templates/_resources.tpl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ These presets are for basic testing and not meant to be used in production
4949
{{- end -}}
5050

5151
{{- define "redis.sentinelReplicas" -}}
52-
{{- ternary 1 3 (le (int .Values.replicas) 1) -}}
52+
{{- ternary 1 3 (eq (int .Values.replicas) 1) -}}
5353
{{- end -}}

‎packages/apps/redis/tests/sentinel_pdb_hook_test.yaml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ tests:
7777
- hasDocuments:
7878
count: 0
7979

80+
# The operator runs three Redis pods for a zero or negative count, so their
81+
# Sentinel PDB stays.
82+
- it: renders nothing for a zero replica count
83+
release:
84+
upgrade: true
85+
set:
86+
replicas: 0
87+
asserts:
88+
- hasDocuments:
89+
count: 0
90+
91+
- it: renders nothing for a negative replica count
92+
release:
93+
upgrade: true
94+
set:
95+
replicas: -1
96+
asserts:
97+
- hasDocuments:
98+
count: 0
99+
80100
# The pods' job-name label takes 63 characters at most; a 53-character
81101
# release name plus -sentinel-pdb would pass it and Kubernetes would refuse
82102
# the Job, leaving the stale PDB in place.

‎packages/apps/redis/tests/sentinel_replicas_test.yaml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ tests:
5454
- notExists:
5555
path: spec.sentinel.disablePodDisruptionBudget
5656

57+
# The operator turns a zero or negative count into three Redis pods, so these
58+
# keep three Sentinels and their PDB rather than the single-pod case.
59+
- it: "keeps three Sentinels and their PDB for a zero replica count"
60+
set:
61+
replicas: 0
62+
documentSelector:
63+
path: kind
64+
value: RedisFailover
65+
asserts:
66+
- equal:
67+
path: spec.sentinel.replicas
68+
value: 3
69+
- notExists:
70+
path: spec.sentinel.disablePodDisruptionBudget
71+
72+
- it: "keeps three Sentinels and their PDB for a negative replica count"
73+
set:
74+
replicas: -1
75+
documentSelector:
76+
path: kind
77+
value: RedisFailover
78+
asserts:
79+
- equal:
80+
path: spec.sentinel.replicas
81+
value: 3
82+
- notExists:
83+
path: spec.sentinel.disablePodDisruptionBudget
84+
5785
- it: "keeps three Sentinels for three Redis pods"
5886
set:
5987
replicas: 3

0 commit comments

Comments
 (0)