From 38f3969492394e4a88e25f73510d6a1ec6e0b577 Mon Sep 17 00:00:00 2001 From: zhyass <34016424+zhyass@users.noreply.github.com> Date: Mon, 19 Jul 2021 14:56:25 +0800 Subject: [PATCH] cluster/container: update test case --- cluster/container/init_mysql_test.go | 42 +--------------------- cluster/container/init_sidecar_test.go | 49 +++++++++++++++++++++++++- cluster/container/mysql_test.go | 11 ++---- cluster/container/xenon_test.go | 9 +++-- 4 files changed, 58 insertions(+), 53 deletions(-) diff --git a/cluster/container/init_mysql_test.go b/cluster/container/init_mysql_test.go index 8510a7077..d9f9e97aa 100644 --- a/cluster/container/init_mysql_test.go +++ b/cluster/container/init_mysql_test.go @@ -42,6 +42,7 @@ var ( }, MysqlVersion: "5.7", MysqlOpts: mysqlv1alpha1.MysqlOpts{ + RootHost: "127.0.0.1", InitTokuDB: false, }, }, @@ -54,11 +55,6 @@ var ( Name: utils.ConfVolumeName, MountPath: utils.ConfVolumeMountPath, }, - { - Name: utils.ConfMapVolumeName, - MountPath: utils.MyCnfMountPath, - SubPath: "my.cnf", - }, { Name: utils.DataVolumeName, MountPath: utils.DataVolumeMountPath, @@ -100,42 +96,6 @@ var ( }, }, }, - { - Name: "MYSQL_DATABASE", - ValueFrom: &corev1.EnvVarSource{ - SecretKeyRef: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: sctName, - }, - Key: "mysql-database", - Optional: &optTrue, - }, - }, - }, - { - Name: "MYSQL_USER", - ValueFrom: &corev1.EnvVarSource{ - SecretKeyRef: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: sctName, - }, - Key: "mysql-user", - Optional: &optTrue, - }, - }, - }, - { - Name: "MYSQL_PASSWORD", - ValueFrom: &corev1.EnvVarSource{ - SecretKeyRef: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: sctName, - }, - Key: "mysql-password", - Optional: &optTrue, - }, - }, - }, } initMysqlCase = EnsureContainer("init-mysql", &testInitMysqlCluster) ) diff --git a/cluster/container/init_sidecar_test.go b/cluster/container/init_sidecar_test.go index fff66d090..52d961f09 100644 --- a/cluster/container/init_sidecar_test.go +++ b/cluster/container/init_sidecar_test.go @@ -17,6 +17,7 @@ limitations under the License. package container import ( + "fmt" "strconv" "testing" @@ -32,11 +33,13 @@ import ( var ( defeatCount int32 = 1 electionTimeout int32 = 5 + replicas int32 = 3 initSidecarMysqlCluster = mysqlv1alpha1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "sample", }, Spec: mysqlv1alpha1.ClusterSpec{ + Replicas: &replicas, PodSpec: mysqlv1alpha1.PodSpec{ SidecarImage: "sidecar image", Resources: corev1.ResourceRequirements{ @@ -80,6 +83,14 @@ var ( Name: "SERVICE_NAME", Value: "sample-mysql", }, + { + Name: "STATEFULSET_NAME", + Value: "sample-mysql", + }, + { + Name: "REPLICAS", + Value: fmt.Sprintf("%d", *testInitSidecarCluster.Spec.Replicas), + }, { Name: "ADMIT_DEFEAT_HEARBEAT_COUNT", Value: strconv.Itoa(int(*testInitSidecarCluster.Spec.XenonOpts.AdmitDefeatHearbeatCount)), @@ -104,6 +115,42 @@ var ( }, }, }, + { + Name: "MYSQL_DATABASE", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: sctName, + }, + Key: "mysql-database", + Optional: &optTrue, + }, + }, + }, + { + Name: "MYSQL_USER", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: sctName, + }, + Key: "mysql-user", + Optional: &optTrue, + }, + }, + }, + { + Name: "MYSQL_PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: sctName, + }, + Key: "mysql-password", + Optional: &optTrue, + }, + }, + }, { Name: "MYSQL_REPL_USER", ValueFrom: &corev1.EnvVarSource{ @@ -228,7 +275,7 @@ func TestGetInitSidecarEnvVar(t *testing.T) { Cluster: &testToKuDBMysqlCluster, } tokudbCase := EnsureContainer("init-sidecar", &testTokuDBCluster) - testTokuDBEnv := make([]corev1.EnvVar, 13) + testTokuDBEnv := make([]corev1.EnvVar, 18) copy(testTokuDBEnv, defaultInitSidecarEnvs) testTokuDBEnv = append(testTokuDBEnv, corev1.EnvVar{ Name: "INIT_TOKUDB", diff --git a/cluster/container/mysql_test.go b/cluster/container/mysql_test.go index d0b0f92d7..d4f03c19e 100644 --- a/cluster/container/mysql_test.go +++ b/cluster/container/mysql_test.go @@ -107,7 +107,7 @@ func TestGetMysqlLivenessProbe(t *testing.T) { livenessProbe := &corev1.Probe{ Handler: corev1.Handler{ Exec: &corev1.ExecAction{ - Command: []string{"sh", "-c", "mysqladmin ping -uroot -p${MYSQL_ROOT_PASSWORD}"}, + Command: []string{"sh", "-c", "mysqladmin --defaults-file=/etc/mysql/client.conf ping"}, }, }, InitialDelaySeconds: 30, @@ -123,7 +123,7 @@ func TestGetMysqlReadinessProbe(t *testing.T) { readinessProbe := &corev1.Probe{ Handler: corev1.Handler{ Exec: &corev1.ExecAction{ - Command: []string{"sh", "-c", `mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "SELECT 1"`}, + Command: []string{"sh", "-c", `test $(mysql --defaults-file=/etc/mysql/client.conf -NB -e "SELECT 1") -eq 1`}, }, }, InitialDelaySeconds: 10, @@ -139,12 +139,7 @@ func TestGetMysqlVolumeMounts(t *testing.T) { volumeMounts := []corev1.VolumeMount{ { Name: "conf", - MountPath: "/etc/mysql/conf.d", - }, - { - Name: "config-map", - MountPath: "/etc/mysql/my.cnf", - SubPath: "my.cnf", + MountPath: "/etc/mysql", }, { Name: "data", diff --git a/cluster/container/xenon_test.go b/cluster/container/xenon_test.go index cd049f96f..a262e5c28 100644 --- a/cluster/container/xenon_test.go +++ b/cluster/container/xenon_test.go @@ -73,9 +73,12 @@ func TestGetXenonLifecycle(t *testing.T) { lifecycle := &corev1.Lifecycle{ PostStart: &corev1.Handler{ Exec: &corev1.ExecAction{ - Command: []string{"sh", "-c", - "until (xenoncli xenon ping && xenoncli cluster add sample-mysql-0.sample-mysql.default:8801) > /dev/null 2>&1; do sleep 2; done", - }, + Command: []string{"sh", "-c", "/scripts/post-start.sh"}, + }, + }, + PreStop: &corev1.Handler{ + Exec: &corev1.ExecAction{ + Command: []string{"sh", "-c", "/scripts/pre-stop.sh"}, }, }, }