Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixed-20260816-093535.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixed
body: Honor postCleanup.serviceAccountName on the post-delete ServiceAccount, ClusterRole, and ClusterRoleBinding
time: 2026-08-16T09:35:35.907047345+01:00
custom:
Author: dttung2905
Issue: ""
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: post-delete-cleanup
name: {{ .Values.postCleanup.serviceAccountName }}
Comment thread
dttung2905 marked this conversation as resolved.
Outdated
annotations:
{{- include "kai-scheduler.post-delete-hook-annotations" . | nindent 4 }}
subjects:
- kind: ServiceAccount
name: post-delete-cleanup
name: {{ .Values.postCleanup.serviceAccountName }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: post-delete-cleanup
name: {{ .Values.postCleanup.serviceAccountName }}
apiGroup: rbac.authorization.k8s.io
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: post-delete-cleanup
name: {{ .Values.postCleanup.serviceAccountName }}
Comment thread
dttung2905 marked this conversation as resolved.
Outdated
annotations:
{{- include "kai-scheduler.post-delete-hook-annotations" . | nindent 4 }}
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: post-delete-cleanup
name: {{ .Values.postCleanup.serviceAccountName }}
namespace: {{ .Release.Namespace }}
labels:
app: kai-operator
Expand Down
69 changes: 69 additions & 0 deletions deployments/kai-scheduler/tests/post_delete_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
suite: test post-delete cleanup hook
templates:
- hooks/post/post-delete-job.yaml
- services/post-delete-serviceaccount.yaml
- rbac/post-delete-clusterrole.yaml
- rbac/post-delete-binding.yaml
tests:
- it: should delete only operator-managed deployments in the release namespace
templates:
- hooks/post/post-delete-job.yaml
release:
namespace: custom-ns
asserts:
Expand All @@ -17,6 +22,8 @@ tests:
pattern: delete deployments? --all

- it: should delete kai-config when the config deployer is enabled
templates:
- hooks/post/post-delete-job.yaml
set:
kaiConfigDeployer.enabled: true
asserts:
Expand All @@ -25,6 +32,8 @@ tests:
pattern: kubectl delete Config kai-config --ignore-not-found

- it: should preserve kai-config when the config deployer is disabled
templates:
- hooks/post/post-delete-job.yaml
set:
kaiConfigDeployer.enabled: false
asserts:
Expand All @@ -33,6 +42,8 @@ tests:
pattern: kubectl delete Config kai-config

- it: should not delete kai-config in GitOps mode (pruned as a tracked release resource)
templates:
- hooks/post/post-delete-job.yaml
set:
kaiConfigDeployer.enabled: false
kaiConfig.render: true
Expand All @@ -42,6 +53,8 @@ tests:
pattern: kubectl delete Config kai-config

- it: should carry the ArgoCD PostDelete hook annotations
templates:
- hooks/post/post-delete-job.yaml
asserts:
- equal:
path: metadata.annotations["argocd.argoproj.io/hook"]
Expand All @@ -51,6 +64,8 @@ tests:
value: BeforeHookCreation,HookSucceeded

- it: should place the cleanup job in the release namespace
templates:
- hooks/post/post-delete-job.yaml
release:
namespace: custom-ns
asserts:
Expand All @@ -64,3 +79,57 @@ tests:
asserts:
- hasDocuments:
count: 0

- it: should use the default postCleanup.serviceAccountName on the job
templates:
- hooks/post/post-delete-job.yaml
asserts:
- equal:
path: spec.template.spec.serviceAccountName
value: post-delete-cleanup

- it: should name the ServiceAccount from postCleanup.serviceAccountName
templates:
- services/post-delete-serviceaccount.yaml
set:
postCleanup.serviceAccountName: custom-cleanup-sa
asserts:
- equal:
path: metadata.name
value: custom-cleanup-sa

- it: should name the ClusterRole from postCleanup.serviceAccountName
templates:
- rbac/post-delete-clusterrole.yaml
set:
postCleanup.serviceAccountName: custom-cleanup-sa
asserts:
- equal:
path: metadata.name
value: custom-cleanup-sa

- it: should wire ClusterRoleBinding subject and roleRef from postCleanup.serviceAccountName
templates:
- rbac/post-delete-binding.yaml
set:
postCleanup.serviceAccountName: custom-cleanup-sa
asserts:
- equal:
path: metadata.name
value: custom-cleanup-sa
- equal:
path: subjects[0].name
value: custom-cleanup-sa
- equal:
path: roleRef.name
value: custom-cleanup-sa

- it: should point the Job at the custom ServiceAccount
templates:
- hooks/post/post-delete-job.yaml
set:
postCleanup.serviceAccountName: custom-cleanup-sa
asserts:
- equal:
path: spec.template.spec.serviceAccountName
value: custom-cleanup-sa
2 changes: 2 additions & 0 deletions deployments/kai-scheduler/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ postCleanup:
name: crd-upgrader
pullPolicy: IfNotPresent
# tag: "" # Optional: Override global.tag or Chart.AppVersion
# Name of the ServiceAccount, ClusterRole, and ClusterRoleBinding used by the
Comment thread
dttung2905 marked this conversation as resolved.
Outdated
# post-delete hook Job. Keep these resources in sync by changing this one value.
serviceAccountName: post-delete-cleanup
resources: {}

Expand Down