apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "fullname" . }}
  labels:
    {{- include "common.labels.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: gitee-mysql
    app: {{ template "fullname" . }}
    chart: "{{ template "mysqlha.chart" . }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
data:
{{ toYaml .Values.mysqlha.master.configFiles | indent 2 }}
  server-id.cnf: |
    [mysqld]
    server-id=1@@SERVER_ID@@
  create-replication-user.sh: |-
    #!/bin/bash
    set -e
    replication_count=`mysql -uroot -h 127.0.0.1 -e "select count(1) from mysql.user where User='${MYSQL_REPLICATION_USER}'"`
    req_count=`echo "$replication_count" |awk 'NR==1 {next} {print $1}'`
    if [[ $req_count -eq 1 ]];then
      exit 0
    fi
    mysql -uroot -h 127.0.0.1 --verbose -e "CREATE USER IF NOT EXISTS '${MYSQL_REPLICATION_USER}' IDENTIFIED BY '${MYSQL_REPLICATION_PASSWORD}';"
    mysql -uroot -h 127.0.0.1 --verbose -e "GRANT PROCESS, RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '${MYSQL_REPLICATION_USER}';"
    mysql -uroot -h 127.0.0.1 --verbose -e "FLUSH PRIVILEGES;"
