Skip to content

Commit c03590e

Browse files
committed
*: Remove the reference to the Replicas in the containers.
1 parent 53edf42 commit c03590e

File tree

7 files changed

+3
-190
lines changed

7 files changed

+3
-190
lines changed

mysqlcluster/container/backup.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package container
1818

1919
import (
20-
"fmt"
21-
2220
corev1 "k8s.io/api/core/v1"
2321
"k8s.io/apimachinery/pkg/util/intstr"
2422

@@ -59,10 +57,6 @@ func (c *backupSidecar) getEnvVars() []corev1.EnvVar {
5957
Name: "SERVICE_NAME",
6058
Value: c.GetNameForResource(utils.HeadlessSVC),
6159
},
62-
{
63-
Name: "REPLICAS",
64-
Value: fmt.Sprintf("%d", *c.Spec.Replicas),
65-
},
6660
{
6761
Name: "MYSQL_ROOT_PASSWORD",
6862
Value: c.Spec.MysqlOpts.RootPassword,

mysqlcluster/container/init_sidecar.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package container
1818

1919
import (
20-
"fmt"
2120
"strconv"
2221

2322
corev1 "k8s.io/api/core/v1"
@@ -79,10 +78,6 @@ func (c *initSidecar) getEnvVars() []corev1.EnvVar {
7978
Name: "STATEFULSET_NAME",
8079
Value: c.GetNameForResource(utils.StatefulSet),
8180
},
82-
{
83-
Name: "REPLICAS",
84-
Value: fmt.Sprintf("%d", *c.Spec.Replicas),
85-
},
8681
{
8782
Name: "ADMIT_DEFEAT_HEARBEAT_COUNT",
8883
Value: strconv.Itoa(int(*c.Spec.XenonOpts.AdmitDefeatHearbeatCount)),

mysqlcluster/container/init_sidecar_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package container
1818

1919
import (
20-
"fmt"
2120
"strconv"
2221
"testing"
2322

@@ -92,10 +91,6 @@ var (
9291
Name: "STATEFULSET_NAME",
9392
Value: "sample-mysql",
9493
},
95-
{
96-
Name: "REPLICAS",
97-
Value: fmt.Sprintf("%d", *testInitSidecarCluster.Spec.Replicas),
98-
},
9994
{
10095
Name: "ADMIT_DEFEAT_HEARBEAT_COUNT",
10196
Value: strconv.Itoa(int(*testInitSidecarCluster.Spec.XenonOpts.AdmitDefeatHearbeatCount)),

mysqlcluster/container/xenon.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,7 @@ func (c *xenon) getEnvVars() []corev1.EnvVar {
5353

5454
// getLifecycle get the container lifecycle.
5555
func (c *xenon) getLifecycle() *corev1.Lifecycle {
56-
return &corev1.Lifecycle{
57-
PostStart: &corev1.Handler{
58-
Exec: &corev1.ExecAction{
59-
Command: []string{"sh", "-c", "/scripts/post-start.sh"},
60-
},
61-
},
62-
PreStop: &corev1.Handler{
63-
Exec: &corev1.ExecAction{
64-
Command: []string{"sh", "-c", "/scripts/pre-stop.sh"},
65-
},
66-
},
67-
}
56+
return nil
6857
}
6958

7059
// getResources get the container resources.

mysqlcluster/container/xenon_test.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
var (
31-
xenonReplicas int32 = 1
31+
xenonReplicas int32 = 3
3232
xenonMysqlCluster = mysqlv1alpha1.MysqlCluster{
3333
ObjectMeta: metav1.ObjectMeta{
3434
Name: "sample",
@@ -70,19 +70,7 @@ func TestGetXenonEnvVar(t *testing.T) {
7070
}
7171

7272
func TestGetXenonLifecycle(t *testing.T) {
73-
lifecycle := &corev1.Lifecycle{
74-
PostStart: &corev1.Handler{
75-
Exec: &corev1.ExecAction{
76-
Command: []string{"sh", "-c", "/scripts/post-start.sh"},
77-
},
78-
},
79-
PreStop: &corev1.Handler{
80-
Exec: &corev1.ExecAction{
81-
Command: []string{"sh", "-c", "/scripts/pre-stop.sh"},
82-
},
83-
},
84-
}
85-
assert.Equal(t, lifecycle, xenonCase.Lifecycle)
73+
assert.Nil(t, xenonCase.Lifecycle)
8674
}
8775

8876
func TestGetXenonResources(t *testing.T) {

sidecar/config.go

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
200190
func 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.
226208
func 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.
527396
func (cfg *Config) buildLeaderStart() []byte {
528397
str := fmt.Sprintf(`#!/usr/bin/env bash

sidecar/init.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,6 @@ func runInitCommand(cfg *Config) error {
115115
return fmt.Errorf("failed to save extra.cnf: %s", err)
116116
}
117117

118-
// build post-start.sh.
119-
bashPostStartPath := path.Join(scriptsPath, "post-start.sh")
120-
bashPostStart, err := cfg.buildPostStart()
121-
if err != nil {
122-
return fmt.Errorf("failed to build post-start.sh: %s", err)
123-
}
124-
if err = ioutil.WriteFile(bashPostStartPath, bashPostStart, os.FileMode(0755)); err != nil {
125-
return fmt.Errorf("failed to write post-start.sh: %s", err)
126-
}
127-
128-
// build pre-stop.sh.
129-
bashPreStopPath := path.Join(scriptsPath, "pre-stop.sh")
130-
bashPreStop := cfg.buildPreStop()
131-
if err = ioutil.WriteFile(bashPreStopPath, bashPreStop, os.FileMode(0755)); err != nil {
132-
return fmt.Errorf("failed to write pre-stop.sh: %s", err)
133-
}
134-
135118
// build leader-start.sh.
136119
bashLeaderStart := cfg.buildLeaderStart()
137120
leaderStartPath := path.Join(scriptsPath, "leader-start.sh")

0 commit comments

Comments
 (0)