{{- if .Values.ingress.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ .Release.Name }}-expose-nodeports"
  labels:
{{ include "spinnaker.standard-labels" . | indent 4 }}
    component: halyard
  annotations:
    "helm.sh/hook": "post-install, post-upgrade"
    "helm.sh/hook-weight": "5"
    "helm.sh/hook-delete-policy": "before-hook-creation"
spec:
  template:
    metadata:
      labels:
{{ include "spinnaker.standard-labels" . | indent 8 }}
        component: halyard
    spec:
      {{- if .Values.serviceAccount.halyardName }}
      serviceAccountName: {{ .Values.serviceAccount.halyardName }}
      {{- else }}
      serviceAccountName: {{ template "spinnaker.fullname" . }}-halyard
      {{- end }}
      restartPolicy: OnFailure
      containers:
      - name: patch-services
        image: {{ .Values.halyard.image.repository }}:{{ .Values.halyard.image.tag }}
        command:
        - bash
        - -c
        - |
          PATCH='{"spec": {"type":"NodePort"}}'
          if [ "$(kubectl get service --namespace {{ .Release.Namespace }} spin-deck -o=jsonpath='{.spec.type}')" = "ClusterIP" ]; then
            kubectl patch service --namespace {{ .Release.Namespace }} spin-deck --patch "$PATCH"
          fi
          if [ "$(kubectl get service --namespace {{ .Release.Namespace }} spin-gate -o=jsonpath='{.spec.type}')" = "ClusterIP" ]; then
            kubectl patch service --namespace {{ .Release.Namespace }} spin-gate --patch "$PATCH"
          fi
{{- end }}
