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

Fixed bug in database secret resolution #837

Merged
merged 1 commit into from
Jul 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func GetDbConfig(

if len(matches) == 0 {

dbConfigs, err := genDbConfigs(secrets.Items)
dbConfigs, err := genDbConfigs(secrets.Items, false)

if err != nil {
return nil, err
Expand Down Expand Up @@ -201,7 +201,7 @@ func resolveDb(spec crd.DatabaseSpec, c []config.DatabaseConfigContainer) config
return config.DatabaseConfigContainer{}
}

func genDbConfigs(secrets []core.Secret) ([]config.DatabaseConfigContainer, error) {
func genDbConfigs(secrets []core.Secret, verify bool) ([]config.DatabaseConfigContainer, error) {
configs := []config.DatabaseConfigContainer{}

var err error
Expand Down Expand Up @@ -235,7 +235,7 @@ func genDbConfigs(secrets []core.Secret) ([]config.DatabaseConfigContainer, erro
keys := []string{"db.host", "db.port", "db.user", "db.password", "db.name"}
providers.ExtractSecretData(secrets, extractFn, keys...)

if err != nil {
if verify && err != nil {
return nil, err
}

Expand All @@ -246,7 +246,7 @@ func searchAnnotationSecret(appName string, secrets []core.Secret) ([]config.Dat
for _, secret := range secrets {
anno := secret.GetAnnotations()
if v, ok := anno["clowder/database"]; ok && v == appName {
configs, err := genDbConfigs([]core.Secret{secret})
configs, err := genDbConfigs([]core.Secret{secret}, true)
return configs, err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAppInterfaceDb(t *testing.T) {
},
}}

configs, err := genDbConfigs(secrets)
configs, err := genDbConfigs(secrets, false)

assert.NoError(t, err, "failed to gen db config")
assert.Equal(t, len(configs), 1, "wrong number of configs")
Expand Down
13 changes: 13 additions & 0 deletions tests/kuttl/test-multi-app-interface-db/01-pods.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ data:
db.user: dXNlcmJhZAo= # userbad
db.password: cGFzc3dvcmQxMjM= # password123
---
apiVersion: v1
kind: Secret
metadata:
name: app-single
namespace: test-multi-app-interface-db
type: Opaque
data:
db.host: YXBwLXNpbmdsZS1zdGFnZS5yZHMuZXhhbXBsZS5jb20= # app-single-stage.rds.example.com
db.name: ZGJuYW1l # dbname
db.port: cGw= # pl This is to check that a bad port doesn't mess with the rest of them
db.user: dXNlcmJhZAo= # userbad
db.password: cGFzc3dvcmQxMjM= # password123
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdApp
metadata:
Expand Down