Skip to content

Commit

Permalink
Add vcluster import command
Browse files Browse the repository at this point in the history
  • Loading branch information
neogopher committed Sep 22, 2023
1 parent 1d82320 commit afcb133
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cmd/vclusterctl/cmd/import.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions cmd/vclusterctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit afcb133

Please sign in to comment.