Skip to content

Commit

Permalink
Merge pull request #1798 from johannesfrey/vclusterctl-config
Browse files Browse the repository at this point in the history
chore(cli/config): unify config and make location configurable
  • Loading branch information
FabianKramm authored May 27, 2024
2 parents 3c64079 + b654616 commit 837f9f1
Show file tree
Hide file tree
Showing 144 changed files with 2,144 additions and 9,209 deletions.
12 changes: 3 additions & 9 deletions cmd/vclusterctl/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
loftctlUtil "github.com/loft-sh/loftctl/v4/pkg/util"
"github.com/loft-sh/log"
"github.com/loft-sh/vcluster/pkg/cli"
"github.com/loft-sh/vcluster/pkg/cli/config"
"github.com/loft-sh/vcluster/pkg/cli/flags"
"github.com/loft-sh/vcluster/pkg/platform"
"github.com/loft-sh/vcluster/pkg/upgrade"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -91,14 +91,8 @@ func (cmd *ConnectCmd) Run(ctx context.Context, args []string) error {
return err
}

// get manager
manager, err := platform.GetManager(cmd.Manager)
if err != nil {
return err
}

// is platform manager?
if manager == platform.ManagerPlatform {
cfg := cmd.GlobalFlags.LoadedConfig(cmd.Log)
if cfg.Manager.Type == config.ManagerPlatform {
return cli.ConnectPlatform(ctx, &cmd.ConnectOptions, cmd.GlobalFlags, vClusterName, args[1:], cmd.Log)
}

Expand Down
15 changes: 9 additions & 6 deletions cmd/vclusterctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
loftctlUtil "github.com/loft-sh/loftctl/v4/pkg/util"
"github.com/loft-sh/log"
"github.com/loft-sh/vcluster/pkg/cli"
"github.com/loft-sh/vcluster/pkg/cli/config"
"github.com/loft-sh/vcluster/pkg/cli/flags"
"github.com/loft-sh/vcluster/pkg/constants"
"github.com/loft-sh/vcluster/pkg/platform"
Expand All @@ -19,6 +20,7 @@ import (
type CreateCmd struct {
*flags.GlobalFlags
cli.CreateOptions

log log.Logger
}

Expand Down Expand Up @@ -94,14 +96,15 @@ vcluster create test --namespace test

// Run executes the functionality
func (cmd *CreateCmd) Run(ctx context.Context, args []string) error {
manager, err := platform.GetManager(cmd.Manager)
if err != nil {
return err
}
cfg := cmd.GlobalFlags.LoadedConfig(cmd.log)

// check if there is a platform client or we skip the info message
_, err := platform.NewClientFromPath(ctx, cmd.Config)
if err == nil {
config.PrintManagerInfo("create", cfg.Manager.Type, cmd.log)
}
// check if we should create a platform vCluster
platform.PrintManagerInfo("create", manager, cmd.log)
if manager == platform.ManagerPlatform {
if cfg.Manager.Type == config.ManagerPlatform {
return cli.CreatePlatform(ctx, &cmd.CreateOptions, cmd.GlobalFlags, args[0], cmd.log)
}

Expand Down
25 changes: 14 additions & 11 deletions cmd/vclusterctl/cmd/delete.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cmd

import (
"context"

loftctlUtil "github.com/loft-sh/loftctl/v4/pkg/util"
"github.com/loft-sh/log"
"github.com/loft-sh/vcluster/pkg/cli"
"github.com/loft-sh/vcluster/pkg/cli/config"
"github.com/loft-sh/vcluster/pkg/cli/flags"
"github.com/loft-sh/vcluster/pkg/platform"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -41,7 +44,7 @@ vcluster delete test --namespace test
Aliases: []string{"rm"},
ValidArgsFunction: newValidVClusterNameFunc(globalFlags),
RunE: func(cobraCmd *cobra.Command, args []string) error {
return cmd.Run(cobraCmd, args)
return cmd.Run(cobraCmd.Context(), args)
},
}

Expand All @@ -61,18 +64,18 @@ vcluster delete test --namespace test
}

// Run executes the functionality
func (cmd *DeleteCmd) Run(cobraCmd *cobra.Command, args []string) error {
manager, err := platform.GetManager(cmd.Manager)
if err != nil {
return err
func (cmd *DeleteCmd) Run(ctx context.Context, args []string) error {
cfg := cmd.GlobalFlags.LoadedConfig(cmd.log)

// check if there is a platform client or we skip the info message
_, err := platform.NewClientFromPath(ctx, cmd.Config)
if err == nil {
config.PrintManagerInfo("delete", cfg.Manager.Type, cmd.log)
}

// check if we should delete a platform vCluster
platform.PrintManagerInfo("delete", manager, cmd.log)
if manager == platform.ManagerPlatform {
// deploy platform cluster
return cli.DeletePlatform(cobraCmd.Context(), &cmd.DeleteOptions, args[0], cmd.log)
if cfg.Manager.Type == config.ManagerPlatform {
return cli.DeletePlatform(ctx, &cmd.DeleteOptions, cmd.Config, args[0], cmd.log)
}

return cli.DeleteHelm(cobraCmd.Context(), &cmd.DeleteOptions, cmd.GlobalFlags, args[0], cmd.log)
return cli.DeleteHelm(ctx, &cmd.DeleteOptions, cmd.GlobalFlags, args[0], cmd.log)
}
7 changes: 4 additions & 3 deletions cmd/vclusterctl/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"runtime"

"github.com/loft-sh/log"
"github.com/loft-sh/vcluster/pkg/cli/flags"
"github.com/loft-sh/vcluster/pkg/platform"
"github.com/loft-sh/vcluster/pkg/telemetry"
"github.com/spf13/cobra"
Expand All @@ -20,7 +21,7 @@ type cliInfo struct {
}

// NewInfoCmd creates a new info command
func NewInfoCmd() *cobra.Command {
func NewInfoCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
cobraCmd := &cobra.Command{
Use: "info",
Short: "Displays informations about the cli and platform",
Expand All @@ -41,10 +42,10 @@ vcluster info
Version: cobraCmd.Root().Version,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
MachineID: telemetry.GetMachineID(log.GetInstance()),
MachineID: telemetry.GetMachineID(globalFlags.LoadedConfig(log.GetInstance())),
}

platformClient, err := platform.CreatePlatformClient()
platformClient, err := platform.NewClientFromPath(cobraCmd.Context(), globalFlags.Config)
if err == nil {
infos.InstanceID = platformClient.Self().Status.InstanceID
}
Expand Down
17 changes: 7 additions & 10 deletions cmd/vclusterctl/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cmd
import (
"github.com/loft-sh/log"
"github.com/loft-sh/vcluster/pkg/cli"
"github.com/loft-sh/vcluster/pkg/cli/config"
"github.com/loft-sh/vcluster/pkg/cli/flags"
"github.com/loft-sh/vcluster/pkg/platform"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -40,8 +40,8 @@ vcluster list --namespace test
`,
Args: cobra.NoArgs,
Aliases: []string{"ls"},
RunE: func(cobraCmd *cobra.Command, args []string) error {
return cmd.Run(cobraCmd, args)
RunE: func(cobraCmd *cobra.Command, _ []string) error {
return cmd.Run(cobraCmd)
},
}

Expand All @@ -52,14 +52,11 @@ vcluster list --namespace test
}

// Run executes the functionality
func (cmd *ListCmd) Run(cobraCmd *cobra.Command, _ []string) error {
manager, err := platform.GetManager(cmd.Manager)
if err != nil {
return err
}

func (cmd *ListCmd) Run(cobraCmd *cobra.Command) error {
// check if we should create a platform vCluster
if manager == platform.ManagerPlatform {

cfg := cmd.GlobalFlags.LoadedConfig(cmd.log)
if cfg.Manager.Type == config.ManagerPlatform {
return cli.ListPlatform(cobraCmd.Context(), &cmd.ListOptions, cmd.GlobalFlags, cmd.log)
}

Expand Down
Loading

0 comments on commit 837f9f1

Please sign in to comment.