ctr: add delete command
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
851d811eb2
commit
f9aac9d599
2 changed files with 51 additions and 0 deletions
50
cmd/ctr/delete.go
Normal file
50
cmd/ctr/delete.go
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
gocontext "context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/docker/containerd/api/execution"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var deleteCommand = cli.Command{
|
||||||
|
Name: "delete",
|
||||||
|
Usage: "delete a process from containerd store",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "pid, p",
|
||||||
|
Usage: "new process id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(context *cli.Context) error {
|
||||||
|
executionService, err := getExecutionService(context)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
id := context.Args().First()
|
||||||
|
if id == "" {
|
||||||
|
return fmt.Errorf("container id must be provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
pid := context.String("pid")
|
||||||
|
if pid != "" {
|
||||||
|
_, err = executionService.DeleteProcess(gocontext.Background(), &execution.DeleteProcessRequest{
|
||||||
|
ContainerID: id,
|
||||||
|
ProcessID: pid,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := executionService.Delete(gocontext.Background(), &execution.DeleteContainerRequest{
|
||||||
|
ID: id,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
|
@ -37,6 +37,7 @@ containerd client
|
||||||
runCommand,
|
runCommand,
|
||||||
execCommand,
|
execCommand,
|
||||||
eventsCommand,
|
eventsCommand,
|
||||||
|
deleteCommand,
|
||||||
}
|
}
|
||||||
app.Before = func(context *cli.Context) error {
|
app.Before = func(context *cli.Context) error {
|
||||||
if context.GlobalBool("debug") {
|
if context.GlobalBool("debug") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue