1 # Copyright © 2017 Amdocs, Bell Canada
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 #{{ if not .Values.disableSdncSdncDbhost }}
16 apiVersion: apps/v1beta1
20 namespace: "{{ .Values.nsPrefix }}"
23 replicas: {{ .Values.numberOfDbReplicas }}
35 image: {{ .Values.image.mysql }}
36 imagePullPolicy: {{ .Values.pullPolicy }}
42 # Generate mysql server-id from pod ordinal index.
43 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
44 ordinal=${BASH_REMATCH[1]}
45 echo BASH_REMATCH=${BASH_REMATCH}
46 echo [mysqld] > /mnt/conf.d/server-id.cnf
47 # Add an offset to avoid reserved server-id=0 value.
48 echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
49 # Copy appropriate conf.d files from config-map to emptyDir.
50 if [[ $ordinal -eq 0 ]]; then
51 cp /mnt/config-map/master.cnf /mnt/conf.d/
53 cp /mnt/config-map/slave.cnf /mnt/conf.d/
57 mountPath: /mnt/conf.d
59 mountPath: /mnt/config-map
61 image: {{ .Values.image.xtrabackup }}
63 - name: MYSQL_ROOT_PASSWORD
70 # Skip the clone if data already exists.
71 [[ -d /var/lib/mysql/mysql ]] && exit 0
72 # Skip the clone on master (ordinal index 0).
73 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
74 ordinal=${BASH_REMATCH[1]}
76 [[ $ordinal -eq 0 ]] && exit 0
77 # Clone data from previous peer.
78 ncat --recv-only sdnc-dbhost-$(($ordinal-1)).dbhost.{{ .Values.nsPrefix }} 3307 | xbstream -x -C /var/lib/mysql
80 xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --prepare --target-dir=/var/lib/mysql
84 mountPath: /var/lib/mysql
87 mountPath: /etc/mysql/conf.d
90 - name: MYSQL_ROOT_PASSWORD
92 - name: MYSQL_ROOT_HOST
94 - name: MYSQL_ALLOW_EMPTY_PASSWORD
96 image: {{ .Values.image.mysql }}
97 imagePullPolicy: {{ .Values.pullPolicy }}
98 name: sdnc-db-container
100 - mountPath: /var/lib/mysql
104 mountPath: /etc/mysql/conf.d
106 - containerPort: 3306
113 command: ["mysqladmin", "ping"]
114 initialDelaySeconds: 30
120 initialDelaySeconds: 5
123 image: {{ .Values.image.xtrabackup }}
125 - name: MYSQL_ROOT_PASSWORD
137 # Determine binlog position of cloned data, if any.
138 if [[ -f xtrabackup_slave_info ]]; then
139 echo "Inside xtrabackup_slave_info"
140 # XtraBackup already generated a partial "CHANGE MASTER TO" query
141 # because we're cloning from an existing slave.
142 mv xtrabackup_slave_info change_master_to.sql.in
143 # Ignore xtrabackup_binlog_info in this case (it's useless).
144 rm -f xtrabackup_binlog_info
145 elif [[ -f xtrabackup_binlog_info ]]; then
146 echo "Inside xtrabackup_binlog_info"
147 # We're cloning directly from master. Parse binlog position.
148 [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
149 rm xtrabackup_binlog_info
150 echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\
151 MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in
154 # Check if we need to complete a clone by starting replication.
155 if [[ -f change_master_to.sql.in ]]; then
156 echo "Waiting for mysqld to be ready (accepting connections)"
157 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
158 ordinal=${BASH_REMATCH[1]}
160 until mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done
162 echo "Initializing replication from clone position"
163 # In case of container restart, attempt this at-most-once.
164 mv change_master_to.sql.in change_master_to.sql.orig
165 mysql --user=root --password=$MYSQL_ROOT_PASSWORD -h 127.0.0.1 <<EOF
166 $(<change_master_to.sql.orig),
167 MASTER_HOST="sdnc-dbhost-0.dbhost.{{ .Values.nsPrefix }}",
169 MASTER_PASSWORD="$MYSQL_ROOT_PASSWORD",
170 MASTER_CONNECT_RETRY=10;
175 # Start a server to send backups when requested by peers.
176 exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \
177 "xtrabackup --user=root --password=$MYSQL_ROOT_PASSWORD --backup --slave-info --stream=xbstream --host=127.0.0.1"
180 mountPath: /var/lib/mysql
183 mountPath: /etc/mysql/conf.d
197 #{{ if .Values.disableNfsProvisioner }}
200 path: /dockerdata-nfs/{{ .Values.nsPrefix }}/sdnc/data
202 volumeClaimTemplates:
206 volume.beta.kubernetes.io/storage-class: "{{ .Values.nsPrefix }}-sdnc-data"
208 accessModes: ["ReadWriteMany"]