ctr: fix the cleanup of task
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
parent
e52fbfd5c1
commit
3d9dd2022d
@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
|
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
|
"github.com/containerd/containerd/errdefs"
|
||||||
clabels "github.com/containerd/containerd/labels"
|
clabels "github.com/containerd/containerd/labels"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
@ -170,7 +171,11 @@ var Command = cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if rm && !detach {
|
if rm && !detach {
|
||||||
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
|
defer func() {
|
||||||
|
if err := container.Delete(ctx, containerd.WithSnapshotCleanup); err != nil {
|
||||||
|
log.L.WithError(err).Error("failed to cleanup container")
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
var con console.Console
|
var con console.Console
|
||||||
if tty {
|
if tty {
|
||||||
@ -199,10 +204,13 @@ var Command = cli.Command{
|
|||||||
defer func() {
|
defer func() {
|
||||||
if enableCNI {
|
if enableCNI {
|
||||||
if err := network.Remove(ctx, commands.FullID(ctx, container), ""); err != nil {
|
if err := network.Remove(ctx, commands.FullID(ctx, container), ""); err != nil {
|
||||||
log.L.WithError(err).Error("network review")
|
log.L.WithError(err).Error("failed to remove network")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
task.Delete(ctx)
|
|
||||||
|
if _, err := task.Delete(ctx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
||||||
|
log.L.WithError(err).Error("failed to cleanup task")
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if statusC, err = task.Wait(ctx); err != nil {
|
if statusC, err = task.Wait(ctx); err != nil {
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -96,7 +97,12 @@ var startCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
var statusC <-chan containerd.ExitStatus
|
var statusC <-chan containerd.ExitStatus
|
||||||
if !detach {
|
if !detach {
|
||||||
defer task.Delete(ctx)
|
defer func() {
|
||||||
|
if _, err := task.Delete(ctx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
|
||||||
|
log.L.WithError(err).Error("failed to cleanup task")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if statusC, err = task.Wait(ctx); err != nil {
|
if statusC, err = task.Wait(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user