From 93241b2f8b9299c0cbedef1a951a7a5bb8f79f7c Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Fri, 8 Dec 2023 01:09:23 -0600 Subject: [PATCH] refactor: Redo env search logic and add support for CloudNativePG --- internal/config/database.go | 8 +- internal/database/mariadb/mariadb.go | 22 ++-- internal/database/mariadb/mariadb_test.go | 8 +- internal/database/mongodb/mongodb.go | 18 ++-- internal/database/mongodb/mongodb_test.go | 8 +- internal/database/postgres/postgres.go | 44 ++++++-- internal/database/postgres/postgres_test.go | 21 +++- internal/kubernetes/config_finder.go | 109 ++++++++++++++++++++ internal/kubernetes/label_query.go | 16 ++- internal/kubernetes/label_query_and_test.go | 16 +-- internal/kubernetes/secret.go | 57 ---------- internal/util/cmd_setup.go | 8 +- 12 files changed, 220 insertions(+), 115 deletions(-) create mode 100644 internal/kubernetes/config_finder.go diff --git a/internal/config/database.go b/internal/config/database.go index dd3413db..dcf2d9e6 100644 --- a/internal/config/database.go +++ b/internal/config/database.go @@ -13,19 +13,19 @@ type Database interface { Name() string DefaultPort() uint16 - PortEnvNames() []string - DatabaseEnvNames() []string + PortEnvNames() kubernetes.ConfigFinders + DatabaseEnvNames() kubernetes.ConfigFinders ListDatabasesQuery() string ListTablesQuery() string - UserEnvNames() []string + UserEnvNames() kubernetes.ConfigFinders DefaultUser() string DropDatabaseQuery(database string) string AnalyzeQuery() string PodLabels() []kubernetes.LabelQueryable FilterPods(ctx context.Context, client kubernetes.KubeClient, pods []v1.Pod) ([]v1.Pod, error) - PasswordEnvNames(conf Global) []string + PasswordEnvNames(conf Global) kubernetes.ConfigFinders ExecCommand(conf Exec) *command.Builder DumpCommand(conf Dump) *command.Builder diff --git a/internal/database/mariadb/mariadb.go b/internal/database/mariadb/mariadb.go index b673f004..e5144f31 100644 --- a/internal/database/mariadb/mariadb.go +++ b/internal/database/mariadb/mariadb.go @@ -18,16 +18,16 @@ func (MariaDB) Name() string { return "mariadb" } -func (MariaDB) PortEnvNames() []string { - return []string{"MARIADB_PORT_NUMBER", "MYSQL_PORT_NUMBER"} +func (MariaDB) PortEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MARIADB_PORT_NUMBER", "MYSQL_PORT_NUMBER"}} } func (MariaDB) DefaultPort() uint16 { return 3306 } -func (MariaDB) DatabaseEnvNames() []string { - return []string{"MARIADB_DATABASE", "MYSQL_DATABASE"} +func (MariaDB) DatabaseEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MARIADB_DATABASE", "MYSQL_DATABASE"}} } func (MariaDB) ListDatabasesQuery() string { @@ -38,8 +38,8 @@ func (MariaDB) ListTablesQuery() string { return "show tables" } -func (MariaDB) UserEnvNames() []string { - return []string{"MARIADB_USER", "MYSQL_USER"} +func (MariaDB) UserEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MARIADB_USER", "MYSQL_USER"}} } func (MariaDB) DefaultUser() string { @@ -77,11 +77,15 @@ func (MariaDB) FilterPods(ctx context.Context, client kubernetes.KubeClient, pod return pods, nil } -func (db MariaDB) PasswordEnvNames(c config.Global) []string { +func (db MariaDB) PasswordEnvNames(c config.Global) kubernetes.ConfigFinders { if c.Username == db.DefaultUser() { - return []string{"MARIADB_ROOT_PASSWORD", "MYSQL_ROOT_PASSWORD"} + return kubernetes.ConfigFinders{ + kubernetes.ConfigFromEnv{"MARIADB_ROOT_PASSWORD", "MYSQL_ROOT_PASSWORD"}, + } + } + return kubernetes.ConfigFinders{ + kubernetes.ConfigFromEnv{"MARIADB_PASSWORD", "MYSQL_PASSWORD"}, } - return []string{"MARIADB_PASSWORD", "MYSQL_PASSWORD"} } func (MariaDB) ExecCommand(conf config.Exec) *command.Builder { diff --git a/internal/database/mariadb/mariadb_test.go b/internal/database/mariadb/mariadb_test.go index 656f8142..243de888 100644 --- a/internal/database/mariadb/mariadb_test.go +++ b/internal/database/mariadb/mariadb_test.go @@ -166,16 +166,16 @@ func TestMariaDB_PasswordEnvNames(t *testing.T) { tests := []struct { name string args args - want []string + want kubernetes.ConfigFinders }{ - {"default", args{}, []string{"MARIADB_PASSWORD", "MYSQL_PASSWORD"}}, - {"root", args{config.Global{Username: "root"}}, []string{"MARIADB_ROOT_PASSWORD", "MYSQL_ROOT_PASSWORD"}}, + {"default", args{}, kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MARIADB_PASSWORD", "MYSQL_PASSWORD"}}}, + {"root", args{config.Global{Username: "root"}}, kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MARIADB_ROOT_PASSWORD", "MYSQL_ROOT_PASSWORD"}}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { db := MariaDB{} got := db.PasswordEnvNames(tt.args.c) - assert.Equal(t, got, tt.want) + assert.Equal(t, tt.want, got) }) } } diff --git a/internal/database/mongodb/mongodb.go b/internal/database/mongodb/mongodb.go index 4d0b62fd..980cc334 100644 --- a/internal/database/mongodb/mongodb.go +++ b/internal/database/mongodb/mongodb.go @@ -18,16 +18,16 @@ func (MongoDB) Name() string { return "mongodb" } -func (MongoDB) PortEnvNames() []string { - return []string{"MONGODB_PORT_NUMBER"} +func (MongoDB) PortEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MONGODB_PORT_NUMBER"}} } func (MongoDB) DefaultPort() uint16 { return 27017 } -func (MongoDB) DatabaseEnvNames() []string { - return []string{"MONGODB_EXTRA_DATABASES"} +func (MongoDB) DatabaseEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MONGODB_EXTRA_DATABASES"}} } func (MongoDB) ListDatabasesQuery() string { @@ -38,8 +38,8 @@ func (MongoDB) ListTablesQuery() string { return "db.getCollectionNames().forEach(function(collection){ print(collection) })" } -func (MongoDB) UserEnvNames() []string { - return []string{"MONGODB_EXTRA_USERNAMES", "MONGODB_ROOT_USER"} +func (MongoDB) UserEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MONGODB_EXTRA_USERNAMES", "MONGODB_ROOT_USER"}} } func (MongoDB) DefaultUser() string { @@ -73,11 +73,11 @@ func (MongoDB) FilterPods(ctx context.Context, client kubernetes.KubeClient, pod return pods, nil } -func (db MongoDB) PasswordEnvNames(c config.Global) []string { +func (db MongoDB) PasswordEnvNames(c config.Global) kubernetes.ConfigFinders { if c.Username == db.DefaultUser() { - return []string{"MONGODB_ROOT_PASSWORD"} + return kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MONGODB_ROOT_PASSWORD"}} } - return []string{"MONGODB_EXTRA_PASSWORDS"} + return kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MONGODB_EXTRA_PASSWORDS"}} } func (db MongoDB) AuthenticationDatabase(c config.Global) string { diff --git a/internal/database/mongodb/mongodb_test.go b/internal/database/mongodb/mongodb_test.go index a0955d47..e16d4f00 100644 --- a/internal/database/mongodb/mongodb_test.go +++ b/internal/database/mongodb/mongodb_test.go @@ -135,16 +135,16 @@ func TestMongoDB_PasswordEnvNames(t *testing.T) { tests := []struct { name string args args - want []string + want kubernetes.ConfigFinders }{ - {"default", args{}, []string{"MONGODB_EXTRA_PASSWORDS"}}, - {"root", args{config.Global{Username: "root"}}, []string{"MONGODB_ROOT_PASSWORD"}}, + {"default", args{}, kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MONGODB_EXTRA_PASSWORDS"}}}, + {"root", args{config.Global{Username: "root"}}, kubernetes.ConfigFinders{kubernetes.ConfigFromEnv{"MONGODB_ROOT_PASSWORD"}}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { db := MongoDB{} got := db.PasswordEnvNames(tt.args.c) - assert.Equal(t, got, tt.want) + assert.Equal(t, tt.want, got) }) } } diff --git a/internal/database/postgres/postgres.go b/internal/database/postgres/postgres.go index 7ea8805c..77e420d0 100644 --- a/internal/database/postgres/postgres.go +++ b/internal/database/postgres/postgres.go @@ -15,6 +15,7 @@ import ( "github.com/clevyr/kubedb/internal/database/sqlformat" "github.com/clevyr/kubedb/internal/kubernetes" log "github.com/sirupsen/logrus" + "k8s.io/apimachinery/pkg/selection" v1 "k8s.io/api/core/v1" ) @@ -25,16 +26,22 @@ func (Postgres) Name() string { return "postgres" } -func (Postgres) PortEnvNames() []string { - return []string{"POSTGRESQL_PORT_NUMBER"} +func (Postgres) PortEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{ + kubernetes.ConfigFromEnv{"POSTGRESQL_PORT_NUMBER"}, + kubernetes.ConfigFromVolumeSecret{Name: "app-secret", Key: "port"}, + } } func (Postgres) DefaultPort() uint16 { return 5432 } -func (Postgres) DatabaseEnvNames() []string { - return []string{"POSTGRES_DATABASE", "POSTGRES_DB"} +func (Postgres) DatabaseEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{ + kubernetes.ConfigFromEnv{"POSTGRES_DATABASE", "POSTGRES_DB"}, + kubernetes.ConfigFromVolumeSecret{Name: "app-secret", Key: "dbname"}, + } } func (Postgres) ListDatabasesQuery() string { @@ -45,8 +52,11 @@ func (Postgres) ListTablesQuery() string { return "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE'" } -func (Postgres) UserEnvNames() []string { - return []string{"POSTGRES_USER", "PGPOOL_POSTGRES_USERNAME", "PGUSER_SUPERUSER"} +func (Postgres) UserEnvNames() kubernetes.ConfigFinders { + return kubernetes.ConfigFinders{ + kubernetes.ConfigFromEnv{"POSTGRES_USER", "PGPOOL_POSTGRES_USERNAME", "PGUSER_SUPERUSER"}, + kubernetes.ConfigFromVolumeSecret{Name: "app-secret", Key: "username"}, + } } func (Postgres) DefaultUser() string { @@ -71,6 +81,7 @@ func (Postgres) PodLabels() []kubernetes.LabelQueryable { {Name: "app.kubernetes.io/name", Value: "postgresql-ha"}, {Name: "app.kubernetes.io/component", Value: "postgresql"}, }, + kubernetes.LabelQuery{Name: "cnpg.io/cluster", Operator: selection.Exists}, kubernetes.LabelQuery{Name: "application", Value: "spilo"}, kubernetes.LabelQuery{Name: "app", Value: "postgresql"}, } @@ -117,6 +128,16 @@ func (Postgres) FilterPods(ctx context.Context, client kubernetes.KubeClient, po break } } + } else if _, ok := pods[0].Labels["cnpg.io/cluster"]; ok { + log.Debug("filtering CloudNativePG Pods for Leader") + + for key, pod := range pods { + if role, ok := pod.Labels["cnpg.io/instanceRole"]; ok { + if role == "primary" { + return pods[key : key+1], nil + } + } + } } else if pods[0].Labels["application"] == "spilo" { log.Debug("querying Patroni for primary instance") cmd := command.NewBuilder("patronictl", "list", "--format=json") @@ -158,11 +179,16 @@ func (Postgres) FilterPods(ctx context.Context, client kubernetes.KubeClient, po return pods, nil } -func (db Postgres) PasswordEnvNames(c config.Global) []string { +func (db Postgres) PasswordEnvNames(c config.Global) kubernetes.ConfigFinders { + var searchEnvs kubernetes.ConfigFromEnv if c.Username == db.DefaultUser() { - return []string{"POSTGRES_POSTGRES_PASSWORD", "POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD", "PGPASSWORD_SUPERUSER"} + searchEnvs = append(searchEnvs, "POSTGRES_POSTGRES_PASSWORD") + } + searchEnvs = append(searchEnvs, "POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD", "PGPASSWORD_SUPERUSER") + return kubernetes.ConfigFinders{ + searchEnvs, + kubernetes.ConfigFromVolumeSecret{Name: "app-secret", Key: "password"}, } - return []string{"POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD", "PGPASSWORD_SUPERUSER"} } func (Postgres) ExecCommand(conf config.Exec) *command.Builder { diff --git a/internal/database/postgres/postgres_test.go b/internal/database/postgres/postgres_test.go index 355963b3..65c735e3 100644 --- a/internal/database/postgres/postgres_test.go +++ b/internal/database/postgres/postgres_test.go @@ -184,10 +184,25 @@ func TestPostgres_PasswordEnvNames(t *testing.T) { tests := []struct { name string args args - want []string + want kubernetes.ConfigFinders }{ - {"default", args{}, []string{"POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD", "PGPASSWORD_SUPERUSER"}}, - {"postgres", args{config.Global{Username: "postgres"}}, []string{"POSTGRES_POSTGRES_PASSWORD", "POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD", "PGPASSWORD_SUPERUSER"}}, + {"default", args{}, kubernetes.ConfigFinders{ + kubernetes.ConfigFromEnv{ + "POSTGRES_PASSWORD", + "PGPOOL_POSTGRES_PASSWORD", + "PGPASSWORD_SUPERUSER", + }, + kubernetes.ConfigFromVolumeSecret{Name: "app-secret", Key: "password"}, + }}, + {"postgres", args{config.Global{Username: "postgres"}}, kubernetes.ConfigFinders{ + kubernetes.ConfigFromEnv{ + "POSTGRES_POSTGRES_PASSWORD", + "POSTGRES_PASSWORD", + "PGPOOL_POSTGRES_PASSWORD", + "PGPASSWORD_SUPERUSER", + }, + kubernetes.ConfigFromVolumeSecret{Name: "app-secret", Key: "password"}, + }}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/kubernetes/config_finder.go b/internal/kubernetes/config_finder.go new file mode 100644 index 00000000..d1a8e095 --- /dev/null +++ b/internal/kubernetes/config_finder.go @@ -0,0 +1,109 @@ +package kubernetes + +import ( + "context" + "errors" + "fmt" + "strings" + + corev1 "k8s.io/api/core/v1" + v1meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +var ( + ErrEnvVarNotFound = errors.New("env var not found") + ErrNoDiscoveryEnvs = errors.New("failed to find config") +) + +type ConfigFinder interface { + GetValue(context.Context, KubeClient, corev1.Pod) (string, error) +} + +type ConfigFinders []ConfigFinder + +func (c ConfigFinders) Search(ctx context.Context, client KubeClient, pod corev1.Pod) (string, error) { + for _, search := range c { + found, err := search.GetValue(ctx, client, pod) + if err == nil { + return found, nil + } + } + return "", ErrNoDiscoveryEnvs +} + +type ConfigFromEnv []string + +func (e ConfigFromEnv) GetValue(ctx context.Context, client KubeClient, pod corev1.Pod) (string, error) { + if len(e) == 0 { + return "", ErrNoEnvNames + } + + var err error + var envVar *corev1.EnvVar + for _, envName := range e { + envVar, err = FindEnvVar(pod, envName) + if err == nil { + break + } + } + if err != nil { + if errors.Is(err, ErrEnvVarNotFound) { + return "", fmt.Errorf("%w: %s", ErrNoDiscoveryEnvs, strings.Join(e, ", ")) + } + return "", err + } + + if envVar.ValueFrom != nil { + switch { + case envVar.ValueFrom.SecretKeyRef != nil: + secretKeyRef := envVar.ValueFrom.SecretKeyRef + secret, err := client.Secrets().Get(ctx, secretKeyRef.Name, v1meta.GetOptions{}) + if err != nil { + return "", err + } + data, ok := secret.Data[secretKeyRef.Key] + if !ok { + return "", fmt.Errorf("%w: %v", ErrSecretDoesNotHaveKey, secretKeyRef) + } + return string(data), nil + case envVar.ValueFrom.ConfigMapKeyRef != nil: + configMapRef := envVar.ValueFrom.ConfigMapKeyRef + configMap, err := client.ConfigMaps().Get(ctx, configMapRef.Name, v1meta.GetOptions{}) + if err != nil { + return "", err + } + data, ok := configMap.Data[configMapRef.Key] + if !ok { + return "", fmt.Errorf("%w: %v", ErrConfigMapDoesNotHaveKey, configMapRef) + } + return data, nil + } + } + return envVar.Value, nil +} + +type ConfigFromVolumeSecret struct { + Name string + Key string +} + +func (f ConfigFromVolumeSecret) GetValue(ctx context.Context, client KubeClient, pod corev1.Pod) (string, error) { + if f.Name == "" || f.Key == "" { + return "", ErrNoEnvNames + } + + for _, volume := range pod.Spec.Volumes { + if volume.Name == f.Name && volume.Secret != nil { + secret, err := client.Secrets().Get(ctx, volume.Secret.SecretName, v1meta.GetOptions{}) + if err != nil { + return "", err + } + + if value, ok := secret.Data[f.Key]; ok { + return string(value), nil + } + } + } + + return "", ErrNoDiscoveryEnvs +} diff --git a/internal/kubernetes/label_query.go b/internal/kubernetes/label_query.go index dfe9fd11..e15d80d4 100644 --- a/internal/kubernetes/label_query.go +++ b/internal/kubernetes/label_query.go @@ -1,18 +1,26 @@ package kubernetes import ( + log "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/selection" ) type LabelQuery struct { - Name string - Value string + Name string + Operator selection.Operator + Value string } func (query LabelQuery) Matches(pod v1.Pod) bool { labelValue, ok := pod.Labels[query.Name] - if ok && labelValue == query.Value { - return true + switch query.Operator { + case selection.Exists: + return ok + case "": + return ok && labelValue == query.Value + default: + log.Panicf("Query operator not implemented: %q", query.Operator) } return false } diff --git a/internal/kubernetes/label_query_and_test.go b/internal/kubernetes/label_query_and_test.go index f5f705e9..ebfb1568 100644 --- a/internal/kubernetes/label_query_and_test.go +++ b/internal/kubernetes/label_query_and_test.go @@ -21,8 +21,8 @@ func TestLabelQueryAnd_FindPods(t *testing.T) { { "1 found", LabelQueryAnd{ - {"key", "value"}, - {"key2", "value2"}, + {Name: "key", Value: "value"}, + {Name: "key2", Value: "value2"}, }, args{&podList}, []v1.Pod{pod}, @@ -31,8 +31,8 @@ func TestLabelQueryAnd_FindPods(t *testing.T) { { "0 found", LabelQueryAnd{ - {"key", "value"}, - {"key2", "wrong"}, + {Name: "key", Value: "value"}, + {Name: "key2", Value: "wrong"}, }, args{&podList}, nil, @@ -65,8 +65,8 @@ func TestLabelQueryAnd_Matches(t *testing.T) { { "1 found", LabelQueryAnd{ - {"key", "value"}, - {"key2", "value2"}, + {Name: "key", Value: "value"}, + {Name: "key2", Value: "value2"}, }, args{pod}, true, @@ -74,8 +74,8 @@ func TestLabelQueryAnd_Matches(t *testing.T) { { "0 found", LabelQueryAnd{ - {"key", "value"}, - {"key2", "wrong"}, + {Name: "key", Value: "value"}, + {Name: "key2", Value: "wrong"}, }, args{pod}, false, diff --git a/internal/kubernetes/secret.go b/internal/kubernetes/secret.go index 62da351a..f978890e 100644 --- a/internal/kubernetes/secret.go +++ b/internal/kubernetes/secret.go @@ -1,19 +1,11 @@ package kubernetes import ( - "context" "errors" "fmt" - "strings" log "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" - v1meta "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -var ( - ErrEnvVarNotFound = errors.New("env var not found") - ErrNoDiscoveryEnvs = errors.New("discovery envs not found") ) func FindEnvVar(pod v1.Pod, envName string) (*v1.EnvVar, error) { @@ -33,52 +25,3 @@ var ( ErrSecretDoesNotHaveKey = errors.New("secret does not have key") ErrConfigMapDoesNotHaveKey = errors.New("config map does not have key") ) - -func (client KubeClient) GetValueFromEnv(ctx context.Context, pod v1.Pod, envNames []string) (string, error) { - if len(envNames) == 0 { - return "", ErrNoEnvNames - } - - var err error - var envVar *v1.EnvVar - for _, envName := range envNames { - envVar, err = FindEnvVar(pod, envName) - if err == nil { - break - } - } - if err != nil { - if errors.Is(err, ErrEnvVarNotFound) { - return "", fmt.Errorf("%w: %s", ErrNoDiscoveryEnvs, strings.Join(envNames, ", ")) - } - return "", err - } - - if envVar.ValueFrom != nil { - switch { - case envVar.ValueFrom.SecretKeyRef != nil: - secretKeyRef := envVar.ValueFrom.SecretKeyRef - secret, err := client.Secrets().Get(ctx, secretKeyRef.Name, v1meta.GetOptions{}) - if err != nil { - return "", err - } - data, ok := secret.Data[secretKeyRef.Key] - if !ok { - return "", fmt.Errorf("%w: %v", ErrSecretDoesNotHaveKey, secretKeyRef) - } - return string(data), nil - case envVar.ValueFrom.ConfigMapKeyRef != nil: - configMapRef := envVar.ValueFrom.ConfigMapKeyRef - configMap, err := client.ConfigMaps().Get(ctx, configMapRef.Name, v1meta.GetOptions{}) - if err != nil { - return "", err - } - data, ok := configMap.Data[configMapRef.Key] - if !ok { - return "", fmt.Errorf("%w: %v", ErrConfigMapDoesNotHaveKey, configMapRef) - } - return data, nil - } - } - return envVar.Value, nil -} diff --git a/internal/util/cmd_setup.go b/internal/util/cmd_setup.go index e99343e3..91899a6f 100644 --- a/internal/util/cmd_setup.go +++ b/internal/util/cmd_setup.go @@ -147,7 +147,7 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) (e panic(err) } if conf.Port == 0 { - port, err := conf.Client.GetValueFromEnv(ctx, conf.DbPod, conf.Dialect.PortEnvNames()) + port, err := conf.Dialect.PortEnvNames().Search(ctx, conf.Client, conf.DbPod) if err != nil { log.Debug("could not detect port from pod env") } else { @@ -172,7 +172,7 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) (e panic(err) } if conf.Database == "" { - conf.Database, err = conf.Client.GetValueFromEnv(ctx, conf.DbPod, conf.Dialect.DatabaseEnvNames()) + conf.Database, err = conf.Dialect.DatabaseEnvNames().Search(ctx, conf.Client, conf.DbPod) if err != nil { log.Debug("could not detect database from pod env") } else { @@ -188,7 +188,7 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) (e panic(err) } if conf.Username == "" { - conf.Username, err = conf.Client.GetValueFromEnv(ctx, conf.DbPod, conf.Dialect.UserEnvNames()) + conf.Username, err = conf.Dialect.UserEnvNames().Search(ctx, conf.Client, conf.DbPod) if err != nil { conf.Username = conf.Dialect.DefaultUser() log.WithField("user", conf.Username).Debug("could not detect user from pod env, using default") @@ -202,7 +202,7 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) (e panic(err) } if conf.Password == "" { - conf.Password, err = conf.Client.GetValueFromEnv(ctx, conf.DbPod, conf.Dialect.PasswordEnvNames(*conf)) + conf.Password, err = conf.Dialect.PasswordEnvNames(*conf).Search(ctx, conf.Client, conf.DbPod) if err != nil { return err }