Skip to content

Commit

Permalink
feat: Support custom database (#910)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege authored and k8s-ci-robot committed Nov 4, 2019
1 parent a55cf2a commit d9bb39e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/db/v1alpha3/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const (

MySQLDBHostEnvName = "KATIB_MYSQL_HOST"
MySQLDBPortEnvName = "KATIB_MYSQL_PORT"
MySQLDatabase = "KATIB_MYSQL_DATABASE"

DefaultMySQLHost = "katib-db"
DefaultMySQLPort = "3306"
DefaultMySQLDatabase = "katib"
DefaultMySQLHost = "katib-db"
DefaultMySQLPort = "3306"
)
6 changes: 4 additions & 2 deletions pkg/db/v1alpha3/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

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

connectInterval = 5 * time.Second
Expand All @@ -37,8 +37,10 @@ func getDbName() string {
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)
return fmt.Sprintf(dbNameTmpl, dbPass, dbHost, dbPort, dbName)
}

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

0 comments on commit d9bb39e

Please sign in to comment.