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