Skip to content

Commit 53b5c4b

Browse files
committed
fix(postgres): fix cloudnative-pg superuser dbname
1 parent 09f0e4a commit 53b5c4b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

internal/database/postgres/postgres.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ func (Postgres) PortDefault() uint16 { return 5432 }
6464

6565
func (db Postgres) DatabaseEnvs(conf *conftypes.Global) kubernetes.ConfigLookups {
6666
if secret := db.cnpgSecretName(conf); secret != "" {
67+
cluster, _ := db.cnpgClusterName(conf)
6768
return kubernetes.ConfigLookups{kubernetes.LookupNamedSecret{
68-
Name: secret,
69+
Name: cluster + "-app", // Always use the app secret since superuser dbname is `*`
6970
Key: "dbname",
7071
}}
7172
}
@@ -357,8 +358,13 @@ func (Postgres) zalandoQuery() filter.Filter {
357358
return filter.Label{Name: "application", Value: "spilo"}
358359
}
359360

361+
func (Postgres) cnpgClusterName(conf *conftypes.Global) (string, bool) {
362+
v, ok := conf.DBPod.Labels["cnpg.io/cluster"]
363+
return v, ok
364+
}
365+
360366
func (db Postgres) cnpgSecretName(conf *conftypes.Global) string {
361-
if cluster, ok := conf.DBPod.Labels["cnpg.io/cluster"]; ok {
367+
if cluster, ok := db.cnpgClusterName(conf); ok {
362368
if conf.Username == db.UserDefault() {
363369
return cluster + "-superuser"
364370
}

0 commit comments

Comments
 (0)