diff --git a/cmd/kops/delete_instance.go b/cmd/kops/delete_instance.go index 5bcc023ac1c7c..8a5b7ea7727db 100644 --- a/cmd/kops/delete_instance.go +++ b/cmd/kops/delete_instance.go @@ -41,6 +41,7 @@ import ( // DeleteInstanceOptions is the command Object for an instance deletion. type deleteInstanceOptions struct { + Yes bool CloudOnly bool // The following two variables are when kops is validating a cluster @@ -91,14 +92,14 @@ func NewCmdDeleteInstance(f *util.Factory, out io.Writer) *cobra.Command { deleteInstanceExample := templates.Examples(i18n.T(` # Delete an instance from the currently active cluster. - kops delete instance i-0a5ed581b862d3425 + kops delete instance i-0a5ed581b862d3425 --yes # Delete an instance from the currently active cluster using node name. - kops delete instance ip-xx.xx.xx.xx.ec2.internal + kops delete instance ip-xx.xx.xx.xx.ec2.internal --yes # Delete an instance from the currently active cluster without validation or draining. - kops delete instance --cloudonly i-0a5ed581b862d3425 + kops delete instance --cloudonly i-0a5ed581b862d3425 --yes `)) deleteInstanceShort := i18n.T(`Delete an instance`) @@ -123,6 +124,8 @@ func NewCmdDeleteInstance(f *util.Factory, out io.Writer) *cobra.Command { cmd.Flags().BoolVar(&options.FailOnDrainError, "fail-on-drain-error", true, "The deletion will fail if draining a node fails.") cmd.Flags().BoolVar(&options.FailOnValidate, "fail-on-validate-error", true, "The deletion will fail if the cluster fails to validate.") + cmd.Flags().BoolVarP(&options.Yes, "yes", "y", options.Yes, "Specify --yes to immediately delete the instance") + cmd.Run = func(cmd *cobra.Command, args []string) { ctx := context.TODO() @@ -221,6 +224,17 @@ func RunDeleteInstance(ctx context.Context, f *util.Factory, out io.Writer, opti return fmt.Errorf("could not find instance %v", options.InstanceID) } + if options.CloudOnly { + fmt.Fprintf(out, "Instance %v found for deletion\n", cloudMember.ID) + } else { + fmt.Fprintf(out, "Instance %v (%v) found for deletion\n", cloudMember.ID, cloudMember.Node.Name) + } + + if !options.Yes { + fmt.Fprintf(out, "\nMust specify --yes to delete instancegroup\n") + return nil + } + d := &instancegroups.RollingUpdateCluster{ MasterInterval: 0, NodeInterval: 0, diff --git a/docs/cli/kops_delete_instance.md b/docs/cli/kops_delete_instance.md index 087c82a0ff238..a70d73586e6f7 100644 --- a/docs/cli/kops_delete_instance.md +++ b/docs/cli/kops_delete_instance.md @@ -17,14 +17,14 @@ kops delete instance [flags] ``` # Delete an instance from the currently active cluster. - kops delete instance i-0a5ed581b862d3425 + kops delete instance i-0a5ed581b862d3425 --yes # Delete an instance from the currently active cluster using node name. - kops delete instance ip-xx.xx.xx.xx.ec2.internal + kops delete instance ip-xx.xx.xx.xx.ec2.internal --yes # Delete an instance from the currently active cluster without validation or draining. - kops delete instance --cloudonly i-0a5ed581b862d3425 + kops delete instance --cloudonly i-0a5ed581b862d3425 --yes ``` ### Options @@ -38,6 +38,7 @@ kops delete instance [flags] --surge Surge by detaching the node from the ASG before deletion (default true) --validate-count int32 Amount of times that a cluster needs to be validated after single node update (default 2) --validation-timeout duration Maximum time to wait for a cluster to validate (default 15m0s) + -y, --yes Specify --yes to immediately delete the instance ``` ### Options inherited from parent commands