diff --git a/cmd/vclusterctl/cmd/import.go b/cmd/vclusterctl/cmd/import.go new file mode 100644 index 0000000000..5aff157672 --- /dev/null +++ b/cmd/vclusterctl/cmd/import.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "fmt" + + "github.com/loft-sh/api/v3/pkg/product" + loftctlImport "github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd/importcmd" + loftctlUtil "github.com/loft-sh/loftctl/v3/pkg/util" + "github.com/loft-sh/vcluster/cmd/vclusterctl/flags" + "github.com/loft-sh/vcluster/pkg/pro" + "github.com/spf13/cobra" +) + +func NewImportCmd(globalFlags *flags.GlobalFlags) (*cobra.Command, error) { + loftctlGlobalFlags, err := pro.GlobalFlags(globalFlags) + if err != nil { + return nil, fmt.Errorf("failed to parse pro flags: %w", err) + } + + description := `######################################################## +################### vcluster import #################### +######################################################## +Imports a vcluster into a vCluster.Pro project. + +Example: +vcluster import my-vcluster --cluster connected-cluster \ +--namespace vcluster-my-vcluster --project my-project --importname my-vcluster +####################################################### + ` + + importCmd := loftctlImport.NewVClusterCmd(loftctlGlobalFlags) + importCmd.Use = "import" + loftctlUtil.VClusterNameOnlyUseLine + importCmd.Short = product.Replace(importCmd.Short) + importCmd.Long = description + + return importCmd, nil +} diff --git a/cmd/vclusterctl/cmd/root.go b/cmd/vclusterctl/cmd/root.go index 11ff5a5fa7..8d7aa4c8f2 100644 --- a/cmd/vclusterctl/cmd/root.go +++ b/cmd/vclusterctl/cmd/root.go @@ -103,6 +103,14 @@ func BuildRoot(log log.Logger) (*cobra.Command, error) { } rootCmd.AddCommand(logoutCmd) + importCmd, err := NewImportCmd(globalFlags) + if err != nil { + return nil, fmt.Errorf("failed to create import command: %w", err) + } + if importCmd != nil { + rootCmd.AddCommand(importCmd) + } + // add completion command err = rootCmd.RegisterFlagCompletionFunc("namespace", newNamespaceCompletionFunc(rootCmd.Context())) if err != nil {