Files
gpu-operator-charts/templates/post-delete-hook.yaml
2025-12-16 17:56:13 +11:00

118 lines
4.3 KiB
YAML

# Run helm uninstall with --no-hooks to bypass the post-delete hook
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "helm-charts-k8s.fullname" . }}-prune
namespace: {{ .Release.Namespace }}
labels:
{{- include "helm-charts-k8s.labels" . | nindent 4 }}
annotations:
# hook with lower weight value will run firstly
"helm.sh/hook-weight": "0"
"helm.sh/hook": post-delete
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "helm-charts-k8s.fullname" . }}-prune
labels:
{{- include "helm-charts-k8s.labels" . | nindent 4 }}
annotations:
# hook with lower weight value will run firstly
"helm.sh/hook-weight": "0"
"helm.sh/hook": post-delete
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
rules:
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- delete
- get
- list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "helm-charts-k8s.fullname" . }}-prune
labels:
{{- include "helm-charts-k8s.labels" . | nindent 4 }}
annotations:
# hook with lower weight value will run firstly
"helm.sh/hook-weight": "1"
"helm.sh/hook": post-delete
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "helm-charts-k8s.fullname" . }}-prune
subjects:
- kind: ServiceAccount
name: {{ include "helm-charts-k8s.fullname" . }}-prune
namespace: {{ .Release.Namespace }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: delete-custom-resource-definitions
namespace: {{ .Release.Namespace }}
labels:
{{- include "helm-charts-k8s.labels" . | nindent 4 }}
annotations:
# hook with lower weight value will run firstly
"helm.sh/hook-weight": "2"
# hook will be executed after helm uninstall
"helm.sh/hook": post-delete
# remove the resource created by the hook whether it succeeded or failed
"helm.sh/hook-delete-policy": before-hook-creation, hook-succeeded
spec:
backoffLimit: 0 # once the job finished first run, don't retry to create another pod
ttlSecondsAfterFinished: 60 # job info will be kept for 1 min then deleted
template:
spec:
serviceAccountName: {{ include "helm-charts-k8s.fullname" . }}-prune
containers:
- name: delete-custom-resource-definitions
image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag }}
command:
- /bin/sh
- -c
- |
if kubectl get crds deviceconfigs.amd.com > /dev/null 2>&1; then
kubectl delete crds deviceconfigs.amd.com
fi
{{- if index .Values "node-feature-discovery" "enabled" }}
if kubectl get crds nodefeaturegroups.nfd.k8s-sigs.io > /dev/null 2>&1; then
kubectl delete crds nodefeaturegroups.nfd.k8s-sigs.io
fi
if kubectl get crds nodefeaturerules.nfd.k8s-sigs.io > /dev/null 2>&1; then
kubectl delete crds nodefeaturerules.nfd.k8s-sigs.io
fi
if kubectl get crds nodefeatures.nfd.k8s-sigs.io > /dev/null 2>&1; then
kubectl delete crds nodefeatures.nfd.k8s-sigs.io
fi
{{- end }}
{{- if .Values.kmm.enabled }}
if kubectl get crds modules.kmm.sigs.x-k8s.io > /dev/null 2>&1; then
kubectl delete crds modules.kmm.sigs.x-k8s.io
fi
if kubectl get crds nodemodulesconfigs.kmm.sigs.x-k8s.io > /dev/null 2>&1; then
kubectl delete crds nodemodulesconfigs.kmm.sigs.x-k8s.io
fi
{{- end }}
{{- if .Values.controllerManager.manager.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.controllerManager.manager.imagePullSecrets }}
{{- end }}
{{- with .Values.controllerManager.manager.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.controllerManager.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never