apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ include "who-need-help.fullname" . }}-migrate-{{ .Release.Revision }}"
  labels:
    {{- include "who-need-help.labels" . | nindent 4 }}
    app.kubernetes.io/component: migrate
  annotations:
    helm.sh/hook: pre-install,pre-upgrade
    helm.sh/hook-weight: "0"
    helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
spec:
  backoffLimit: 4
  template:
    metadata:
      labels:
        {{- include "who-need-help.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: migrate
    spec:
      restartPolicy: Never
      securityContext:
        runAsNonRoot: true
        runAsUser: 65534
        fsGroup: 65534
      containers:
        - name: migrate
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command: ["/app/bin/migrate"]
          envFrom:
            - secretRef:
                name: {{ include "who-need-help.secretName" . }}
          env:
            - name: APP_ROLE
              value: migrate
            - name: ERL_ZFLAGS
              value: {{ printf "+Q %d" (int .Values.app.erlangPortLimit) | quote }}
            - name: CLUSTER_INTERFACE
              value: {{ .Values.app.clusterInterface | quote }}
            - name: POOL_SIZE
              value: {{ .Values.app.migratePoolSize | quote }}
            - name: OBAN_MAINTENANCE_CONCURRENCY
              value: {{ .Values.worker.maintenanceConcurrency | quote }}
            - name: OBAN_PUSH_CONCURRENCY
              value: {{ .Values.worker.pushConcurrency | quote }}
            - name: EMAIL_DELIVERY_PROVIDER
              value: {{ .Values.app.emailDeliveryProvider | quote }}
            - name: UNISENDER_GO_BASE_URL
              value: {{ .Values.app.unisenderGoBaseUrl | quote }}
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
