Skip to content

Commit

Permalink
Add Helm pre-delete hook to remove configurations before Akri chart c…
Browse files Browse the repository at this point in the history
…leanup

Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed Nov 6, 2024
1 parent f12e5a2 commit b30e14e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
36 changes: 36 additions & 0 deletions deployment/helm/templates/pre-delete-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.cleanupHook.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-cleanup"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app.kubernetes.io/component: helm-hook
spec:
restartPolicy: Never
serviceAccountName: akri-helm-cleanup-hook-sa
containers:
- name: delete-configurations
image: curlimages/curl:latest
command: ["/bin/sh", "-c"]
args: [
"curl -ik -X DELETE -H \"Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)\" https://kubernetes.default.svc.cluster.local/apis/akri.sh/v0/namespaces/{{ .Release.Namespace }}/configurations"
]
{{- end }}
35 changes: 35 additions & 0 deletions deployment/helm/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,39 @@ subjects:
- kind: 'ServiceAccount'
name: 'akri-agent-sa'
namespace: {{ .Release.Namespace }}
{{- if .Values.cleanupHook.enabled }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: akri-helm-cleanup-hook-sa
labels:
app.kubernetes.io/component: helm-hook
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: "akri-helm-cleanup-hook-role"
labels:
app.kubernetes.io/component: helm-hook
rules:
- apiGroups: ["akri.sh"]
resources: ["configurations"]
verbs: ["deletecollection"]
---
apiVersion: 'rbac.authorization.k8s.io/v1'
kind: 'ClusterRoleBinding'
metadata:
name: "akri-helm-cleanup-hook-binding"
labels:
app.kubernetes.io/component: helm-hook
roleRef:
apiGroup: ''
kind: 'ClusterRole'
name: 'akri-helm-cleanup-hook-role'
subjects:
- kind: 'ServiceAccount'
name: 'akri-helm-cleanup-hook-sa'
namespace: {{ .Release.Namespace }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions deployment/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ useDevelopmentContainers: true
# This can be set from the helm command line using `--set imagePullSecrets[0].name="mysecret"`
imagePullSecrets: []

cleanupHook:
# enabled defines whether to enable the Helm pre-delete hook to cleanup
# Configurations during chart deletion. Also applies associated RBAC for the
# hook. More information on Helm hooks:
# https://helm.sh/docs/topics/charts_hooks/
enabled: true

# generalize references to `apiGroups` and `apiVersion` values for Akri CRDs
crds:
group: akri.sh
Expand Down

0 comments on commit b30e14e

Please sign in to comment.