{{- $replicas := int .Values.replicaCount }}
{{- $raftNodes := include "orchestrator.raftList" . | splitList "," }}
{{- $raftServiceName := include "orchestrator.fullname" . }}
{{- $conf := .Values.orchestrator.config }}
{{- $_ := set $conf "ListenAddress" ":3000" }}
{{- $_ := set $conf "MySQLTopologyCredentialsConfigFile" "/etc/orchestrator/orc-topology.cnf" }}
{{- $_ := set $conf "BackendDB" "sqlite" }}
{{- $_ := set $conf "SQLite3DataFile" "/var/lib/orchestrator/orc.db" }}
{{- $_ := set $conf "RaftEnabled" true }}
{{- $_ := set $conf "RaftDataDir" "/var/lib/orchestrator" }}
{{- $_ := set $conf "RaftAdvertise" (printf "{{ .Env.HOSTNAME }}.%s" $raftServiceName) }}
{{- $_ := set $conf "RaftBind" "{{ .Env.HOSTNAME }}"}}
{{- $_ := set $conf "HTTPAdvertise" (printf "http://{{ .Env.HOSTNAME }}.%s:3000" $raftServiceName) }}
{{- if eq 1 $replicas -}}
{{- $_ := set $conf "RaftNodes" (list) }}
{{- else -}}
{{- $_ := set $conf "RaftNodes" $raftNodes }}
{{- end -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "orchestrator.fullname" . }}
  labels:
    {{- include "mysql-operator.labels" . | nindent 4 }}
data:
  orchestrator.conf.json: {{ toPrettyJson $conf | quote }}
  orc-topology.cnf: |
    [client]
    user = {{ printf "{{ .Env.ORC_TOPOLOGY_USER }}" }}
    password = {{ printf "{{ .Env.ORC_TOPOLOGY_PASSWORD }}" }}
