mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-13 13:46:46 +00:00
shimv2: trust cached status when deleting containers
vc status might not be accurate because it does not watch container status change. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
325a4f868d
commit
6487044fa1
@ -9,25 +9,21 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/api/types/task"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
|
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func deleteContainer(ctx context.Context, s *service, c *container) error {
|
func deleteContainer(ctx context.Context, s *service, c *container) error {
|
||||||
status, err := s.sandbox.StatusContainer(c.id)
|
if !c.cType.IsSandbox() {
|
||||||
if err != nil && !isNotFound(err) {
|
if c.status != task.StatusStopped {
|
||||||
return err
|
_, err := s.sandbox.StopContainer(c.id, false)
|
||||||
}
|
|
||||||
if !c.cType.IsSandbox() && err == nil {
|
|
||||||
if status.State.State != types.StateStopped {
|
|
||||||
_, err = s.sandbox.StopContainer(c.id, false)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = s.sandbox.DeleteContainer(c.id); err != nil {
|
if _, err := s.sandbox.DeleteContainer(c.id); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user