Skip to content

Commit

Permalink
Added vcluster pro start command
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Kosiewski <[email protected]>
  • Loading branch information
Thomas Kosiewski committed Sep 21, 2023
1 parent 36132a7 commit bf8a12a
Show file tree
Hide file tree
Showing 450 changed files with 95,303 additions and 585 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/.idea
/.vscode
/.devspace
/kubeconfig.yaml
.devspace/
Expand Down
14 changes: 12 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
"program": "${workspaceRoot}/cmd/vclusterctl/main.go",
"cwd": "${workspaceRoot}",
"args": ["create", "vcluster-1", "-nvcluster-1"]
},
{
"name": "Debug pro cli",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/cmd/vclusterctl/main.go",
"cwd": "${workspaceRoot}",
"buildFlags": "-tags=pro",
"args": ["pro", "start"]
},
{
"name": "Debug vcluster (localhost:2346)",
Expand Down Expand Up @@ -43,6 +53,6 @@
},
"args": ["-ginkgo.v"], // add "-ginkgo.focus=.*part of test name.*" to run just the test containing said regexp
"showLog": true,
}
}
]
}
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"gopls": {
"build.env": {
"GOFLAGS": "-tags=pro"
}
}
}
13 changes: 13 additions & 0 deletions cmd/vclusterctl/cmd/login/notpro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !pro
// +build !pro

package login

import (
"github.com/loft-sh/vcluster/cmd/vclusterctl/flags"
"github.com/spf13/cobra"
)

func NewLoginCmd(globalFlags *flags.GlobalFlags) (*cobra.Command, error) {
return nil, nil
}
43 changes: 43 additions & 0 deletions cmd/vclusterctl/cmd/login/pro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//go:build pro
// +build pro

package login

import (
"fmt"

loftctl "github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd"
loftctlflags "github.com/loft-sh/loftctl/v3/cmd/loftctl/flags"
"github.com/loft-sh/vcluster/cmd/vclusterctl/flags"
"github.com/loft-sh/vcluster/pkg/pro"
"github.com/spf13/cobra"
)

func NewLoginCmd(globalFlags *flags.GlobalFlags) (*cobra.Command, error) {
loftctlGlobalFlags := &loftctlflags.GlobalFlags{
Silent: globalFlags.Silent,
Debug: globalFlags.Debug,
Config: globalFlags.Config,
LogOutput: globalFlags.LogOutput,
}

var err error
loftctlGlobalFlags.Config, err = pro.GetConfigFilePath()
if err != nil {
return nil, fmt.Errorf("failed to get vcluster pro configuration file path: %w", err)
}

loginCmd := loftctl.NewLoginCmd(loftctlGlobalFlags)

loginCmd.Use = "login [VCLUSTER_PRO_HOST]"
loginCmd.Long = `########################################################
Login into vCluster.Pro
Example:
vcluster login https://my-vcluster-pro.com
vcluster login https://my-vcluster-pro.com --access-key myaccesskey
########################################################
`

return loginCmd, nil
}
80 changes: 0 additions & 80 deletions cmd/vclusterctl/cmd/pro/alias.go

This file was deleted.

112 changes: 0 additions & 112 deletions cmd/vclusterctl/cmd/pro/login.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/vclusterctl/cmd/pro/notpro.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
"github.com/spf13/cobra"
)

func NewProCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
return nil
func NewProCmd(globalFlags *flags.GlobalFlags) (*cobra.Command, error) {
return nil, nil
}
70 changes: 43 additions & 27 deletions cmd/vclusterctl/cmd/pro/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
package pro

import (
"fmt"

loftctl "github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd"
loftctlflags "github.com/loft-sh/loftctl/v3/cmd/loftctl/flags"
"github.com/loft-sh/vcluster/cmd/vclusterctl/flags"
"github.com/loft-sh/vcluster/cmd/vclusterctl/log"
"github.com/loft-sh/vcluster/pkg/pro"
"github.com/spf13/cobra"
)

func NewProCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
func NewProCmd(globalFlags *flags.GlobalFlags) (*cobra.Command, error) {
proCmd := &cobra.Command{
Use: "pro",
Short: "vCluster.Pro subcommands",
Expand All @@ -19,38 +25,48 @@ func NewProCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
Args: cobra.NoArgs,
}

proCmd.AddCommand(NewStartCmd(globalFlags))
proCmd.AddCommand(NewLoginCmd(globalFlags))
loftctlGlobalFlags := &loftctlflags.GlobalFlags{
Silent: globalFlags.Silent,
Debug: globalFlags.Debug,
Config: globalFlags.Config,
LogOutput: globalFlags.LogOutput,
}

proxy := NewAliasCmd(globalFlags)
startCmd, err := NewStartCmd(loftctlGlobalFlags)
if err != nil {
return nil, fmt.Errorf("failed to create vcluster pro start command: %w", err)
}

proxy.AddCmd("connect", "Creates a kube context for the given virtual cluster")
proxy.AddCmd("create", "Creates a new virtual cluster in the given parent cluster")
proxy.AddCmd("delete", "Deletes a virtual cluster from a cluster")
proxy.AddCmd("import", "Imports a vCluster.Pro instance into a space")
proxy.AddCmd("list", "Lists the vCluster.Pro instances you have access to")
// Use is an alias to connect
proxy.AddCmd("use", "Creates a kube context for the given virtual cluster")
proCmd.AddCommand(startCmd)

proxy.AddCmd("space", "Management operations on space resources")
proxy.AddCmd("space create", "Creates a new space in the given cluster")
proxy.AddCmd("space delete", "Deletes a space from a cluster")
proxy.AddCmd("space import", "Imports a vcluster into a vcluster pro project")
proxy.AddCmd("space list", "Lists the vcluster pro spaces you have access to")
proxy.AddCmd("space use", "Creates a kube context for the given space")
return proCmd, nil
}

proxy.AddCmd("secret", "Management Operations on secret resources")
proxy.AddCmd("secret get", "Returns the key value of a project / shared secret")
proxy.AddCmd("secret list", "Lists all the shared secrets you have access to")
proxy.AddCmd("secret set", "Sets the key value of a project / shared secret")
func NewStartCmd(loftctlGlobalFlags *loftctlflags.GlobalFlags) (*cobra.Command, error) {
starCmd := loftctl.NewStartCmd(loftctlGlobalFlags)

proxy.AddCmd("generate", "Generates configuration")
proxy.AddCmd("generate admin-kube-config", "Generates a new kube config for connecting a cluster")
configPath, err := pro.GetConfigFilePath()
if err != nil {
return nil, fmt.Errorf("failed to get vcluster pro configuration file path: %w", err)
}

proxy.AddCmd("reset", "Reset configuration")
proxy.AddCmd("reset password", "Resets the password of a user")
starCmd.Flags().Set("config", configPath)

proCmd.AddCommand(proxy.Commands()...)
starCmd.Flags().Set("product", "vcluster-pro")
starCmd.Flags().Set("chart-name", "vcluster-control-plane")

starCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
version := pro.MinimumVersionTag

latestVersion, err := pro.LatestCompatibleVersion(cmd.Context())
if err != nil {
log.GetInstance().Warnf("failed to get latest compatible version: %v", err)
} else {
version = latestVersion
}

starCmd.Flags().Set("version", version)
}

return proCmd
return starCmd, nil
}
Loading

0 comments on commit bf8a12a

Please sign in to comment.