Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
refactor: make the pg logic clearer (#96)
Browse files Browse the repository at this point in the history
Signed-off-by: Thulio Ferraz Assis <[email protected]>
  • Loading branch information
Thulio Ferraz Assis authored Jul 30, 2020
1 parent 3e026af commit 5a6362c
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pkg/minibroker/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,27 @@ func (p PostgresProvider) Bind(services []corev1.Service, params map[string]inte

host := buildHostFromService(service)

database := ""
dbVal, ok := params["postgresqlDatabase"]
if ok {
database = dbVal.(string)
if !ok {
// Some older chart versions use postgresDatabase instead of postgresqlDatabase.
dbVal, ok = params["postgresDatabase"]
if !ok {
dbVal = ""
}
}
database := dbVal.(string)

var user, password string
userVal, ok := params["postgresqlUsername"]
if ok {
user = userVal.(string)
} else {
user = "postgres"
if !ok {
// Some older chart versions use postgresUsername instead of postgresqlUsername.
userVal, ok = params["postgresUsername"]
if !ok {
userVal = "postgres"
}
}
user := userVal.(string)

var password string
if user != "postgres" {
// postgresql-postgres-password is used when postgresqlPostgresPassword is set and
// postgresqlUsername is not 'postgres'.
Expand All @@ -60,11 +67,11 @@ func (p PostgresProvider) Bind(services []corev1.Service, params map[string]inte
}
password = passwordVal.(string)
} else {
passwordVal, ok := chartSecrets["postgres-password"]
passwordVal, ok := chartSecrets["postgresql-password"]
if !ok {
// Chart versions 2.0+ use postgresqlPassword instead of postresPassword
// Chart versions <2.0 use postgres-password instead of postgresql-password.
// See https://github.com/kubernetes-sigs/minibroker/issues/17
passwordVal, ok = chartSecrets["postgresql-password"]
passwordVal, ok = chartSecrets["postgres-password"]
if !ok {
return nil, errors.Errorf("password not found in secret keys")
}
Expand Down

0 comments on commit 5a6362c

Please sign in to comment.