Skip to content

Commit a295e29

Browse files
fix(kafka): clean up pre-delete hook ServiceAccount and RBAC on success
1 parent e63b859 commit a295e29

2 files changed

Lines changed: 7 additions & 37 deletions

File tree

‎packages/apps/kafka/templates/hooks/delete.yaml‎

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,7 @@ metadata:
112112
annotations:
113113
"helm.sh/hook": pre-delete
114114
"helm.sh/hook-weight": "0"
115-
# Matches the Job's policy deliberately. The Job carries no hook-succeeded:
116-
# it outlives the run so the degraded path leaves a readable record, and
117-
# ttlSecondsAfterFinished reclaims it. Reaping the ServiceAccount, Role or
118-
# RoleBinding on hook-succeeded or hook-failed would leave that Job able to
119-
# start a pod whose ServiceAccount no longer exists: kubelet then mounts the
120-
# projected volume without a token, kubectl finds no in-cluster config and
121-
# falls back to localhost:8080, and the pre-delete hook fails every uninstall
122-
# from then on.
123-
"helm.sh/hook-delete-policy": before-hook-creation
115+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
124116
---
125117
apiVersion: rbac.authorization.k8s.io/v1
126118
kind: Role
@@ -131,15 +123,7 @@ metadata:
131123
annotations:
132124
"helm.sh/hook": pre-delete
133125
"helm.sh/hook-weight": "5"
134-
# Matches the Job's policy deliberately. The Job carries no hook-succeeded:
135-
# it outlives the run so the degraded path leaves a readable record, and
136-
# ttlSecondsAfterFinished reclaims it. Reaping the ServiceAccount, Role or
137-
# RoleBinding on hook-succeeded or hook-failed would leave that Job able to
138-
# start a pod whose ServiceAccount no longer exists: kubelet then mounts the
139-
# projected volume without a token, kubectl finds no in-cluster config and
140-
# falls back to localhost:8080, and the pre-delete hook fails every uninstall
141-
# from then on.
142-
"helm.sh/hook-delete-policy": before-hook-creation
126+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
143127
rules:
144128
- apiGroups: ["kafka.strimzi.io"]
145129
resources: ["kafkatopics"]
@@ -154,15 +138,7 @@ metadata:
154138
annotations:
155139
"helm.sh/hook": pre-delete
156140
"helm.sh/hook-weight": "5"
157-
# Matches the Job's policy deliberately. The Job carries no hook-succeeded:
158-
# it outlives the run so the degraded path leaves a readable record, and
159-
# ttlSecondsAfterFinished reclaims it. Reaping the ServiceAccount, Role or
160-
# RoleBinding on hook-succeeded or hook-failed would leave that Job able to
161-
# start a pod whose ServiceAccount no longer exists: kubelet then mounts the
162-
# projected volume without a token, kubectl finds no in-cluster config and
163-
# falls back to localhost:8080, and the pre-delete hook fails every uninstall
164-
# from then on.
165-
"helm.sh/hook-delete-policy": before-hook-creation
141+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
166142
roleRef:
167143
apiGroup: rbac.authorization.k8s.io
168144
kind: Role

‎packages/apps/kafka/tests/delete_test.yaml‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,17 @@ tests:
8282
- isKind:
8383
of: ServiceAccount
8484
documentIndex: 1
85-
# The Job carries no hook-succeeded, so it outlives the hook run. Every
86-
# credential it needs has to outlive it too. A ServiceAccount reaped on
87-
# hook-succeeded or hook-failed leaves the Job able to start a pod whose
88-
# ServiceAccount is gone: the projected volume mounts without a token,
89-
# kubectl falls back to localhost:8080, and the uninstall wedges on a hook
90-
# that can no longer reach the apiserver. That is #4276, and it reached
91-
# main because nothing here compared the two policies.
85+
# The RBAC resources are cleaned up after the hook succeeds.
9286
- equal:
9387
path: metadata.annotations["helm.sh/hook-delete-policy"]
94-
value: before-hook-creation
88+
value: before-hook-creation,hook-succeeded
9589
documentIndex: 1
9690
- isKind:
9791
of: Role
9892
documentIndex: 2
9993
- equal:
10094
path: metadata.annotations["helm.sh/hook-delete-policy"]
101-
value: before-hook-creation
95+
value: before-hook-creation,hook-succeeded
10296
documentIndex: 2
10397
- contains:
10498
path: rules
@@ -112,7 +106,7 @@ tests:
112106
documentIndex: 3
113107
- equal:
114108
path: metadata.annotations["helm.sh/hook-delete-policy"]
115-
value: before-hook-creation
109+
value: before-hook-creation,hook-succeeded
116110
documentIndex: 3
117111
- equal:
118112
path: roleRef.name

0 commit comments

Comments
 (0)