mirror of https://github.com/kubernetes/kops.git
Clean up "kops replace" command
This commit is contained in:
parent
265e57bada
commit
1f9f6fc8ce
|
@ -127,7 +127,6 @@ go_library(
|
||||||
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
|
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/util/homedir:go_default_library",
|
"//vendor/k8s.io/client-go/util/homedir:go_default_library",
|
||||||
"//vendor/k8s.io/klog/v2:go_default_library",
|
"//vendor/k8s.io/klog/v2:go_default_library",
|
||||||
"//vendor/k8s.io/kubectl/pkg/cmd/util:go_default_library",
|
|
||||||
"//vendor/k8s.io/kubectl/pkg/cmd/util/editor:go_default_library",
|
"//vendor/k8s.io/kubectl/pkg/cmd/util/editor:go_default_library",
|
||||||
"//vendor/k8s.io/kubectl/pkg/util/i18n:go_default_library",
|
"//vendor/k8s.io/kubectl/pkg/util/i18n:go_default_library",
|
||||||
"//vendor/k8s.io/kubectl/pkg/util/templates:go_default_library",
|
"//vendor/k8s.io/kubectl/pkg/util/templates:go_default_library",
|
||||||
|
|
|
@ -31,7 +31,6 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup"
|
"k8s.io/kops/upup/pkg/fi/cloudup"
|
||||||
"k8s.io/kops/util/pkg/text"
|
"k8s.io/kops/util/pkg/text"
|
||||||
"k8s.io/kops/util/pkg/vfs"
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
|
||||||
"k8s.io/kubectl/pkg/util/i18n"
|
"k8s.io/kubectl/pkg/util/i18n"
|
||||||
"k8s.io/kubectl/pkg/util/templates"
|
"k8s.io/kubectl/pkg/util/templates"
|
||||||
)
|
)
|
||||||
|
@ -54,42 +53,38 @@ var (
|
||||||
replaceShort = i18n.T(`Replace cluster resources.`)
|
replaceShort = i18n.T(`Replace cluster resources.`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// replaceOptions is the options for the command
|
// ReplaceOptions is the options for the command
|
||||||
type replaceOptions struct {
|
type ReplaceOptions struct {
|
||||||
// Filenames is a list of files containing resources
|
// Filenames is a list of files containing resources to replace.
|
||||||
Filenames []string
|
Filenames []string
|
||||||
// create any resources not found - we limit to instance groups only for now
|
// Force causes any missing rescources to be created.
|
||||||
force bool
|
Force bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdReplace returns a new replace command
|
// NewCmdReplace returns a new replace command
|
||||||
func NewCmdReplace(f *util.Factory, out io.Writer) *cobra.Command {
|
func NewCmdReplace(f *util.Factory, out io.Writer) *cobra.Command {
|
||||||
options := &replaceOptions{}
|
options := &ReplaceOptions{}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "replace -f FILENAME",
|
Use: "replace {-f FILENAME}...",
|
||||||
Short: replaceShort,
|
Short: replaceShort,
|
||||||
Long: replaceLong,
|
Long: replaceLong,
|
||||||
Example: replaceExample,
|
Example: replaceExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Args: cobra.NoArgs,
|
||||||
ctx := context.TODO()
|
ValidArgsFunction: cobra.NoFileCompletions,
|
||||||
if len(options.Filenames) == 0 {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cmd.Help()
|
return RunReplace(context.TODO(), f, out, options)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdutil.CheckErr(RunReplace(ctx, f, cmd, out, options))
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().StringSliceVarP(&options.Filenames, "filename", "f", options.Filenames, "A list of one or more files separated by a comma.")
|
cmd.Flags().StringSliceVarP(&options.Filenames, "filename", "f", options.Filenames, "A list of one or more files separated by a comma.")
|
||||||
cmd.Flags().BoolVarP(&options.force, "force", "", false, "Force any changes, which will also create any non-existing resource")
|
|
||||||
cmd.MarkFlagRequired("filename")
|
cmd.MarkFlagRequired("filename")
|
||||||
|
cmd.Flags().BoolVarP(&options.Force, "force", "", false, "Force any changes, which will also create any non-existing resource")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunReplace processes the replace command
|
// RunReplace processes the replace command
|
||||||
func RunReplace(ctx context.Context, f *util.Factory, cmd *cobra.Command, out io.Writer, c *replaceOptions) error {
|
func RunReplace(ctx context.Context, f *util.Factory, out io.Writer, c *ReplaceOptions) error {
|
||||||
clientset, err := f.Clientset()
|
clientset, err := f.Clientset()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -140,7 +135,7 @@ func RunReplace(ctx context.Context, f *util.Factory, cmd *cobra.Command, out io
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cluster == nil {
|
if cluster == nil {
|
||||||
if !c.force {
|
if !c.Force {
|
||||||
return fmt.Errorf("cluster %v does not exist (try adding --force flag)", clusterName)
|
return fmt.Errorf("cluster %v does not exist (try adding --force flag)", clusterName)
|
||||||
}
|
}
|
||||||
_, err = clientset.CreateCluster(ctx, v)
|
_, err = clientset.CreateCluster(ctx, v)
|
||||||
|
@ -172,7 +167,7 @@ func RunReplace(ctx context.Context, f *util.Factory, cmd *cobra.Command, out io
|
||||||
ig, err := clientset.InstanceGroupsFor(cluster).Get(ctx, igName, metav1.GetOptions{})
|
ig, err := clientset.InstanceGroupsFor(cluster).Get(ctx, igName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsNotFound(err) {
|
if errors.IsNotFound(err) {
|
||||||
if !c.force {
|
if !c.Force {
|
||||||
return fmt.Errorf("instanceGroup: %v does not exist (try adding --force flag)", igName)
|
return fmt.Errorf("instanceGroup: %v does not exist (try adding --force flag)", igName)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,7 +10,7 @@ Replace cluster resources.
|
||||||
Replace a resource desired configuration by filename or stdin.
|
Replace a resource desired configuration by filename or stdin.
|
||||||
|
|
||||||
```
|
```
|
||||||
kops replace -f FILENAME [flags]
|
kops replace {-f FILENAME}... [flags]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
Loading…
Reference in New Issue