From ad6810b1f0c5045e408451af71fcfc2ffc1fdf23 Mon Sep 17 00:00:00 2001 From: urmsone Date: Sun, 22 Dec 2019 20:51:10 +0800 Subject: [PATCH 1/2] Get dbUser from Env or default('root') --- pkg/db/v1alpha3/common/const.go | 3 +++ pkg/db/v1alpha3/mysql/mysql.go | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/db/v1alpha3/common/const.go b/pkg/db/v1alpha3/common/const.go index 2c5b03483be..abc42df4ec0 100644 --- a/pkg/db/v1alpha3/common/const.go +++ b/pkg/db/v1alpha3/common/const.go @@ -1,6 +1,8 @@ package common const ( + DBUserEnvName = "DB_USER" + DBNameEnvName = "DB_NAME" MySqlDBNameEnvValue = "mysql" @@ -11,6 +13,7 @@ const ( MySQLDBPortEnvName = "KATIB_MYSQL_PORT" MySQLDatabase = "KATIB_MYSQL_DATABASE" + DefaultMySQLUser = "root" DefaultMySQLDatabase = "katib" DefaultMySQLHost = "katib-db" DefaultMySQLPort = "3306" diff --git a/pkg/db/v1alpha3/mysql/mysql.go b/pkg/db/v1alpha3/mysql/mysql.go index 28378ef52cd..550a1976d01 100644 --- a/pkg/db/v1alpha3/mysql/mysql.go +++ b/pkg/db/v1alpha3/mysql/mysql.go @@ -19,7 +19,8 @@ import ( const ( dbDriver = "mysql" - dbNameTmpl = "root:%s@tcp(%s:%s)/%s?timeout=5s" + //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 @@ -33,6 +34,8 @@ 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( @@ -40,7 +43,7 @@ func getDbName() string { 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, From 33d3e85b679db86821746fbb135a081063d3e78e Mon Sep 17 00:00:00 2001 From: urmsone Date: Mon, 23 Dec 2019 15:49:59 +0800 Subject: [PATCH 2/2] Get dbUser from Env or default('root') --- pkg/db/v1alpha3/mysql/mysql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/db/v1alpha3/mysql/mysql.go b/pkg/db/v1alpha3/mysql/mysql.go index 550a1976d01..d6a521ec504 100644 --- a/pkg/db/v1alpha3/mysql/mysql.go +++ b/pkg/db/v1alpha3/mysql/mysql.go @@ -18,7 +18,7 @@ import ( ) const ( - dbDriver = "mysql" + 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"