Skip to content

Commit

Permalink
Get dbUser from Env or default('root') (kubeflow#985)
Browse files Browse the repository at this point in the history
* Get dbUser from Env or default('root')

* Get dbUser from Env or default('root')
  • Loading branch information
UrmsOne authored and k8s-ci-robot committed Dec 27, 2019
1 parent 133845a commit 3e9c9db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkg/db/v1alpha3/common/const.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package common

const (
DBUserEnvName = "DB_USER"

DBNameEnvName = "DB_NAME"

MySqlDBNameEnvValue = "mysql"
Expand All @@ -11,6 +13,7 @@ const (
MySQLDBPortEnvName = "KATIB_MYSQL_PORT"
MySQLDatabase = "KATIB_MYSQL_DATABASE"

DefaultMySQLUser = "root"
DefaultMySQLDatabase = "katib"
DefaultMySQLHost = "katib-db"
DefaultMySQLPort = "3306"
Expand Down
9 changes: 6 additions & 3 deletions pkg/db/v1alpha3/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
)

const (
dbDriver = "mysql"
dbNameTmpl = "root:%s@tcp(%s:%s)/%s?timeout=5s"
dbDriver = "mysql"
//dbNameTmpl = "root:%s@tcp(%s:%s)/%s?timeout=5s"
dbNameTmpl = "%s:%s@tcp(%s:%s)/%s?timeout=5s"
mysqlTimeFmt = "2006-01-02 15:04:05.999999"

connectInterval = 5 * time.Second
Expand All @@ -33,14 +34,16 @@ type dbConn struct {
func getDbName() string {
dbPassEnvName := common.DBPasswordEnvName
dbPass := os.Getenv(dbPassEnvName)
dbUser := env.GetEnvOrDefault(
common.DBUserEnvName, common.DefaultMySQLUser)
dbHost := env.GetEnvOrDefault(
common.MySQLDBHostEnvName, common.DefaultMySQLHost)
dbPort := env.GetEnvOrDefault(
common.MySQLDBPortEnvName, common.DefaultMySQLPort)
dbName := env.GetEnvOrDefault(common.MySQLDatabase,
common.DefaultMySQLDatabase)

return fmt.Sprintf(dbNameTmpl, dbPass, dbHost, dbPort, dbName)
return fmt.Sprintf(dbNameTmpl, dbUser, dbPass, dbHost, dbPort, dbName)
}

func openSQLConn(driverName string, dataSourceName string, interval time.Duration,
Expand Down

0 comments on commit 3e9c9db

Please sign in to comment.