Skip to content

Commit

Permalink
Update rmp to test for running sandbox
Browse files Browse the repository at this point in the history
Running pod sandboxes have to be stopped before the actual removal. To
achieve a better user-experience, we now error in that case and give the
user the option to ignore it with the added `-f` flag for `rmp`.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed May 29, 2019
1 parent a7c9d2a commit dbe59e1
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions cmd/crictl/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,35 @@ var removePodCommand = cli.Command{
Name: "rmp",
Usage: "Remove one or more pods",
ArgsUsage: "POD-ID [POD-ID...]",
Action: func(context *cli.Context) error {
if context.NArg() == 0 {
return cli.ShowSubcommandHelp(context)
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Force removal of the pod sandbox, disregarding if running",
},
},
Action: func(ctx *cli.Context) error {
if ctx.NArg() == 0 {
return cli.ShowSubcommandHelp(ctx)
}
if err := getRuntimeClient(context); err != nil {
if err := getRuntimeClient(ctx); err != nil {
return err
}
for i := 0; i < context.NArg(); i++ {
id := context.Args().Get(i)
err := RemovePodSandbox(runtimeClient, id)
for i := 0; i < ctx.NArg(); i++ {
id := ctx.Args().Get(i)

resp, err := runtimeClient.PodSandboxStatus(context.Background(),
&pb.PodSandboxStatusRequest{PodSandboxId: id})
if err != nil {
return err
}
if !ctx.Bool("force") &&
resp.Status.State == pb.PodSandboxState_SANDBOX_READY {
if err := StopPodSandbox(runtimeClient, id); err != nil {
return fmt.Errorf("stopping the pod sandbox %q failed: %v", id, err)
}
}

err = RemovePodSandbox(runtimeClient, id)
if err != nil {
return fmt.Errorf("removing the pod sandbox %q failed: %v", id, err)
}
Expand Down

0 comments on commit dbe59e1

Please sign in to comment.