{{- if and .Values.configuration.backupStorageProvider.name .Values.configuration.backupStorageProvider.bucket -}}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ template "ark.fullname" . }}-create-config
  labels:
    chart: {{ template "ark.chart" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
    app: {{ template "ark.name" . }}
  annotations:
    "helm.sh/hook": post-install
    "helm.sh/hook-delete-policy": hook-succeeded
spec:
  template:
    metadata:
      labels:
        release: {{ .Release.Name }}
        app: {{ template "ark.name" . }}
    spec:
      restartPolicy: Never
      containers:
        - name: create-ark-config
          image: "{{ .Values.kubectl.image.repository }}:{{ .Values.kubectl.image.tag }}"
          imagePullPolicy: {{ .Values.kubectl.image.pullPolicy }}
          command:
            - kubectl
          args:
            - create
            - -f
            - /config
          volumeMounts:
            - name: ark-config
              mountPath: /config
      volumes:
        - name: ark-config
          configMap:
            name: {{ template "ark.fullname" . }}
      serviceAccountName: {{ template "ark.hookServiceAccount" . }}
{{- end -}}
