Skip to content

Commit

Permalink
runtime: Ignore ENOENT in kill/delete
Browse files Browse the repository at this point in the history
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: kata-containers#2959.

Signed-off-by: Shukui Yang <keloyangsk@gmail.com>
  • Loading branch information
keloyang committed Oct 15, 2020
1 parent cb196de commit 120e616
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"fmt"
"os"
"syscall"

"github.com/kata-containers/runtime/pkg/katautils"
vc "github.com/kata-containers/runtime/virtcontainers"
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion cli/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 120e616

Please sign in to comment.