apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ template "common.names.fullname" . }}-preinstall-job"
  labels:
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/instance: {{ .Release.Name | quote }}
    app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
    helm.sh/chart: {{ template "common.names.chart" . }}
  annotations:
    "helm.sh/hook": pre-install
    "helm.sh/hook-delete-policy": hook-succeeded
spec:
  template:
    metadata:
      name: "{{ template "common.names.fullname" . }}-preinstall-hook"
      labels:
        app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
        app.kubernetes.io/instance: {{ .Release.Name | quote }}
        helm.sh/chart: {{ template "common.names.chart" . }}
    spec:
      restartPolicy: Never
      containers:
      - name: pre-install-job
        image: "alpine:latest"
        command: ["/bin/sh", "-c"]
        args:
          - {{ include "add.user" . }}
            {{ include "change.user.permissions" . }}
        volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" (dict "appVolumeMounts" .Values.elasticSearchAppVolumeMounts )  | nindent 12 }}
      volumes: {{ include "common.storage.configureAppVolumes" (dict "appVolumeMounts" .Values.elasticSearchAppVolumeMounts "emptyDirVolumes" .Values.emptyDirVolumes "ixVolumes" .Values.ixVolumes) | nindent 8 }}
