{{- include "nplus.init" $ -}}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ .component.fullName }}
  {{- if .this.utils.includeNamespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    {{- include "nplus.instanceLabels" . | nindent 4 }}
  annotations:
    {{- include "nplus.argoWave" . | nindent 4 }}
    {{- include "nplus.annotations" . | nindent 4 }}
    {{- include "nplus.securityAnnotations" . | nindent 4 }}
    ignore-check.kube-linter.io/job-ttl-seconds-after-finished: "Deletion ist done by Operator when successful, so no ttl necessary."
spec:
  # Deletion ist done by Operator when successful, so no ttl necessary.
  # ttlSecondsAfterFinished: 60
  template:
    metadata:
      labels:
        app.kubernetes.io/version: {{ .Chart.AppVersion }}
        app.kubernetes.io/managed-by: {{ .Release.Service }}
        app.kubernetes.io/instance: {{ .instance.group | default .instance.name | default .Release.Name }}
        app.kubernetes.io/component: {{ .component.chartName }}
        {{- include "nplus.templateLabels" . | nindent 8 }}
    spec:
      # hostname: {{ .component.fullName }}
      {{- include "nplus.imagePullSecrets" . | nindent 6 }}
      {{- include "nplus.podSecurityContext" . | nindent 6 }}
      {{- include "nplus.terminationGracePeriodSeconds" . | nindent 6 }}
      
      initContainers:
      {{- include "nplus.waitFor" . | nindent 6 }}
      {{- include "nplus.copyConfig" . | nindent 6 }}
      {{- include "nplus.initContainers" . | nindent 6 }}
      
      containers:
      - name: run
        image: {{ include "nplus.image"  (dict "global" .Values.global "image" .Values.image) }}
        imagePullPolicy: {{ include "nplus.imagePullPolicy" .Values.image }}
        {{- include "nplus.containerSecurityContext" . | nindent 8 }}
        env:
        {{- include "nplus.environment" . | nindent 8 }}

        command: ["/bin/bash", "-c", "/config/run"]

        {{- include "nplus.resources" . | nindent 8 }}

        volumeMounts:
        {{- include "nplus.defaultMounts" . | nindent 8 }}
        - name: config
          mountPath: /config
        - name: conf
          subPath: {{ .this.instance.name }}
          mountPath: /instance

      volumes:
      {{- include "nplus.defaultVolumes" . | nindent 6 }}
      - name: config
        configMap:
          name: {{ .component.fullName }}-config
          defaultMode: 0777

      restartPolicy: Never
  backoffLimit: 0