Skip to content

Commit

Permalink
Set MYSQL_ROOT_PASSWORD via Secret (kubeflow#253)
Browse files Browse the repository at this point in the history
* Set randomly generated MYSQL_ROOT_PASSWORD via Secret

Signed-off-by: Koichiro Den <den@valinux.co.jp>

* Seperate manifest for MYSQL_ROOT_PASSWORD, "test" being set by default

Signed-off-by: Koichiro Den <den@valinux.co.jp>

* Update run-tests.sh

Fixes: 5312459 ("Set randomly generated MYSQL_ROOT_PASSWORD via Secret")

Signed-off-by: Koichiro Den <den@valinux.co.jp>
  • Loading branch information
lkpdn authored and k8s-ci-robot committed Nov 22, 2018
1 parent 63dc070 commit 67e94c7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions manifests/vizier/core/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ spec:
containers:
- name: vizier-core
image: katib/vizier-core
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: vizier-db-secrets
key: MYSQL_ROOT_PASSWORD
command:
- './vizier-manager'
ports:
Expand Down
5 changes: 4 additions & 1 deletion manifests/vizier/db/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ spec:
image: mysql:8.0.3
env:
- name: MYSQL_ROOT_PASSWORD
value: "test"
valueFrom:
secretKeyRef:
name: vizier-db-secrets
key: MYSQL_ROOT_PASSWORD
- name: MYSQL_ALLOW_EMPTY_PASSWORD
value: "true"
- name: MYSQL_DATABASE
Expand Down
8 changes: 8 additions & 0 deletions manifests/vizier/db/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: vizier-db-secrets
namespace: katib
data:
MYSQL_ROOT_PASSWORD: test
18 changes: 16 additions & 2 deletions pkg/db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"math/big"
"math/rand"
"os"
"strings"
"time"

Expand All @@ -19,7 +20,7 @@ import (

const (
dbDriver = "mysql"
dbName = "root:test@tcp(vizier-db:3306)/vizier"
dbNameTmpl = "root:%s@tcp(vizier-db:3306)/vizier"
mysqlTimeFmt = "2006-01-02 15:04:05.999999"
)

Expand Down Expand Up @@ -76,6 +77,19 @@ type dbConn struct {

var rs1Letters = []rune("abcdefghijklmnopqrstuvwxyz")

func getDbName() string {
dbPass := os.Getenv("MYSQL_ROOT_PASSWORD")
if dbPass == "" {
log.Printf("WARN: Env var MYSQL_ROOT_PASSWORD is empty. Falling back to \"test\".")

// For backward compatibility, e.g. in case that all but vizier-core
// is older ones so we do not have Secret nor upgraded vizier-db.
dbPass = "test"
}

return fmt.Sprintf(dbNameTmpl, dbPass)
}

func NewWithSQLConn(db *sql.DB) VizierDBInterface {
d := new(dbConn)
d.db = db
Expand All @@ -91,7 +105,7 @@ func NewWithSQLConn(db *sql.DB) VizierDBInterface {
}

func New() VizierDBInterface {
db, err := sql.Open(dbDriver, dbName)
db, err := sql.Open(dbDriver, getDbName())
if err != nil {
log.Fatalf("DB open failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ sed -i -e "s@image: katib\/suggestion-grid@image: ${REGISTRY}\/${REPO_NAME}\/sug
sed -i -e "s@image: katib\/suggestion-hyperband@image: ${REGISTRY}\/${REPO_NAME}\/suggestion-hyperband:${VERSION}@" manifests/vizier/suggestion/hyperband/deployment.yaml
sed -i -e "s@image: katib\/suggestion-bayesianoptimization@image: ${REGISTRY}\/${REPO_NAME}\/suggestion-bayesianoptimization:${VERSION}@" manifests/vizier/suggestion/bayesianoptimization/deployment.yaml
sed -i -e "s@image: katib\/earlystopping-medianstopping@image: ${REGISTRY}\/${REPO_NAME}\/earlystopping-medianstopping:${VERSION}@" manifests/vizier/earlystopping/medianstopping/deployment.yaml
sed -i -e "31,37d" manifests/vizier/db/deployment.yaml
sed -i -e '/volumeMounts:/,$d' manifests/vizier/db/deployment.yaml

cat manifests/vizier/core/deployment.yaml
./scripts/deploy.sh
Expand Down

0 comments on commit 67e94c7

Please sign in to comment.