Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in global flag dependency injection #69

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/command/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func Clusters() *cobra.Command {
}

cmd.AddCommand(
clusters.Connect(run, kubeConfig, apiURL, useStdout),
clusters.List(run, apiURL),
clusters.Delete(run, apiURL),
clusters.View(run, apiURL),
clusters.Status(run, kubeConfig),
clusters.Connect(run, &kubeConfig, &apiURL, &useStdout),
clusters.List(run, &apiURL),
clusters.Delete(run, &apiURL),
clusters.View(run, &apiURL),
clusters.Status(run, &kubeConfig),
// TODO cleanup is currently experimental
// clusters.CleanUp(run, kubeConfig),
)
Expand Down
8 changes: 4 additions & 4 deletions internal/command/clusters/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// Connect returns a new cobra.Command that connects a cluster to the control plane.
func Connect(run types.RunFunc, kubeConfigPath, apiURL string, useStdout bool) *cobra.Command {
func Connect(run types.RunFunc, kubeConfigPath, apiURL *string, useStdout *bool) *cobra.Command {
const defaultRegistry = "quay.io/jetstack"
var registry string

Expand All @@ -36,18 +36,18 @@ func Connect(run types.RunFunc, kubeConfigPath, apiURL string, useStdout bool) *
return commandErrors.ErrNoOrganizationName
}

http := client.New(ctx, apiURL)
http := client.New(ctx, *apiURL)

serviceAccount, err := cluster.CreateServiceAccount(ctx, http, cnf.Organization, name)
if err != nil {
return fmt.Errorf("failed to create service account: %w", err)
}

var applier cluster.Applier
if useStdout {
if *useStdout {
applier = kubernetes.NewStdOutApplier()
} else {
applier, err = kubernetes.NewKubeConfigApplier(kubeConfigPath)
applier, err = kubernetes.NewKubeConfigApplier(*kubeConfigPath)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/command/clusters/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// Delete returns a new cobra.Command for deleting a cluster in the JSCP api
func Delete(run types.RunFunc, apiURL string) *cobra.Command {
func Delete(run types.RunFunc, apiURL *string) *cobra.Command {
var force bool

cmd := &cobra.Command{
Expand All @@ -30,7 +30,7 @@ func Delete(run types.RunFunc, apiURL string) *cobra.Command {
return errors.ErrNoOrganizationName
}

http := client.New(ctx, apiURL)
http := client.New(ctx, *apiURL)
name := args[0]
if name == "" {
return errors2.New("you must specify a cluster name")
Expand Down
4 changes: 2 additions & 2 deletions internal/command/clusters/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// List returns a new cobra.Command for listing clusters in the JSCP api
func List(run types.RunFunc, apiURL string) *cobra.Command {
func List(run types.RunFunc, apiURL *string) *cobra.Command {
var jsonOut bool

cmd := &cobra.Command{
Expand All @@ -30,7 +30,7 @@ func List(run types.RunFunc, apiURL string) *cobra.Command {
return errors.ErrNoOrganizationName
}

http := client.New(ctx, apiURL)
http := client.New(ctx, *apiURL)

clusters, err := cluster.List(ctx, http, cnf.Organization)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/command/clusters/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
)

// Status returns a new command that shows the status of a cluster resources
func Status(run types.RunFunc, kubeConfigPath string) *cobra.Command {
func Status(run types.RunFunc, kubeConfigPath *string) *cobra.Command {
return &cobra.Command{
Use: "status",
Short: "Prints information about the state in the currently configured cluster in kubeconfig",
Long: "The information printed by this command can be used to determine the state of a cluster prior to installing Jetstack Secure.",
Args: cobra.ExactValidArgs(0),
Run: run(func(ctx context.Context, args []string) error {
kubeCfg, err := kubernetes.NewConfig(kubeConfigPath)
kubeCfg, err := kubernetes.NewConfig(*kubeConfigPath)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/command/clusters/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// View returns a new cobra.Command for viewing a cluster in the JSCP api
func View(run types.RunFunc, apiURL string) *cobra.Command {
func View(run types.RunFunc, apiURL *string) *cobra.Command {
return &cobra.Command{
Use: "view [name]",
Short: "Opens a browser window to the cluster's dashboard",
Expand All @@ -27,7 +27,7 @@ func View(run types.RunFunc, apiURL string) *cobra.Command {
return errors.ErrNoOrganizationName
}

http := client.New(ctx, apiURL)
http := client.New(ctx, *apiURL)
name := args[0]
if name == "" {
return errors2.New("you must specify a cluster name")
Expand Down