Skip to content

Commit 1e493d2

Browse files
committed
fix(postgres): set default database to postgres when lookup fails
1 parent f1164d0 commit 1e493d2

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

internal/database/postgres/postgres.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (db Postgres) DatabaseEnvs(conf *conftypes.Global) kubernetes.ConfigLookups
7373

7474
return kubernetes.ConfigLookups{
7575
kubernetes.LookupEnv{"POSTGRES_DATABASE", "POSTGRES_DB"},
76+
kubernetes.LookupDefault("postgres"),
7677
}
7778
}
7879

internal/database/postgres/postgres_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,10 @@ func TestPostgres_DatabaseEnvs(t *testing.T) {
632632
{
633633
"default",
634634
args{&conftypes.Global{}},
635-
kubernetes.ConfigLookups{kubernetes.LookupEnv{"POSTGRES_DATABASE", "POSTGRES_DB"}},
635+
kubernetes.ConfigLookups{
636+
kubernetes.LookupEnv{"POSTGRES_DATABASE", "POSTGRES_DB"},
637+
kubernetes.LookupDefault("postgres"),
638+
},
636639
},
637640
{"cnpg", args{&conftypes.Global{DBPod: newCNPGPod()}}, kubernetes.ConfigLookups{
638641
kubernetes.LookupNamedSecret{

internal/kubernetes/config_lookup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,9 @@ func (f LookupSecretVolume) GetValue(ctx context.Context, client KubeClient, pod
163163

164164
return LookupNamedSecret{Name: secretName, Key: f.Key}.GetValue(ctx, client, pod)
165165
}
166+
167+
type LookupDefault string
168+
169+
func (l LookupDefault) GetValue(context.Context, KubeClient, corev1.Pod) (string, error) {
170+
return string(l), nil
171+
}

0 commit comments

Comments
 (0)