Skip to content

Commit

Permalink
feat(postgres): Add support for CloudNativePG superuser
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Dec 10, 2023
1 parent 1cb0163 commit 242b205
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions internal/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ func (Postgres) FilterPods(ctx context.Context, client kubernetes.KubeClient, po

func (db Postgres) PasswordEnvNames(c config.Global) kubernetes.ConfigFinders {
var searchEnvs kubernetes.ConfigFromEnv
searchUser := kubernetes.ConfigFromVolumeSecret{Key: "password"}
if c.Username == db.DefaultUser() {
searchEnvs = append(searchEnvs, "POSTGRES_POSTGRES_PASSWORD")
searchUser.Name = "superuser-secret"
} else {
searchUser.Name = "app-secret"
}
searchEnvs = append(searchEnvs, "POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD", "PGPASSWORD_SUPERUSER")
return kubernetes.ConfigFinders{
searchEnvs,
kubernetes.ConfigFromVolumeSecret{Name: "app-secret", Key: "password"},
}
return kubernetes.ConfigFinders{searchEnvs, searchUser}
}

func (Postgres) ExecCommand(conf config.Exec) *command.Builder {
Expand Down
2 changes: 1 addition & 1 deletion internal/database/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestPostgres_PasswordEnvNames(t *testing.T) {
"PGPOOL_POSTGRES_PASSWORD",
"PGPASSWORD_SUPERUSER",
},
kubernetes.ConfigFromVolumeSecret{Name: "app-secret", Key: "password"},
kubernetes.ConfigFromVolumeSecret{Name: "superuser-secret", Key: "password"},
}},
}
for _, tt := range tests {
Expand Down

0 comments on commit 242b205

Please sign in to comment.