apiVersion: batch/v1
kind: Job
metadata:
  annotations:
    "helm.sh/hook": post-upgrade
    "helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
  name: longhorn-post-upgrade
  namespace: {{ .Release.Namespace }}
  labels: {{- include "longhorn.labels" . | nindent 4 }}
spec:
  activeDeadlineSeconds: 900
  backoffLimit: 1
  template:
    metadata:
      name: longhorn-post-upgrade
      labels: {{- include "longhorn.labels" . | nindent 8 }}
    spec:
      containers:
      - name: longhorn-post-upgrade
        image: {{ template "registry_url" . }}{{ .Values.image.longhorn.manager.repository }}:{{ .Values.image.longhorn.manager.tag }}
        imagePullPolicy: Always
        command:
        - longhorn-manager
        - post-upgrade
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
      restartPolicy: OnFailure
      {{- if .Values.defaultSettings.registrySecret }}
      imagePullSecrets:
      - name: {{ .Values.defaultSettings.registrySecret }}
      {{- end }}
      serviceAccountName: longhorn-service-account
