diff --git a/cmd/aiven/create_cmd.go b/cmd/aiven/create_cmd.go index 814da03c..9bf875d6 100644 --- a/cmd/aiven/create_cmd.go +++ b/cmd/aiven/create_cmd.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/nais/nais-cli/cmd" "github.com/nais/nais-cli/pkg/aiven" - "github.com/nais/nais-cli/pkg/client" "github.com/spf13/cobra" "log" "strings" @@ -54,7 +53,7 @@ nais aiven create username namespace -e 10 | nais aiven create username namespac return fmt.Errorf("flag: %s", err) } - aivenConfig := aiven.SetupAiven(client.SetupClient(), username, namespace, pool, secretName, expiry) + aivenConfig := aiven.SetupAiven(nil, username, namespace, pool, secretName, expiry) aivenApp, err := aivenConfig.GenerateApplication() if err != nil { return fmt.Errorf("an error occurred generating 'AivenApplication': %s", err) diff --git a/pkg/aiven/aiven.go b/pkg/aiven/aiven.go index bd43aaaa..0629795c 100644 --- a/pkg/aiven/aiven.go +++ b/pkg/aiven/aiven.go @@ -4,6 +4,7 @@ import ( "context" "fmt" aiven_nais_io_v1 "github.com/nais/liberator/pkg/apis/aiven.nais.io/v1" + client "github.com/nais/nais-cli/pkg/client" "github.com/nais/nais-cli/pkg/common" v1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -32,10 +33,10 @@ type AivenProperties struct { Expiry int } -func SetupAiven(client ctrl.Client, username, namespace, pool, secretName string, expiry int) *Aiven { +func SetupAiven(inClient ctrl.Client, username, namespace, pool, secretName string, expiry int) *Aiven { return &Aiven{ context.Background(), - client, + setupClient(inClient), AivenProperties{ Username: username, Namespace: namespace, @@ -46,6 +47,13 @@ func SetupAiven(client ctrl.Client, username, namespace, pool, secretName string } } +func setupClient(inClient ctrl.Client) ctrl.Client { + if inClient == nil { + return client.SetupClient() + } + return inClient +} + func (a *Aiven) GenerateApplication() (*aiven_nais_io_v1.AivenApplication, error) { namespace := v1.Namespace{} err := common.ValidateNamespace(a.Ctx, a.Client, a.Props.Namespace, &namespace)