mirror of https://github.com/kubernetes/kops.git
Rework toolbox convert imported command
This commit is contained in:
parent
a8da81a361
commit
a7722cf67a
|
|
@ -100,6 +100,7 @@ func NewCmdRoot(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
cmd.AddCommand(NewCmdEdit(f, out))
|
||||
cmd.AddCommand(NewCmdUpdate(f, out))
|
||||
cmd.AddCommand(NewCmdReplace(f, out))
|
||||
cmd.AddCommand(NewCmdToolbox(f, out))
|
||||
cmd.AddCommand(NewCmdValidate(f, out))
|
||||
|
||||
return cmd
|
||||
|
|
|
|||
|
|
@ -20,12 +20,14 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// toolboxCmd represents the toolbox command
|
||||
var toolboxCmd = &cobra.Command{
|
||||
Use: "toolbox",
|
||||
Short: "Misc infrequently used commands",
|
||||
}
|
||||
func NewCmdToolbox(f *util.Factory, out io.Writer) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "toolbox",
|
||||
Short: "Misc infrequently used commands",
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCommand.AddCommand(toolboxCmd)
|
||||
// create subcommands
|
||||
cmd.AddCommand(NewCmdToolboxConvertImported(f, out))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,46 +19,64 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"k8s.io/kops/cmd/kops/util"
|
||||
api "k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||
"k8s.io/kops/upup/pkg/kutil"
|
||||
k8sapi "k8s.io/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
type ConvertImportedCmd struct {
|
||||
type ToolboxConvertImportedOptions struct {
|
||||
NewClusterName string
|
||||
|
||||
// Channel is the location of the api.Channel to use for our defaults
|
||||
Channel string
|
||||
|
||||
ClusterName string
|
||||
}
|
||||
|
||||
var convertImported ConvertImportedCmd
|
||||
func (o *ToolboxConvertImportedOptions) InitDefaults() {
|
||||
o.Channel = api.DefaultChannel
|
||||
}
|
||||
|
||||
func NewCmdToolboxConvertImported(f *util.Factory, out io.Writer) *cobra.Command {
|
||||
options := &ToolboxConvertImportedOptions{}
|
||||
|
||||
func init() {
|
||||
cmd := &cobra.Command{
|
||||
Use: "convert-imported",
|
||||
Short: "Convert an imported cluster into a kops cluster",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := convertImported.Run()
|
||||
if err := rootCommand.ProcessArgs(args); err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
|
||||
options.ClusterName = rootCommand.ClusterName()
|
||||
|
||||
err := RunToolboxConvertImported(f, out, options)
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
toolboxCmd.AddCommand(cmd)
|
||||
cmd.Flags().StringVar(&options.NewClusterName, "newname", options.NewClusterName, "new cluster name")
|
||||
cmd.Flags().StringVar(&options.Channel, "channel", options.Channel, "Channel to use for upgrade")
|
||||
|
||||
cmd.Flags().StringVar(&convertImported.NewClusterName, "newname", "", "new cluster name")
|
||||
cmd.Flags().StringVar(&convertImported.Channel, "channel", api.DefaultChannel, "Channel to use for upgrade")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *ConvertImportedCmd) Run() error {
|
||||
cluster, err := rootCommand.Cluster()
|
||||
func RunToolboxConvertImported(f *util.Factory, out io.Writer, options *ToolboxConvertImportedOptions) error {
|
||||
clientset, err := f.Clientset()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientset, err := rootCommand.Clientset()
|
||||
if options.ClusterName == "" {
|
||||
return fmt.Errorf("ClusterName is required")
|
||||
}
|
||||
|
||||
cluster, err := clientset.Clusters().Get(options.ClusterName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -76,7 +94,7 @@ func (c *ConvertImportedCmd) Run() error {
|
|||
return fmt.Errorf("cluster %q does not appear to be a cluster imported using kops import", cluster.ObjectMeta.Name)
|
||||
}
|
||||
|
||||
if c.NewClusterName == "" {
|
||||
if options.NewClusterName == "" {
|
||||
return fmt.Errorf("--newname is required for converting an imported cluster")
|
||||
}
|
||||
|
||||
|
|
@ -110,13 +128,13 @@ func (c *ConvertImportedCmd) Run() error {
|
|||
return fmt.Errorf("error initializing AWS client: %v", err)
|
||||
}
|
||||
|
||||
channel, err := api.LoadChannel(c.Channel)
|
||||
channel, err := api.LoadChannel(options.Channel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d := &kutil.ConvertKubeupCluster{
|
||||
NewClusterName: c.NewClusterName,
|
||||
NewClusterName: options.NewClusterName,
|
||||
OldClusterName: oldClusterName,
|
||||
Cloud: cloud,
|
||||
ClusterConfig: cluster,
|
||||
|
|
|
|||
Loading…
Reference in New Issue