Skip to content

Commit 354ed21

Browse files
committed
fix(mariadb): clean up orphaned operator-generated secrets (#3056)
The mariadb-operator creates <release>-metrics-password and <release>-repl-password Secrets as a side effect of metrics/replication being enabled. These are not Helm-owned and survive `helm uninstall`, leaving orphaned Secrets in the tenant namespace after the app CR is deleted. Extend the existing post-delete cleanup hook to sweep them: grant the cleanup Role RBAC on secrets and delete both password Secrets by name. Add a helm-unittest suite locking in the behaviour (and a `test` Makefile target so the package's tests run in CI). Signed-off-by: Алексей Артамонов <[email protected]>
1 parent 374cac1 commit 354ed21

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎packages/apps/mariadb/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ update:
1111
hack/update-versions.sh
1212
make generate
1313

14+
test:
15+
helm unittest .
16+
1417
image:
1518
docker buildx build images/mariadb-backup \
1619
$(call image-tags,mariadb-backup,$(MARIADB_BACKUP_TAG)) \

‎packages/apps/mariadb/templates/hooks/cleanup-pvc.yaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ spec:
2828
echo "Deleting orphaned PVCs for {{ .Release.Name }}..."
2929
kubectl delete pvc -n {{ .Release.Namespace }} -l app.kubernetes.io/instance={{ .Release.Name }} || true
3030
echo "PVC cleanup complete."
31+
echo "Deleting orphaned operator-generated Secrets for {{ .Release.Name }}..."
32+
kubectl delete secret -n {{ .Release.Namespace }} \
33+
{{ .Release.Name }}-metrics-password {{ .Release.Name }}-repl-password --ignore-not-found || true
34+
echo "Secret cleanup complete."
3135
---
3236
apiVersion: v1
3337
kind: ServiceAccount
@@ -52,7 +56,7 @@ metadata:
5256
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
5357
rules:
5458
- apiGroups: [""]
55-
resources: ["persistentvolumeclaims"]
59+
resources: ["persistentvolumeclaims", "secrets"]
5660
verbs: ["get", "list", "delete"]
5761
---
5862
apiVersion: rbac.authorization.k8s.io/v1
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
suite: post-delete cleanup hook
2+
3+
# Locks in the post-delete cleanup behaviour. The mariadb-operator creates
4+
# <release>-metrics-password and <release>-repl-password Secrets as a side
5+
# effect of metrics/replication being enabled. These Secrets are not
6+
# Helm-owned and survive `helm uninstall`, so the post-delete hook must
7+
# sweep them (issue #3056) alongside the orphaned PVCs. The hook Role also
8+
# needs RBAC on secrets to do so.
9+
10+
templates:
11+
- templates/hooks/cleanup-pvc.yaml
12+
13+
release:
14+
name: mariadb-test
15+
namespace: tenant-test
16+
17+
tests:
18+
- it: "cleanup Job deletes the operator-generated password Secrets by name"
19+
documentSelector:
20+
path: kind
21+
value: Job
22+
asserts:
23+
- matchRegex:
24+
path: spec.template.spec.containers[0].command[2]
25+
pattern: "mariadb-test-metrics-password mariadb-test-repl-password --ignore-not-found"
26+
27+
- it: "cleanup Role grants delete on secrets"
28+
documentSelector:
29+
path: kind
30+
value: Role
31+
asserts:
32+
- contains:
33+
path: rules
34+
content:
35+
apiGroups: [""]
36+
resources: ["persistentvolumeclaims", "secrets"]
37+
verbs: ["get", "list", "delete"]

0 commit comments

Comments
 (0)