From 120e616ea6a3d8b3d1ffca609b78bfdc4d6e8ade Mon Sep 17 00:00:00 2001 From: Shukui Yang Date: Fri, 18 Sep 2020 18:56:40 +0800 Subject: [PATCH] runtime: Ignore ENOENT in kill/delete If sandbox/container's dir is not exist, the kill/delete will always fail,and this make kubelet/container delete it repeatedly but fail always. In some kind of abnormal situation(e.g. kill -9 $pidofqemu), kata-runtime may kill/delete sandbox first, this make container'dir not exist, so kata-runtime should skip this error. Fixes: #2959. Signed-off-by: Shukui Yang --- cli/delete.go | 6 ++++++ cli/kill.go | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cli/delete.go b/cli/delete.go index c2ce52a468..641ef3727a 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -10,6 +10,7 @@ import ( "context" "fmt" "os" + "syscall" "github.com/kata-containers/runtime/pkg/katautils" vc "github.com/kata-containers/runtime/virtcontainers" @@ -75,6 +76,11 @@ func delete(ctx context.Context, containerID string, force bool) error { kataLog.Warnf("Failed to get container, force will not fail: %s", err) return nil } + if err.Error() == syscall.ENOENT.Error() { + kataLog.WithField("container", containerID).Info("skipping delete as container does not exist") + katautils.DelContainerIDMapping(ctx, containerID) + return nil + } return err } diff --git a/cli/kill.go b/cli/kill.go index 60fa41e09e..259a72dd52 100644 --- a/cli/kill.go +++ b/cli/kill.go @@ -108,8 +108,11 @@ func kill(ctx context.Context, containerID, signal string, all bool) error { // Checks the MUST and MUST NOT from OCI runtime specification status, sandboxID, err := getExistingContainerInfo(ctx, containerID) - if err != nil { + if err.Error() == syscall.ENOENT.Error() { + kataLog.WithField("container", containerID).Info("skipping kill as container does not exist") + return nil + } return err }