add ctr delete --exec-id to debug DeleteProcess

Signed-off-by: Lifubang <lifubang@acmcoder.com>
This commit is contained in:
Lifubang 2018-11-20 19:53:06 +08:00
parent 55baf50b5a
commit 2101b1362e

View File

@ -32,8 +32,16 @@ var deleteCommand = cli.Command{
Name: "force, f",
Usage: "force delete task process",
},
cli.StringFlag{
Name: "exec-id",
Usage: "process ID to kill",
},
},
Action: func(context *cli.Context) error {
var (
execID = context.String("exec-id")
force = context.Bool("force")
)
client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
return err
@ -48,9 +56,22 @@ var deleteCommand = cli.Command{
return err
}
var opts []containerd.ProcessDeleteOpts
if context.Bool("force") {
if force {
opts = append(opts, containerd.WithProcessKill)
}
if execID != "" {
p, err := task.LoadProcess(ctx, execID, nil)
if err != nil {
return err
}
status, err := p.Delete(ctx, opts...)
if err != nil {
return err
}
if ec := status.ExitCode(); ec != 0 {
return cli.NewExitError("", int(ec))
}
} else {
status, err := task.Delete(ctx, opts...)
if err != nil {
return err
@ -58,6 +79,7 @@ var deleteCommand = cli.Command{
if ec := status.ExitCode(); ec != 0 {
return cli.NewExitError("", int(ec))
}
}
return nil
},
}