apiVersion: batch/v1
kind: Job
metadata:
  annotations:
    "helm.sh/hook": pre-delete
    "helm.sh/hook-delete-policy": hook-succeeded
  name: longhorn-uninstall
  namespace: {{ include "release_namespace" . }}
  labels: {{- include "longhorn.labels" . | nindent 4 }}
spec:
  activeDeadlineSeconds: 900
  backoffLimit: 1
  template:
    metadata:
      name: longhorn-uninstall
      labels: {{- include "longhorn.labels" . | nindent 8 }}
    spec:
      containers:
      - name: longhorn-uninstall
        image: {{ template "registry_url" . }}{{ .Values.image.longhorn.manager.repository }}:{{ .Values.image.longhorn.manager.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        securityContext:
          privileged: true
        command:
        - longhorn-manager
        - uninstall
        - --force
        env:
        - name: LONGHORN_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
      restartPolicy: OnFailure
      {{- if .Values.privateRegistry.registrySecret }}
      imagePullSecrets:
      - name: {{ .Values.privateRegistry.registrySecret }}
      {{- end }}
      {{- if .Values.longhornManager.priorityClass }}
      priorityClassName: {{ .Values.longhornManager.priorityClass | quote}}
      {{- end }}
      serviceAccountName: longhorn-service-account
      {{- if .Values.longhornManager.tolerations }}
      tolerations:
{{ toYaml .Values.longhornManager.tolerations | indent 6 }}
      {{- end }}
      {{- if .Values.longhornManager.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.longhornManager.nodeSelector | indent 8 }}
      {{- end }}