Skip to content

Commit

Permalink
fix(dbm-services): deal mysql5.5 auth plugin #8151
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Nov 25, 2024
1 parent 2700a73 commit 8d76d03
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
35 changes: 20 additions & 15 deletions dbm-services/mysql/db-simulation/app/service/kubernets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
Expand Down Expand Up @@ -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",
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion dbm-services/mysql/db-simulation/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8d76d03

Please sign in to comment.