apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ .Values.redash.instance.name.admin }}-install"
  labels:
    helm.sh/chart: {{ .Values.redash.instance.name.admin }}-2.3.0
    app.kubernetes.io/name: {{ .Values.redash.instance.name.admin }}
    app.kubernetes.io/instance: {{ .Values.redash.instance.name.admin }}
    app.kubernetes.io/version: {{ .Values.redash.version }}
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: install
  annotations:
    # This is what defines this resource as a hook.
    "helm.sh/hook": post-install
    "helm.sh/hook-weight": "-5"
    "helm.sh/hook-delete-policy": hook-succeeded
spec:
  template:
    metadata:
      name: {{ .Values.redash.instance.name.admin }}
      annotations:
        sidecar.istio.io/inject: "false"
      labels:
        app.kubernetes.io/name: {{ .Values.redash.instance.name.admin }}
        app.kubernetes.io/instance: {{ .Values.redash.instance.name.admin }}
    spec:
      serviceAccountName: {{ .Values.serviceAccount.name }}
      restartPolicy: Never
      containers:
      - name: {{ .Values.redash.instance.name.admin }}-server
        image: "{{ .Values.image.name }}:{{ .Values.image.version }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        command: ["/bin/bash", "/config/install-upgrade.sh", "install"]
        volumeMounts:
          - name: config
            mountPath: /config
        env:
          - name: REDASH_DATABASE_HOSTNAME
            value: {{ .Values.redash.instance.name.admin }}-postgresql
          - name: REDASH_REDIS_HOSTNAME
            value: {{ .Values.redash.instance.name.admin }}-redis-master
          - name: REDASH_SAML_ENTITY_ID
            value: {{ default  .Values.redash.samlEntityId.admin | quote }}
        {{- include "redash.env" . | nindent 10 }}
        {{- range $key, $value := .Values.server.env }}
          - name: "{{ $key }}"
            value: "{{ $value }}"
        {{- end }}
        envFrom:
        {{- include "redash.envFrom" . | nindent 10 }}
        {{- if not .Values.global.disableRequestsLimits }}
        resources:
{{ toYaml .Values.server.resources | indent 10 }}
        {{- end }}
      volumes:
        - name: config
          configMap:
            name: {{ include "redash.fullname" . }}
    {{- with .Values.server.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.server.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.server.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}