apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ .Release.Name }}-install-using-hal"
  labels:
{{ include "spinnaker.standard-labels" . | indent 4 }}
    component: halyard
  annotations:
    "helm.sh/hook": "post-install,post-upgrade"
    "helm.sh/hook-delete-policy": "before-hook-creation"
    "helm.sh/hook-weight": "0"
spec:
  template:
    metadata:
      labels:
{{ include "spinnaker.standard-labels" . | indent 8 }}
        component: halyard
    spec:
      {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
      {{- end }}
      restartPolicy: OnFailure
      volumes:
      {{- if .Values.kubeConfig.enabled }}
      - name: kube-config
        secret:
          secretName: {{ .Values.kubeConfig.secretName }}
      {{- end }}
      - name: halyard-config
        configMap:
          name: {{ template "spinnaker.fullname" . }}-halyard-config
      {{- if .Values.halyard.additionalConfig.enabled }}
      - name: additional-config
        configMap:
          name: {{ .Values.halyard.additionalConfig.configMapName }}
      {{- end }}
      {{- if .Values.gcs.enabled }}
      - name: gcs-key
        secret:
          secretName: {{ template "spinnaker.fullname" . }}-gcs
      {{- end }}
      {{- if and .Values.s3.enabled .Values.s3.accessKey .Values.s3.secretKey }}
      - name: s3-secrets
        secret:
          secretName: {{ template "spinnaker.fullname" .}}-s3
      {{- end }}
      containers:
      - name: halyard-install
        image: {{ .Values.halyard.image.repository }}:{{ .Values.halyard.image.tag }}
        volumeMounts:
        - name: halyard-config
          mountPath: /opt/halyard/scripts
        {{- if .Values.halyard.additionalConfig.enabled }}
        - name: additional-config
          mountPath: /opt/halyard/additional
        {{- end }}
        {{- if .Values.gcs.enabled }}
        - name: gcs-key
          mountPath: /opt/gcs
        {{- end }}
        {{- if and .Values.s3.enabled .Values.s3.accessKey .Values.s3.secretKey }}
        - name: s3-secrets
          mountPath: /opt/s3
        {{- end }}
        {{- if .Values.kubeConfig.enabled }}
        - name: kube-config
          mountPath: /opt/kube
        {{- end }}
        command:
        - bash
        - -xe
        - "/opt/halyard/scripts/install.sh"
