From e4afcd88692935e8864b837e706c9e8c0930f746 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 7 Nov 2017 12:43:56 +0100 Subject: [PATCH 1/3] Add no edit flag so create instancegroup command is usable on scripts --- cmd/kops/create_ig.go | 71 ++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/cmd/kops/create_ig.go b/cmd/kops/create_ig.go index dbff7591a1..79e656b3bc 100644 --- a/cmd/kops/create_ig.go +++ b/cmd/kops/create_ig.go @@ -43,6 +43,8 @@ type CreateInstanceGroupOptions struct { DryRun bool // Output type during a DryRun Output string + // Do not launch editor when creating an instance group + NoEditor bool } var ( @@ -96,6 +98,7 @@ func NewCmdCreateInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command { // DryRun mode that will print YAML or JSON cmd.Flags().BoolVar(&options.DryRun, "dry-run", options.DryRun, "If true, only print the object that would be sent, without sending it. This flag can be used to create a cluster YAML or JSON manifest.") cmd.Flags().StringVarP(&options.Output, "output", "o", options.Output, "Ouput format. One of json|yaml") + cmd.Flags().BoolVar(&options.NoEditor, "no-editor", options.NoEditor, "If true, The instance group will be created by default with no option of editing it") return cmd } @@ -179,42 +182,46 @@ func RunCreateInstanceGroup(f *util.Factory, cmd *cobra.Command, args []string, } } - var ( - edit = editor.NewDefaultEditor(editorEnvs) - ) + if !options.NoEditor { + var ( + edit = editor.NewDefaultEditor(editorEnvs) + ) - raw, err := kopscodecs.ToVersionedYaml(ig) - if err != nil { - return err - } - ext := "yaml" - - // launch the editor - edited, file, err := edit.LaunchTempFile(fmt.Sprintf("%s-edit-", filepath.Base(os.Args[0])), ext, bytes.NewReader(raw)) - defer func() { - if file != "" { - os.Remove(file) + raw, err := kopscodecs.ToVersionedYaml(ig) + if err != nil { + return err } - }() - if err != nil { - return fmt.Errorf("error launching editor: %v", err) + ext := "yaml" + + // launch the editor + edited, file, err := edit.LaunchTempFile(fmt.Sprintf("%s-edit-", filepath.Base(os.Args[0])), ext, bytes.NewReader(raw)) + defer func() { + if file != "" { + os.Remove(file) + } + }() + if err != nil { + return fmt.Errorf("error launching editor: %v", err) + } + + obj, _, err := kopscodecs.ParseVersionedYaml(edited) + if err != nil { + return fmt.Errorf("error parsing yaml: %v", err) + } + group, ok := obj.(*api.InstanceGroup) + if !ok { + return fmt.Errorf("unexpected object type: %T", obj) + } + + err = validation.ValidateInstanceGroup(group) + if err != nil { + return err + } + + ig = group } - obj, _, err := kopscodecs.ParseVersionedYaml(edited) - if err != nil { - return fmt.Errorf("error parsing yaml: %v", err) - } - group, ok := obj.(*api.InstanceGroup) - if !ok { - return fmt.Errorf("unexpected object type: %T", obj) - } - - err = validation.ValidateInstanceGroup(group) - if err != nil { - return err - } - - _, err = clientset.InstanceGroupsFor(cluster).Create(group) + _, err = clientset.InstanceGroupsFor(cluster).Create(ig) if err != nil { return fmt.Errorf("error storing InstanceGroup: %v", err) } From a32da0748d095749a9b2742c47d0dad2abb6dc9a Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Fri, 10 Nov 2017 14:06:38 +0100 Subject: [PATCH 2/3] Generate cli docs --- docs/cli/kops_create_instancegroup.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/cli/kops_create_instancegroup.md b/docs/cli/kops_create_instancegroup.md index e37d9ce273..735adfe68e 100644 --- a/docs/cli/kops_create_instancegroup.md +++ b/docs/cli/kops_create_instancegroup.md @@ -30,6 +30,7 @@ kops create instancegroup ``` --dry-run If true, only print the object that would be sent, without sending it. This flag can be used to create a cluster YAML or JSON manifest. + --no-editor If true, The instance group will be created by default with no option of editing it -o, --output string Ouput format. One of json|yaml --role string Type of instance group to create (Node,Master,Bastion) (default "Node") --subnet stringSlice Subnets in which to create instance group From 9ca5f9ac989c0836caac547ed0897bb9b8b36cac Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Mon, 13 Nov 2017 11:32:24 +0100 Subject: [PATCH 3/3] Change no-edit flag to edit --- cmd/kops/create_ig.go | 11 ++++++----- docs/cli/kops_create_instancegroup.md | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/kops/create_ig.go b/cmd/kops/create_ig.go index 79e656b3bc..39b16e0d1d 100644 --- a/cmd/kops/create_ig.go +++ b/cmd/kops/create_ig.go @@ -43,8 +43,8 @@ type CreateInstanceGroupOptions struct { DryRun bool // Output type during a DryRun Output string - // Do not launch editor when creating an instance group - NoEditor bool + // Launch editor when creating an instance group + Editor bool } var ( @@ -70,7 +70,8 @@ var ( // NewCmdCreateInstanceGroup create a new cobra command object for creating a instancegroup. func NewCmdCreateInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command { options := &CreateInstanceGroupOptions{ - Role: string(api.InstanceGroupRoleNode), + Role: string(api.InstanceGroupRoleNode), + Editor: true, } cmd := &cobra.Command{ @@ -98,7 +99,7 @@ func NewCmdCreateInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command { // DryRun mode that will print YAML or JSON cmd.Flags().BoolVar(&options.DryRun, "dry-run", options.DryRun, "If true, only print the object that would be sent, without sending it. This flag can be used to create a cluster YAML or JSON manifest.") cmd.Flags().StringVarP(&options.Output, "output", "o", options.Output, "Ouput format. One of json|yaml") - cmd.Flags().BoolVar(&options.NoEditor, "no-editor", options.NoEditor, "If true, The instance group will be created by default with no option of editing it") + cmd.Flags().BoolVar(&options.Editor, "editor", options.Editor, "Default true. If true, an editor will be opened to edit default values.") return cmd } @@ -182,7 +183,7 @@ func RunCreateInstanceGroup(f *util.Factory, cmd *cobra.Command, args []string, } } - if !options.NoEditor { + if options.Editor { var ( edit = editor.NewDefaultEditor(editorEnvs) ) diff --git a/docs/cli/kops_create_instancegroup.md b/docs/cli/kops_create_instancegroup.md index 735adfe68e..96c889781d 100644 --- a/docs/cli/kops_create_instancegroup.md +++ b/docs/cli/kops_create_instancegroup.md @@ -30,7 +30,7 @@ kops create instancegroup ``` --dry-run If true, only print the object that would be sent, without sending it. This flag can be used to create a cluster YAML or JSON manifest. - --no-editor If true, The instance group will be created by default with no option of editing it + --editor Default true. If true, an editor will be opened to edit default values. (default true) -o, --output string Ouput format. One of json|yaml --role string Type of instance group to create (Node,Master,Bastion) (default "Node") --subnet stringSlice Subnets in which to create instance group