@@ -38,8 +38,6 @@ type Config struct {
3838 ServiceName string
3939 // The name of the statefulset.
4040 StatefulSetName string
41- // Replicas is the number of pods.
42- Replicas int32
4341
4442 // The password of the root user.
4543 RootPassword string
@@ -134,13 +132,6 @@ func NewInitConfig() *Config {
134132 }
135133 }
136134
137- replicaStr := getEnvValue ("REPLICAS" )
138- replicas , err := strconv .ParseInt (replicaStr , 10 , 32 )
139- if err != nil {
140- log .Error (err , "invalid environment values" , "REPLICAS" , replicaStr )
141- panic (err )
142- }
143-
144135 initTokuDB := false
145136 if len (getEnvValue ("INIT_TOKUDB" )) > 0 {
146137 initTokuDB = true
@@ -162,7 +153,6 @@ func NewInitConfig() *Config {
162153 NameSpace : getEnvValue ("NAMESPACE" ),
163154 ServiceName : getEnvValue ("SERVICE_NAME" ),
164155 StatefulSetName : getEnvValue ("STATEFULSET_NAME" ),
165- Replicas : int32 (replicas ),
166156
167157 RootPassword : getEnvValue ("MYSQL_ROOT_PASSWORD" ),
168158 InternalRootPassword : getEnvValue ("INTERNAL_ROOT_PASSWORD" ),
@@ -198,17 +188,9 @@ func NewInitConfig() *Config {
198188
199189// NewBackupConfig returns the configuration file needed for backup container.
200190func NewBackupConfig () * Config {
201- replicaStr := getEnvValue ("REPLICAS" )
202- replicas , err := strconv .ParseInt (replicaStr , 10 , 32 )
203- if err != nil {
204- log .Error (err , "invalid environment values" , "REPLICAS" , replicaStr )
205- panic (err )
206- }
207-
208191 return & Config {
209192 NameSpace : getEnvValue ("NAMESPACE" ),
210193 ServiceName : getEnvValue ("SERVICE_NAME" ),
211- Replicas : int32 (replicas ),
212194 ClusterName : getEnvValue ("SERVICE_NAME" ),
213195 RootPassword : getEnvValue ("MYSQL_ROOT_PASSWORD" ),
214196
@@ -224,17 +206,9 @@ func NewBackupConfig() *Config {
224206
225207// NewReqBackupConfig returns the configuration file needed for backup job.
226208func NewReqBackupConfig () * Config {
227- replicaStr := getEnvValue ("REPLICAS" )
228- replicas , err := strconv .ParseInt (replicaStr , 10 , 32 )
229- if err != nil {
230- log .Error (err , "invalid environment values" , "REPLICAS" , replicaStr )
231- panic (err )
232- }
233-
234209 return & Config {
235210 NameSpace : getEnvValue ("NAMESPACE" ),
236211 ServiceName : getEnvValue ("SERVICE_NAME" ),
237- Replicas : int32 (replicas ),
238212
239213 BackupUser : getEnvValue ("BACKUP_USER" ),
240214 BackupPassword : getEnvValue ("BACKUP_PASSWORD" ),
@@ -418,111 +392,6 @@ func (cfg *Config) buildClientConfig() (*ini.File, error) {
418392 return conf , nil
419393}
420394
421- func (cfg * Config ) buildPostStart () ([]byte , error ) {
422- ordinal , err := utils .GetOrdinal (cfg .HostName )
423- if err != nil {
424- return nil , err
425- }
426-
427- nums := ordinal
428- if cfg .existMySQLData {
429- nums = int (cfg .Replicas )
430- }
431-
432- host := fmt .Sprintf ("%s.%s.%s" , cfg .HostName , cfg .ServiceName , cfg .NameSpace )
433-
434- str := fmt .Sprintf (`#!/bin/sh
435- while true; do
436- info=$(curl -i -X GET -u root:%s http://%s:%d/v1/xenon/ping)
437- code=$(echo $info|grep "HTTP"|awk '{print $2}')
438- if [ "$code" -eq "200" ]; then
439- break
440- fi
441- done
442- ` , cfg .RootPassword , host , utils .XenonPeerPort )
443-
444- if ! cfg .existMySQLData && ordinal == 0 {
445- str = fmt .Sprintf (`%s
446- for i in $(seq 12); do
447- curl -i -X POST -u root:%s http://%s:%d/v1/raft/trytoleader
448- sleep 5
449- curl -i -X GET -u root:%s http://%s:%d/v1/raft/status | grep LEADER
450- if [ $? -eq 0 ] ; then
451- echo "trytoleader success"
452- break
453- fi
454- if [ $i -eq 12 ]; then
455- echo "wait trytoleader failed"
456- fi
457- done
458- ` , str , cfg .RootPassword , host , utils .XenonPeerPort , cfg .RootPassword , host , utils .XenonPeerPort )
459- } else {
460- str = fmt .Sprintf (`%s
461- i=0
462- while [ $i -lt %d ]; do
463- if [ $i -ne %d ]; then
464- for k in $(seq 12); do
465- res=$(curl -i -X POST -d '{"address": "%s-'$i'.%s.%s:%d"}' -u root:%s http://%s:%d/v1/cluster/add)
466- code=$(echo $res|grep "HTTP"|awk '{print $2}')
467- if [ "$code" -eq "200" ]; then
468- break
469- fi
470- done
471-
472- for k in $(seq 12); do
473- res=$(curl -i -X POST -d '{"address": "%s:%d"}' -u root:%s http://%s-$i.%s.%s:%d/v1/cluster/add)
474- code=$(echo $res|grep "HTTP"|awk '{print $2}')
475- if [ "$code" -eq "200" ]; then
476- break
477- fi
478- done
479- fi
480- i=$((i+1))
481- done
482- ` , str , nums , ordinal , cfg .StatefulSetName , cfg .ServiceName , cfg .NameSpace , utils .XenonPort ,
483- cfg .RootPassword , host , utils .XenonPeerPort , host , utils .XenonPort , cfg .RootPassword ,
484- cfg .StatefulSetName , cfg .ServiceName , cfg .NameSpace , utils .XenonPeerPort )
485- }
486-
487- return utils .StringToBytes (str ), nil
488- }
489-
490- func (cfg * Config ) buildPreStop () []byte {
491- host := fmt .Sprintf ("%s.%s.%s" , cfg .HostName , cfg .ServiceName , cfg .NameSpace )
492-
493- str := fmt .Sprintf (`#!/bin/sh
494- while true; do
495- info=$(curl -i -X GET -u root:%s http://%s:%d/v1/xenon/ping)
496- code=$(echo $info|grep "HTTP"|awk '{print $2}')
497- if [ "$code" -eq "200" ]; then
498- break
499- fi
500- done
501-
502- curl -i -X PUT -u root:%s http://%s:%d/v1/raft/disable
503- for line in $(curl -X GET -u root:%s http://%s:%d/v1/raft/status | jq -r .nodes[] | cut -d : -f 1)
504- do
505- if [ "$line" != "%s" ]; then
506- for i in $(seq 12); do
507- info=$(curl -i -X POST -d '{"address": "%s:%d"}' -u root:%s http://$line:%d/v1/cluster/remove)
508- code=$(echo $info|grep "HTTP"|awk '{print $2}')
509- if [ "$code" -eq "200" ]; then
510- break
511- fi
512- if [ $i -eq 12 ]; then
513- echo "remove node failed"
514- break
515- fi
516- sleep 5
517- done
518- fi
519- done
520- ` , cfg .RootPassword , host , utils .XenonPeerPort , cfg .RootPassword , host , utils .XenonPeerPort , cfg .RootPassword ,
521- host , utils .XenonPeerPort , host , host , utils .XenonPort , cfg .RootPassword , utils .XenonPeerPort )
522-
523- return utils .StringToBytes (str )
524- }
525-
526395// buildLeaderStart build the leader-start.sh.
527396func (cfg * Config ) buildLeaderStart () []byte {
528397 str := fmt .Sprintf (`#!/usr/bin/env bash
0 commit comments