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