Skip to content

Commit

Permalink
kustomize: fix unamanaged Postgres component (PROJQUAY-2002)
Browse files Browse the repository at this point in the history
Fix a regression where DB_URI is not copied from provided
'configBundleSecret' when using an unmanaged database.

Signed-off-by: Alec Merdler <alecmerdler@gmail.com>
  • Loading branch information
alecmerdler committed May 11, 2021
1 parent b9d5b5f commit 49a524f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,9 @@ func Inflate(ctx *quaycontext.QuayRegistryContext, quay *v1.QuayRegistry, baseCo
}
parsedUserConfig["SECRET_KEY"] = ctx.SecretKey

if ctx.DbUri == "" && v1.ComponentIsManaged(quay.Spec.Components, v1.ComponentPostgres) {
if _, found := parsedUserConfig["DB_URI"]; found {
return nil, fmt.Errorf("`postgres` component marked as managed, but `DB_URI` found in user-provided config")
} else {
log.Info("`DB_URI` not found in config, generating new one")
if ctx.DbUri == "" {
if v1.ComponentIsManaged(quay.Spec.Components, v1.ComponentPostgres) {
log.Info("managed `DB_URI` not found in config, generating new one")

user := quay.GetName() + "-quay-database"
name := quay.GetName() + "-quay-database"
Expand All @@ -475,6 +473,10 @@ func Inflate(ctx *quaycontext.QuayRegistryContext, quay *v1.QuayRegistry, baseCo
}

ctx.DbUri = fmt.Sprintf("postgresql://%s:%s@%s:%s/%s", user, password, host, port, name)
} else {
if dbURI, found := parsedUserConfig["DB_URI"]; found {
ctx.DbUri = dbURI.(string)
}
}
}
parsedUserConfig["DB_URI"] = ctx.DbUri
Expand Down
21 changes: 21 additions & 0 deletions pkg/kustomize/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,27 @@ var inflateTests = []struct {
withComponents([]string{"base", "postgres"}),
nil,
},
{
"PostgresUnmanagedDbUriExists",
&v1.QuayRegistry{
Spec: v1.QuayRegistrySpec{
Components: []v1.Component{
{Kind: "postgres", Managed: false},
},
},
},
quaycontext.QuayRegistryContext{},
&corev1.Secret{
Data: map[string][]byte{
"config.yaml": encode(map[string]interface{}{
"SERVER_HOSTNAME": "quay.io",
"DB_URI": "postgresql://test-quay-database:postgres@test-quay-database:5432/test-quay-database",
}),
},
},
withComponents([]string{"base"}),
nil,
},
}

func TestInflate(t *testing.T) {
Expand Down

0 comments on commit 49a524f

Please sign in to comment.