Skip to content

Commit

Permalink
client init later
Browse files Browse the repository at this point in the history
  • Loading branch information
ybelMekk committed Sep 28, 2021
1 parent 1e64ed7 commit 0f3b1c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cmd/aiven/create_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions pkg/aiven/aiven.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 0f3b1c7

Please sign in to comment.