From be7f04742520f978496727dcf1c2aac3138d3752 Mon Sep 17 00:00:00 2001 From: yuanruji Date: Mon, 25 Nov 2024 16:28:10 +0800 Subject: [PATCH] fix(dbm-services): deal mysql5.5 auth plugin #8151 --- .../db-simulation/app/service/kubernets.go | 35 +++++++++++-------- .../app/service/kubernets_test.go | 2 +- .../app/service/simulation_task.go | 4 +-- .../mysql/db-simulation/handler/handler.go | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/dbm-services/mysql/db-simulation/app/service/kubernets.go b/dbm-services/mysql/db-simulation/app/service/kubernets.go index b4cbf974a2..dc5e94b26e 100644 --- a/dbm-services/mysql/db-simulation/app/service/kubernets.go +++ b/dbm-services/mysql/db-simulation/app/service/kubernets.go @@ -121,7 +121,19 @@ func (k *DbPodSets) getCreateClusterSqls() []string { // getClusterPodContanierSpec create cluster pod container spec // nolint -func (k *DbPodSets) getClusterPodContanierSpec() []v1.Container { +func (k *DbPodSets) getClusterPodContanierSpec(mysqlVersion string) []v1.Container { + mysqldStartArgs := []string{"mysqld", + "--defaults-file=/etc/my.cnf", + "--log_bin_trust_function_creators", + "--port=20000", + "--max_allowed_packet=1073741824", + "--sql-mode=", + fmt.Sprintf("--character-set-server=%s", + k.BaseInfo.Charset), + "--user=mysql"} + if cmutil.MySQLVersionParse(mysqlVersion) >= cmutil.MySQLVersionParse("8.0.0") { + mysqldStartArgs = append(mysqldStartArgs, "--default-authentication-plugin=mysql_native_password") + } return []v1.Container{ { Name: "backend", @@ -132,16 +144,7 @@ func (k *DbPodSets) getClusterPodContanierSpec() []v1.Container { Resources: k.getResourceLimit(), ImagePullPolicy: v1.PullIfNotPresent, Image: k.DbImage, - Args: []string{"mysqld", - "--defaults-file=/etc/my.cnf", - "--log_bin_trust_function_creators", - "--port=20000", - "--max_allowed_packet=1073741824", - "--default-authentication-plugin=mysql_native_password", - "--sql-mode=", - fmt.Sprintf("--character-set-server=%s", - k.BaseInfo.Charset), - "--user=mysql"}, + Args: mysqldStartArgs, ReadinessProbe: &v1.Probe{ ProbeHandler: v1.ProbeHandler{ Exec: &v1.ExecAction{ @@ -206,7 +209,7 @@ func (k *DbPodSets) getClusterPodContanierSpec() []v1.Container { } // CreateClusterPod create tendbcluster simulation pod -func (k *DbPodSets) CreateClusterPod() (err error) { +func (k *DbPodSets) CreateClusterPod(mySQLVersion string) (err error) { c := &v1.Pod{ TypeMeta: metav1.TypeMeta{ Kind: "Pod", @@ -223,7 +226,7 @@ func (k *DbPodSets) CreateClusterPod() (err error) { item.Value }), Tolerations: k.getToleration(), - Containers: k.getClusterPodContanierSpec(), + Containers: k.getClusterPodContanierSpec(mySQLVersion), }, } if err = k.createpod(c, 26000); err != nil { @@ -354,13 +357,15 @@ func (k *DbPodSets) gettdbctlResourceLimit() v1.ResourceRequirements { } // CreateMySQLPod create mysql pod -func (k *DbPodSets) CreateMySQLPod() (err error) { +func (k *DbPodSets) CreateMySQLPod(mysqlVersion string) (err error) { startArgs := []string{ "--defaults-file=/etc/my.cnf", "--skip-log-bin", "--max_allowed_packet=1073741824", - "--default-authentication-plugin=mysql_native_password", fmt.Sprintf("--character-set-server=%s", k.BaseInfo.Charset)} + if cmutil.MySQLVersionParse(mysqlVersion) >= cmutil.MySQLVersionParse("8.0.0") { + startArgs = append(startArgs, "--default-authentication-plugin=mysql_native_password") + } startArgs = append(startArgs, k.BaseInfo.Args...) startArgs = append(startArgs, "--user=mysql") logger.Info("start pod args %v", startArgs) diff --git a/dbm-services/mysql/db-simulation/app/service/kubernets_test.go b/dbm-services/mysql/db-simulation/app/service/kubernets_test.go index 3df549628e..96e0067ed5 100644 --- a/dbm-services/mysql/db-simulation/app/service/kubernets_test.go +++ b/dbm-services/mysql/db-simulation/app/service/kubernets_test.go @@ -17,7 +17,7 @@ func TestCreateClusterPod(t *testing.T) { ps.DbImage = config.GAppConfig.Image.Tendb57Img ps.TdbCtlImage = config.GAppConfig.Image.TdbCtlImg ps.SpiderImage = config.GAppConfig.Image.SpiderImg - if err := ps.CreateClusterPod(); err != nil { + if err := ps.CreateClusterPod(""); err != nil { t.Fatalf("%s", err.Error()) return } diff --git a/dbm-services/mysql/db-simulation/app/service/simulation_task.go b/dbm-services/mysql/db-simulation/app/service/simulation_task.go index ad1c88f3ce..f1f7f9d1cd 100644 --- a/dbm-services/mysql/db-simulation/app/service/simulation_task.go +++ b/dbm-services/mysql/db-simulation/app/service/simulation_task.go @@ -180,9 +180,9 @@ func run(task SimulationTask, tkType string) { func createPod(task SimulationTask, tkType string) (err error) { switch tkType { case app.MySQL: - return task.CreateMySQLPod() + return task.CreateMySQLPod(task.BaseParam.MySQLVersion) case app.TdbCtl: - return task.DbPodSets.CreateClusterPod() + return task.DbPodSets.CreateClusterPod(task.BaseParam.MySQLVersion) } return } diff --git a/dbm-services/mysql/db-simulation/handler/handler.go b/dbm-services/mysql/db-simulation/handler/handler.go index b237a2c8b5..71f8a26d58 100644 --- a/dbm-services/mysql/db-simulation/handler/handler.go +++ b/dbm-services/mysql/db-simulation/handler/handler.go @@ -63,7 +63,7 @@ func CreateTmpSpiderPodCluster(r *gin.Context) { return } ps.SpiderImage, ps.TdbCtlImage = getSpiderAndTdbctlImg(param.SpiderVersion, LatestVersion) - if err := ps.CreateClusterPod(); err != nil { + if err := ps.CreateClusterPod("MySQL-5.7"); err != nil { logger.Error(err.Error()) return }