Skip to content

Commit fd568de

Browse files
committed
fix(keycloak-configure): patch HelmRelease in release namespace on teardown
The pre-delete teardown Job clears the HelmRelease finalizers as its final step, but targeted a hardcoded namespace that does not match the namespace where the release and its RBAC live. The Job's Role and RoleBinding are created in the release namespace and grant patch on the HelmRelease by release name, so the ServiceAccount was Forbidden to patch the HelmRelease in the hardcoded namespace. The Job errored and retried forever, the HelmRelease stuck in Terminating, and the Helm release wedged in "uninstalling", blocking any teardown or reinstall. Target the release name and namespace so the patch matches the RBAC that grants it. Add a helm-unittest pinning the rendered namespace. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 8bffa34 commit fd568de

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎packages/system/keycloak-configure/templates/delete.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spec:
3939
done
4040
done
4141
42-
kubectl patch hr keycloak-configure -n cozy-system --type=merge -p '{"metadata":{"finalizers":[]}}'
42+
kubectl patch hr {{ .Release.Name }} -n {{ .Release.Namespace }} --type=merge -p '{"metadata":{"finalizers":[]}}'
4343
4444
4545
---
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
suite: flux teardown job patches the HelmRelease in the release namespace
2+
3+
# The pre-delete teardown Job clears the HelmRelease finalizers as its last
4+
# step. Its RBAC (Role + RoleBinding, resourceNames: [.Release.Name]) is created
5+
# in .Release.Namespace, so the kubectl patch MUST target that same namespace and
6+
# release name. A hardcoded namespace that differs from the install namespace
7+
# makes the ServiceAccount Forbidden to patch the HelmRelease, the Job retries
8+
# forever, and the Helm release wedges in "uninstalling".
9+
release:
10+
name: keycloak-configure
11+
namespace: cozy-keycloak
12+
tests:
13+
- it: teardown patches the HelmRelease using the release name and namespace
14+
template: templates/delete.yaml
15+
documentSelector:
16+
path: kind
17+
value: Job
18+
set:
19+
_cluster:
20+
root-host: example.com
21+
kube-root-ca: ""
22+
asserts:
23+
- matchRegex:
24+
path: spec.template.spec.containers[0].command[2]
25+
pattern: kubectl patch hr keycloak-configure -n cozy-keycloak
26+
27+
- it: teardown never targets a namespace other than the release namespace
28+
template: templates/delete.yaml
29+
documentSelector:
30+
path: kind
31+
value: Job
32+
set:
33+
_cluster:
34+
root-host: example.com
35+
kube-root-ca: ""
36+
asserts:
37+
- notMatchRegex:
38+
path: spec.template.spec.containers[0].command[2]
39+
pattern: patch hr \S+ -n cozy-system
40+
41+
# Prove the patch is parameterized on .Release.Name / .Release.Namespace
42+
# rather than matching the default install namespace by coincidence.
43+
- it: teardown tracks a non-default release name and namespace
44+
template: templates/delete.yaml
45+
documentSelector:
46+
path: kind
47+
value: Job
48+
release:
49+
name: custom-release
50+
namespace: custom-ns
51+
set:
52+
_cluster:
53+
root-host: example.com
54+
kube-root-ca: ""
55+
asserts:
56+
- matchRegex:
57+
path: spec.template.spec.containers[0].command[2]
58+
pattern: kubectl patch hr custom-release -n custom-ns

0 commit comments

Comments
 (0)