# helm_charts_cleanup-job.yaml
# Delete the parent chart before the sub-chart
{{- if .Values.nfs.enableExampleNFS }}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ include "spark-history-server.fullname" . }}
  annotations:
    "helm.sh/hook": pre-delete
    "helm.sh/hook-delete-policy": hook-succeeded
  labels:
    app.kubernetes.io/name: {{ include "spark-history-server.name" . }}
    helm.sh/chart: {{ include "spark-history-server.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
 template:
   spec:
     serviceAccountName: {{ include "spark-history-server.serviceAccountName" . }}
     restartPolicy: OnFailure
     containers:
     - name: main
       image: "lightbend/curl:7.47.0"
       imagePullPolicy: IfNotPresent
       command:
         - "/bin/sh"
         - "-c"
         - "curl -ik \
          -X DELETE \
          -H 'Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)' \
          -H 'Accept: application/json' \
          -H 'Content-Type: application/json' \
          https://kubernetes.default.svc/api/v1/deployments/{{ include "spark-history-server.fullname" . }}"
{{- end }}