fix(redis): drop the post-upgrade hook that deleted the Sentinel PDB

The hook ran a ServiceAccount, Role, RoleBinding and a kubectl Job on
every upgrade of every single-replica instance, to delete the Sentinel
PDB the operator left behind once disablePodDisruptionBudget was set.
The operator now deletes a disabled PDB itself on reconcile, so the
hook, its RBAC and the helper extracted for it have no work left.

An instance that still carries the stale PDB loses it on the first
reconcile by the updated operator.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
This commit is contained in:
Aleksei Sviridkin committed 2026-12-02 05:45:52 +03:00
1 parent 56648783b3
commit aeb9bf6fbf
4 files changed
+2 -284

No files matched your search

@@ -47,7 +47,3 @@ These presets are for basic testing and not meant to be used in production
{{- printf "ERROR: Preset key '%s' invalid. Allowed values are %s" .type (join "," (keys $presets)) | fail -}}
{{- end -}}
{{- end -}}
{{- define "redis.sentinelReplicas" -}}
{{- ternary 1 3 (eq (int .Values.replicas) 1) -}}
{{- end -}}
@@ -1,122 +0,0 @@
{{- /*
An instance scaled down to one Redis pod keeps the Sentinel PDB the operator
created while it ran three Sentinels: setting disablePodDisruptionBudget only
stops the operator from ensuring it, never deletes it, and minAvailable 1 on
a single Sentinel refuses every eviction. A fresh install with one replica
never gets that PDB, so this runs on upgrade only.
*/}}
{{- if and .Release.IsUpgrade (eq (include "redis.sentinelReplicas" . | int) 1) }}
{{- $name := printf "%s-sentinel-pdb" .Release.Name }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ $name }}
labels:
app.kubernetes.io/instance: {{ .Release.Name }}
annotations:
helm.sh/hook: post-upgrade
helm.sh/hook-weight: "0"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $name }}
labels:
app.kubernetes.io/instance: {{ .Release.Name }}
annotations:
helm.sh/hook: post-upgrade
helm.sh/hook-weight: "0"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
rules:
- apiGroups: ["policy"]
resources: ["poddisruptionbudgets"]
resourceNames: ["rfs-{{ .Release.Name }}"]
verbs: ["get", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $name }}
labels:
app.kubernetes.io/instance: {{ .Release.Name }}
annotations:
helm.sh/hook: post-upgrade
helm.sh/hook-weight: "0"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ $name }}
subjects:
- kind: ServiceAccount
name: {{ $name }}
namespace: {{ .Release.Namespace }}
---
apiVersion: batch/v1
kind: Job
metadata:
{{- /* 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:
helm.sh/hook: post-upgrade
helm.sh/hook-weight: "5"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
spec:
ttlSecondsAfterFinished: 3600
# Bounds the kubectl call too: a --request-timeout would make kubectl skip
# its in-cluster credentials (hack/check-hook-request-timeout.bats).
activeDeadlineSeconds: 120
backoffLimit: 2
template:
metadata:
labels:
app.kubernetes.io/instance: {{ .Release.Name }}
policy.cozystack.io/allow-to-apiserver: "true"
spec:
serviceAccountName: {{ $name }}
restartPolicy: Never
terminationGracePeriodSeconds: 10
securityContext:
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
seccompProfile:
type: RuntimeDefault
containers:
- name: delete-pdb
image: '{{ include "cozy-lib.image" (list "clastix/kubectl:v1.32@sha256:b9ef7d8dbe65bcc81a46c09b8dc7543103055021c4f43287bf59e92a8f4fe05c" $) }}'
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
env:
- name: HOME
value: /tmp
command:
- kubectl
- --namespace={{ .Release.Namespace }}
- delete
- poddisruptionbudget
- rfs-{{ .Release.Name }}
- --ignore-not-found=true
volumeMounts:
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
emptyDir: {}
{{- end }}
@@ -22,11 +22,9 @@
watch it. One Sentinel still lets the operator find the master (its quorum is
replicas/2+1, so 1). The operator gives the Sentinel Deployment a PDB with
minAvailable 1 whenever Redis has two replicas or fewer, which on a single
Sentinel would block every node drain, so that PDB is dropped with it; the
operator does not delete a PDB it stops managing, hence
hooks/sentinel-pdb.yaml.
Sentinel would block every node drain, so that PDB is dropped with it.
*/}}
{{- $sentinelReplicas := include "redis.sentinelReplicas" . | int -}}
{{- $sentinelReplicas := ternary 1 3 (eq (int .Values.replicas) 1) -}}
{{- $sentinelPreset := $sentinel.resourcesPreset | default .Values.resourcesPreset -}}
{{- $sentinelResources := .Values.resources -}}
{{- if or $sentinel.resources $sentinel.resourcesPreset -}}
@@ -1,154 +0,0 @@
suite: stale Sentinel PDB removed on scale-down to one Redis pod
# The operator only stops ensuring the Sentinel PDB once
# disablePodDisruptionBudget is set; it never deletes the one it created while
# three Sentinels ran. Left in place, its minAvailable 1 refuses every eviction
# of the single Sentinel and blocks node drains.
templates:
- templates/hooks/sentinel-pdb.yaml
release:
name: my-redis
namespace: tenant-test
set:
_cluster:
cluster-domain: cluster.local
_namespace:
host: example.com
tests:
- it: deletes the operator's Sentinel PDB on an upgrade to one replica
release:
upgrade: true
set:
replicas: 1
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.annotations["helm.sh/hook"]
value: post-upgrade
- equal:
path: spec.template.spec.containers[0].command
value:
- kubectl
- --namespace=tenant-test
- delete
- poddisruptionbudget
- rfs-my-redis
- --ignore-not-found=true
- notMatchRegex:
path: spec.template.spec.containers[0].command[4]
pattern: request-timeout
- it: lets the hook delete only that PDB
release:
upgrade: true
set:
replicas: 1
documentSelector:
path: kind
value: Role
asserts:
- equal:
path: rules
value:
- apiGroups: ["policy"]
resources: ["poddisruptionbudgets"]
resourceNames: ["rfs-my-redis"]
verbs: ["get", "delete"]
- it: renders nothing on install, where no such PDB exists
set:
replicas: 1
asserts:
- hasDocuments:
count: 0
- it: renders nothing while three Sentinels run
release:
upgrade: true
set:
replicas: 2
asserts:
- 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.
- 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]$'
# The full release name stays in the Job name, so the hooks of two
# releases in one namespace never replace each other's Job.
- matchRegex:
path: metadata.name
pattern: ^redis-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-
- equal:
path: spec.template.spec.containers[0].command[4]
value: rfs-redis-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- it: lets the hook delete the Sentinel PDB of the longest release name
release:
name: redis-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
upgrade: true
set:
replicas: 1
documentSelector:
path: kind
value: Role
asserts:
- equal:
path: rules[0].resourceNames
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