Skip to content

Commit

Permalink
fix: pg cluster connect fail (#5862)
Browse files Browse the repository at this point in the history
  • Loading branch information
1aal authored Nov 18, 2023
1 parent 97bb6c1 commit 2fff161
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/lorry/engines/foxlake/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string {
userPass = connectInfo.UserPasswd
}

foxlakeCmd := []string{fmt.Sprintf("%s mysql://%s:%s@:${serverPort}", r.info.Client, userName, userPass)}
foxlakeCmd := []string{fmt.Sprintf("%s %s", r.info.Client, engines.AddSingleQuote(fmt.Sprintf("mysql://%s:%s@:${serverPort}", userName, userPass)))}

return []string{"sh", "-c", strings.Join(foxlakeCmd, " ")}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/lorry/engines/mongodb/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string {
userPass = connectInfo.UserPasswd
}

mongodbCmd := []string{fmt.Sprintf("export CLIENT=`which mongosh>/dev/null&&echo %s||echo mongo`; $CLIENT mongodb://%s:%s@$KB_POD_FQDN:27017/admin?replicaSet=$KB_CLUSTER_COMP_NAME", r.info.Client, userName, userPass)}
mongodbCmd := []string{fmt.Sprintf("export CLIENT=`which mongosh>/dev/null&&echo %s||echo mongo`; $CLIENT %s", r.info.Client, engines.AddSingleQuote(fmt.Sprintf("mongodb://%s:%s@$KB_POD_FQDN:27017/admin?replicaSet=$KB_CLUSTER_COMP_NAME", userName, userPass)))}

return []string{"sh", "-c", strings.Join(mongodbCmd, " ")}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/lorry/engines/mysql/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (m *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string {
// MYSQL_PWD is deprecated as of MySQL 8.0; expect it to be removed in a future version of MySQL.
// ref to mysql manual for more details.
// https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html
mysqlCmd := []string{fmt.Sprintf("%s -u%s -p%s", m.info.Client, userName, userPass)}
mysqlCmd := []string{fmt.Sprintf("%s -u%s -p%s", m.info.Client, engines.AddSingleQuote(userName), engines.AddSingleQuote(userPass))}

return []string{"sh", "-c", strings.Join(mysqlCmd, " ")}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/lorry/engines/nebula/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string {
userPass = connectInfo.UserPasswd
}

nebulaCmd := []string{fmt.Sprintf("%s --addr $GRAPHD_SVC_NAME --port $GRAPHD_SVC_PORT --user %s --password %s", r.info.Client, userName, userPass)}
nebulaCmd := []string{fmt.Sprintf("%s --addr $GRAPHD_SVC_NAME --port $GRAPHD_SVC_PORT --user %s --password %s", r.info.Client, userName, engines.AddSingleQuote(userPass))}

return []string{"sh", "-c", strings.Join(nebulaCmd, " ")}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/lorry/engines/oceanbase/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string {
var obCmd []string

if userPass != "" {
obCmd = []string{fmt.Sprintf("%s -h127.0.0.1 -P2881 -u%s -A -p%s", r.info.Client, userName, userPass)}
obCmd = []string{fmt.Sprintf("%s -h127.0.0.1 -P2881 -u%s -A -p%s", r.info.Client, userName, engines.AddSingleQuote(userPass))}
} else {
obCmd = []string{fmt.Sprintf("%s -h127.0.0.1 -P2881 -u%s -A", r.info.Client, userName)}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/lorry/engines/postgres/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (m *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string {

// please refer to PostgreSQL documentation for more details
// https://www.postgresql.org/docs/current/libpq-envars.html
cmd := []string{fmt.Sprintf("PGUSER=%s PGPASSWORD=%s PGDATABASE=%s %s", userName, userPass, m.info.Database, m.info.Client)}
cmd := []string{fmt.Sprintf("PGUSER=%s PGPASSWORD=%s PGDATABASE=%s %s", engines.AddSingleQuote(userName), engines.AddSingleQuote(userPass), m.info.Database, m.info.Client)}
return []string{"sh", "-c", strings.Join(cmd, " ")}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/lorry/engines/redis/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (r Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string {
}

if connectInfo != nil {
redisCmd = append(redisCmd, "--user", connectInfo.UserName)
redisCmd = append(redisCmd, "--pass", connectInfo.UserPasswd)
redisCmd = append(redisCmd, "--user", engines.AddSingleQuote(connectInfo.UserName))
redisCmd = append(redisCmd, "--pass", engines.AddSingleQuote(connectInfo.UserPasswd))
}
return []string{"sh", "-c", strings.Join(redisCmd, " ")}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/lorry/engines/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ func GetIndex(memberName string) (int, error) {
return strconv.Atoi(memberName[i+1:])
}

func AddSingleQuote(str string) string {
return "'" + str + "'"
}

type Properties map[string]string

0 comments on commit 2fff161

Please sign in to comment.