@@ -26,18 +26,22 @@ import (
26
26
"github.com/codeskyblue/go-sh"
27
27
core "k8s.io/api/core/v1"
28
28
"k8s.io/client-go/kubernetes"
29
+ meta_util "kmodules.xyz/client-go/meta"
29
30
"kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
30
31
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
31
32
)
32
33
33
34
const (
34
- PostgresUser = "POSTGRES_USER"
35
- PostgresPassword = "POSTGRES_PASSWORD"
36
- EnvPgPassword = "PGPASSWORD"
37
- PgDumpFile = "dumpfile.sql"
38
- PgDumpCMD = "pg_dump"
39
- PgDumpallCMD = "pg_dumpall"
40
- PgRestoreCMD = "psql"
35
+ EnvPgPassword = "PGPASSWORD"
36
+ PgDumpFile = "dumpfile.sql"
37
+ PgDumpCMD = "pg_dump"
38
+ PgDumpallCMD = "pg_dumpall"
39
+ PgRestoreCMD = "psql"
40
+
41
+ // Deprecated
42
+ envPostgresUser = "POSTGRES_USER"
43
+ // Deprecated
44
+ envPostgresPassword = "POSTGRES_PASSWORD"
41
45
)
42
46
43
47
type postgresOptions struct {
@@ -58,14 +62,21 @@ type postgresOptions struct {
58
62
dumpOptions restic.DumpOptions
59
63
}
60
64
65
+ func must (v []byte , err error ) string {
66
+ if err != nil {
67
+ panic (err )
68
+ }
69
+ return string (v )
70
+ }
71
+
61
72
func waitForDBReady (appBinding * v1alpha1.AppBinding , secret * core.Secret , waitTimeout int32 ) error {
62
73
log .Infoln ("Waiting for the database to be ready....." )
63
74
shell := sh .NewSession ()
64
- shell .SetEnv (EnvPgPassword , string ( secret .Data [ PostgresPassword ] ))
75
+ shell .SetEnv (EnvPgPassword , must ( meta_util . GetBytesForKeys ( secret .Data , core . BasicAuthPasswordKey , envPostgresPassword ) ))
65
76
args := []interface {}{
66
77
fmt .Sprintf ("--host=%s" , appBinding .Spec .ClientConfig .Service .Name ),
67
78
fmt .Sprintf ("--port=%d" , appBinding .Spec .ClientConfig .Service .Port ),
68
- fmt .Sprintf ("--username=%s" , secret .Data [ PostgresUser ] ),
79
+ fmt .Sprintf ("--username=%s" , must ( meta_util . GetBytesForKeys ( secret .Data , core . BasicAuthUsernameKey , envPostgresUser )) ),
69
80
fmt .Sprintf ("--timeout=%d" , waitTimeout ),
70
81
}
71
82
return shell .Command ("pg_isready" , args ... ).Run ()
0 commit comments