---
apiVersion: batch/v1
kind: Job
metadata:
  annotations:
    helm.sh/hook: pre-delete
    helm.sh/hook-delete-policy: before-hook-creation, hook-succeeded
    helm.sh/hook-weight: "2"
  labels:
    app.kubernetes.io/instance: amd-gpu-operator
    app.kubernetes.io/name: gpu-operator-charts
    app.kubernetes.io/version: v1.3.0
  name: delete-leftover-deviceconfigs
  namespace: kube-amd-gpu
spec:
  backoffLimit: 0
  template:
    spec:
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - preference:
                matchExpressions:
                  - key: node-role.kubernetes.io/control-plane
                    operator: Exists
              weight: 1
      containers:
        - command:
            - /bin/sh
            - -c
            - |
              installed=$(kubectl api-resources -owide | grep -i amd.com | grep -i deviceconfig)
              if [ -z ${installed} ] ; then
                exit 0
              fi
              kubectl delete deviceconfigs.amd.com --all -A
          image: docker.io/rocm/gpu-operator@sha256:58ac66493b185891c228ccf7c88c88973ace8ec5b59716cc6ddffd3a428c3cef # Original tag: v1.3.0
          name: delete-leftover-deviceconfigs
      restartPolicy: Never
      serviceAccountName: amd-gpu-operator-gpu-operator-charts-pre-delete
      tolerations:
        - effect: NoSchedule
          key: node-role.kubernetes.io/master
          operator: Equal
          value: ""
        - effect: NoSchedule
          key: node-role.kubernetes.io/control-plane
          operator: Equal
          value: ""
  ttlSecondsAfterFinished: 60