Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apiserver s3 and MySQL env vars #1455

Merged
merged 3 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/apiserver/client/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/go-sql-driver/mysql"
)

func CreateMySQLConfig(user string, mysqlServiceHost string,
func CreateMySQLConfig(user, password string, mysqlServiceHost string,
mysqlServicePort string, dbName string) *mysql.Config {
return &mysql.Config{
User: user,
Expand Down
16 changes: 12 additions & 4 deletions backend/src/apiserver/client_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"database/sql"
"fmt"
"os"
"strconv"
"time"

Expand All @@ -42,7 +43,10 @@ const (
minioServiceHost = "MINIO_SERVICE_SERVICE_HOST"
minioServicePort = "MINIO_SERVICE_SERVICE_PORT"
mysqlServiceHost = "MYSQL_SERVICE_HOST"
mysqlUser = "DBConfig.User"
mysqlPassword = "DBConfig.Password"
mysqlServicePort = "MYSQL_SERVICE_PORT"

podNamespace = "POD_NAMESPACE"
dbName = "mlpipeline"
initConnectionTimeout = "InitConnectionTimeout"
Expand Down Expand Up @@ -164,7 +168,8 @@ func initMetadataStore() *metadata.Store {
Host: proto.String(getStringConfig(mysqlServiceHost)),
Port: proto.Uint32(uint32(port)),
Database: proto.String("mlmetadata"),
User: proto.String("root"),
User: proto.String(getStringConfigWithDefault(mysqlUser, "root")),
Password: proto.String(getStringConfigWithDefault(mysqlPassword, "")),
},
},
}
Expand Down Expand Up @@ -218,7 +223,8 @@ func initDBClient(initConnectionTimeout time.Duration) *storage.DB {
// Format would be something like root@tcp(ip:port)/dbname?charset=utf8&loc=Local&parseTime=True
func initMysql(driverName string, initConnectionTimeout time.Duration) string {
mysqlConfig := client.CreateMySQLConfig(
"root",
getStringConfigWithDefault(mysqlUser, "root"),
getStringConfigWithDefault(mysqlPassword, ""),
getStringConfig(mysqlServiceHost),
getStringConfig(mysqlServicePort),
"")
Expand Down Expand Up @@ -258,8 +264,10 @@ func initMysql(driverName string, initConnectionTimeout time.Duration) string {

func initMinioClient(initConnectionTimeout time.Duration) storage.ObjectStoreInterface {
// Create minio client.
minioServiceHost := getStringConfig(minioServiceHost)
minioServicePort := getStringConfig(minioServicePort)
minioServiceHost := getStringConfigWithDefault(
"ObjectStoreConfig.Host", os.Getenv(minioServiceHost))
minioServicePort := getStringConfigWithDefault(
"ObjectStoreConfig.Port", os.Getenv(minioServicePort))
accessKey := getStringConfig("ObjectStoreConfig.AccessKey")
secretKey := getStringConfig("ObjectStoreConfig.SecretAccessKey")
bucketName := getStringConfig("ObjectStoreConfig.BucketName")
Expand Down
12 changes: 11 additions & 1 deletion backend/src/apiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"strings"
"time"

"github.com/fsnotify/fsnotify"
Expand All @@ -23,7 +24,9 @@ import (
)

func initConfig() {
// Import environment variable
// Import environment variable, support nested vars e.g. OBJECTSTORECONFIG_ACCESSKEY
replacer := strings.NewReplacer(".", "_")
Ark-kun marked this conversation as resolved.
Show resolved Hide resolved
viper.SetEnvKeyReplacer(replacer)
viper.AutomaticEnv()

// Set configuration file name. The format is auto detected in this case.
Expand All @@ -49,6 +52,13 @@ func getStringConfig(configName string) string {
return viper.GetString(configName)
}

func getStringConfigWithDefault(configName, value string) string {
if !viper.IsSet(configName) {
return value
}
return viper.GetString(configName)
}

func getDurationConfig(configName string) time.Duration {
if !viper.IsSet(configName) {
glog.Fatalf("Please specify flag %s", configName)
Expand Down