Skip to content

Commit

Permalink
fix(run): Remove stop race condition (#655)
Browse files Browse the repository at this point in the history
Approved-by: Alexander Jung <[email protected]>
  • Loading branch information
nderjung authored Jul 24, 2023
2 parents b14725b + 9860b19 commit 20225fb
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions cmd/kraft/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,6 @@ func (opts *Run) Run(cmd *cobra.Command, args []string) error {
break loop
}
}

// Remove the instance on Ctrl+C if the --rm flag is passed
if opts.Remove {
if _, err := opts.machineController.Stop(ctx, machine); err != nil {
log.G(ctx).Errorf("could not stop: %v", err)
return
}
if _, err := opts.machineController.Delete(ctx, machine); err != nil {
log.G(ctx).Errorf("could not remove: %v", err)
return
}
}
}()
}

Expand Down Expand Up @@ -431,6 +419,17 @@ func (opts *Run) Run(cmd *cobra.Command, args []string) error {
break loop
}
}

// Remove the instance on Ctrl+C if the --rm flag is passed
if opts.Remove {
if _, err := opts.machineController.Stop(ctx, machine); err != nil {
log.G(ctx).Errorf("could not stop: %v", err)
}

if _, err := opts.machineController.Delete(ctx, machine); err != nil {
log.G(ctx).Errorf("could not remove: %v", err)
}
}
} else {
// Output the name of the instance such that it can be piped
fmt.Fprintf(iostreams.G(ctx).Out, "%s\n", machine.Name)
Expand Down

0 comments on commit 20225fb

Please sign in to comment.