Skip to content

Commit

Permalink
Apiserver s3 and MySQL env vars (#1455)
Browse files Browse the repository at this point in the history
* making MySQL user and password configurable

* making minio parameters/secret configurable through env and file
  • Loading branch information
yaronha authored and k8s-ci-robot committed Jun 7, 2019
1 parent 5061fcf commit 6f8d430
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
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(".", "_")
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

0 comments on commit 6f8d430

Please sign in to comment.