mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-12 05:12:37 +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"
|
||||
"path"
|
||||
|
||||
"github.com/containerd/containerd/api/types/task"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"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 {
|
||||
status, err := s.sandbox.StatusContainer(c.id)
|
||||
if err != nil && !isNotFound(err) {
|
||||
return err
|
||||
}
|
||||
if !c.cType.IsSandbox() && err == nil {
|
||||
if status.State.State != types.StateStopped {
|
||||
_, err = s.sandbox.StopContainer(c.id, false)
|
||||
if !c.cType.IsSandbox() {
|
||||
if c.status != task.StatusStopped {
|
||||
_, err := s.sandbox.StopContainer(c.id, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = s.sandbox.DeleteContainer(c.id); err != nil {
|
||||
if _, err := s.sandbox.DeleteContainer(c.id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user