diff --git a/incubator/mysqlha/Chart.yaml b/incubator/mysqlha/Chart.yaml index f224091099..f4e7188692 100644 --- a/incubator/mysqlha/Chart.yaml +++ b/incubator/mysqlha/Chart.yaml @@ -1,5 +1,5 @@ name: mysqlha -version: 0.3.0 +version: 0.4.0 appVersion: 5.7.13 description: MySQL cluster with a single master and zero or more slave replicas keywords: diff --git a/incubator/mysqlha/templates/configmap.yaml b/incubator/mysqlha/templates/configmap.yaml index 930c6ae9be..376bfe5fea 100644 --- a/incubator/mysqlha/templates/configmap.yaml +++ b/incubator/mysqlha/templates/configmap.yaml @@ -12,7 +12,10 @@ data: server-id.cnf: | [mysqld] server-id=@@SERVER_ID@@ - create-replication-user.sql: | - CREATE USER IF NOT EXISTS '@@REPLICATION_USER@@' IDENTIFIED BY '@@REPLICATION_PASSWORD@@'; - GRANT PROCESS, RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '@@REPLICATION_USER@@'; - FLUSH PRIVILEGES; \ No newline at end of file + create-replication-user.sh: |- + #!/bin/bash + set -e + + mysql -h 127.0.0.1 --verbose -e "CREATE USER IF NOT EXISTS '${MYSQL_REPLICATION_USER}' IDENTIFIED BY '${MYSQL_REPLICATION_PASSWORD}';" + mysql -h 127.0.0.1 --verbose -e "GRANT PROCESS, RELOAD, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '${MYSQL_REPLICATION_USER}';" + mysql -h 127.0.0.1 --verbose -e "FLUSH PRIVILEGES;" diff --git a/incubator/mysqlha/templates/statefulset.yaml b/incubator/mysqlha/templates/statefulset.yaml index 6401d3b13c..29db5db8f7 100644 --- a/incubator/mysqlha/templates/statefulset.yaml +++ b/incubator/mysqlha/templates/statefulset.yaml @@ -51,8 +51,8 @@ spec: mountPath: /etc/mysql/conf.d - name: init-mysql image: {{ .Values.mysqlImage }} - command: - - bash + command: ["/bin/bash"] + args: - "-c" - | set -ex @@ -63,13 +63,14 @@ spec: cat /mnt/config-map/server-id.cnf | sed s/@@SERVER_ID@@/$((100 + $ordinal))/g > /mnt/conf.d/server-id.cnf # Copy appropriate conf.d files from config-map to config mount. if [[ $ordinal -eq 0 ]]; then - cp /mnt/config-map/master.cnf /mnt/conf.d/ + cp -f /mnt/config-map/master.cnf /mnt/conf.d/ else - cp /mnt/config-map/slave.cnf /mnt/conf.d/ + cp -f /mnt/config-map/slave.cnf /mnt/conf.d/ fi # Copy replication user script if [[ $ordinal -eq 0 ]]; then - cp /mnt/config-map/create-replication-user.sql /mnt/scripts/create-replication-user.sql + cp -f /mnt/config-map/create-replication-user.sh /mnt/scripts/create-replication-user.sh + chmod 700 /mnt/scripts/create-replication-user.sh fi volumeMounts: - name: conf @@ -154,58 +155,55 @@ spec: ports: - name: xtrabackup containerPort: 3307 - command: - - bash - - "-c" - - | - set -ex + command: ["/bin/bash"] + args: + - "-c" + - | + set -ex - echo "Waiting for mysqld to be ready (accepting connections)" - until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done + echo "Waiting for mysqld to be ready (accepting connections)" + until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 5; done - # Create replication user - cd /mnt/scripts - if [[ -f create-replication-user.sql ]]; then - cp create-replication-user.sql create-replication-user.orig.sql - cat create-replication-user.sql \ - | sed s/@@REPLICATION_USER@@/"${MYSQL_REPLICATION_USER}"/g \ - | sed s/@@REPLICATION_PASSWORD@@/"${MYSQL_REPLICATION_PASSWORD}"/g \ - | tee create-replication-user.sql - mysql -h 127.0.0.1 --verbose < create-replication-user.sql - fi + # Create replication user + cd /mnt/scripts + # file exists and is not empty with -s + if [[ -s create-replication-user.sh ]]; then + ls -la + ./create-replication-user.sh + fi - cd /var/lib/mysql - # Determine binlog position of cloned data, if any. - if [[ -f xtrabackup_slave_info ]]; then - # XtraBackup already generated a partial "CHANGE MASTER TO" query - # because we're cloning from an existing slave. - cp xtrabackup_slave_info change_master_to.sql.in - elif [[ -f xtrabackup_binlog_info ]]; then - # We're cloning directly from master. Parse binlog position. - [[ $(cat xtrabackup_binlog_info) =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1 - echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\ - MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in - fi + cd /var/lib/mysql + # Determine binlog position of cloned data, if any. + if [[ -f xtrabackup_slave_info ]]; then + # XtraBackup already generated a partial "CHANGE MASTER TO" query + # because we're cloning from an existing slave. + cp xtrabackup_slave_info change_master_to.sql.in + elif [[ -f xtrabackup_binlog_info ]]; then + # We're cloning directly from master. Parse binlog position. + [[ $(cat xtrabackup_binlog_info) =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1 + echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\ + MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in + fi - # Check if we need to complete a clone by starting replication. - if [[ -f change_master_to.sql.in ]]; then + # Check if we need to complete a clone by starting replication. + if [[ -f change_master_to.sql.in ]]; then - # In case of container restart, attempt this at-most-once. - cp change_master_to.sql.in change_master_to.sql.orig - mysql -h 127.0.0.1 --verbose<