Skip to content

Commit

Permalink
Fixed bug in database secret resolution (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
psav authored Jul 6, 2023
1 parent 0dd482f commit c1066bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
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

0 comments on commit c1066bc

Please sign in to comment.