apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "spinnaker.fullname" . }}-halyard-init-script
  labels:
{{ include "spinnaker.standard-labels" . | indent 4 }}
data:
  init.sh: |
    #!/bin/bash

    # Override Halyard daemon's listen address
    cp /opt/halyard/config/* /tmp/config
    printf 'server.address: 0.0.0.0\n' > /tmp/config/halyard-local.yml
    # Use Redis deployed via the dependent Helm chart
    rm -rf /tmp/spinnaker/.hal/default/service-settings
    mkdir -p /tmp/spinnaker/.hal/default/service-settings
    cp /tmp/service-settings/* /tmp/spinnaker/.hal/default/service-settings/

    {{- if .Values.halyard.additionalProfileConfigMaps.create }}
    rm -rf /tmp/spinnaker/.hal/default/profiles
    mkdir -p /tmp/spinnaker/.hal/default/profiles
    cp /tmp/additionalProfileConfigMaps/* /tmp/spinnaker/.hal/default/profiles/
    {{- end }}

    {{- if hasKey .Values.halyard "additionalInitScript" }}
    # additionalInitScript
    {{ .Values.halyard.additionalInitScript | indent 4 }}
    {{- end }}
