Skip to content

Commit

Permalink
Add yes flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Aug 28, 2020
1 parent e205046 commit 2a12a05
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cmd/kops/delete_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`)
Expand All @@ -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()

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2a12a05

Please sign in to comment.