fix(redis): keep the Sentinel PDB hook Job name within 63 characters

The API server copies a Job's name into its pods' job-name label, which
takes 63 characters at most, and a release name may take 53, so
<release>-sentinel-pdb could be refused and leave the stale PDB in
place. The Job name is truncated; the ServiceAccount, Role and
RoleBinding keep the full name.

Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
(cherry picked from commit 2541aec625)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
Mattia Eleuteri authored and Myasnikov Daniil committed 2026-11-10 12:40:55 +00:00
1 parent 048949f02e
commit ef2657a3fb
2 files changed
+40 -1

No files matched your search

@@ -57,7 +57,10 @@ subjects:
apiVersion: batch/v1
kind: Job
metadata:
name: {{ $name }}
{{- /* The API server copies a Job's name into its pods' job-name label,
which takes 63 characters at most, while a release name may take 53.
The objects above have no such limit and keep the full name. */}}
name: {{ $name | trunc 63 | trimSuffix "-" }}
labels:
app.kubernetes.io/instance: {{ .Release.Name }}
annotations:
@@ -76,3 +76,39 @@ tests:
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.
- it: keeps the Job name within 63 characters for the longest release name
release:
name: redis-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
upgrade: true
set:
replicas: 1
documentSelector:
path: kind
value: Job
asserts:
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9-]{1,63}$
- matchRegex:
path: metadata.name
pattern: '[a-z0-9]$'
- equal:
path: spec.template.spec.containers[0].command[4]
value: rfs-redis-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- it: keeps the full Job name for a short release name
release:
upgrade: true
set:
replicas: 1
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: my-redis-sentinel-pdb