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

kustomize: fix unamanaged Postgres component (PROJQUAY-2002) #458

Merged
merged 1 commit into from
May 11, 2021
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
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