From c78d6b057eb8f22ee111bed87a0a4327df952689 Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Thu, 7 Feb 2019 16:00:12 +0000 Subject: [PATCH] delete: force: Do not fail on non exiting container When a container does not exist, runc does not fail. Lets mimic this behavior, sometimes kuberentes will try to force delete containers that could not be created and gets confused if delete --force fails. Fixes: #1219 Signed-off-by: Jose Carlos Venegas Munoz --- cli/delete.go | 4 ++++ cli/delete_test.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cli/delete.go b/cli/delete.go index cb74539027..2db13821e8 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -71,6 +71,10 @@ func delete(ctx context.Context, containerID string, force bool) error { // Checks the MUST and MUST NOT from OCI runtime specification status, sandboxID, err := getExistingContainerInfo(ctx, containerID) if err != nil { + if force { + kataLog.Warnf("Failed to get container, force will not fail: %s", err) + return nil + } return err } diff --git a/cli/delete_test.go b/cli/delete_test.go index e3cde76f71..51fc553bb9 100644 --- a/cli/delete_test.go +++ b/cli/delete_test.go @@ -65,6 +65,10 @@ func TestDeleteInvalidContainer(t *testing.T) { err = delete(context.Background(), testContainerID, false) assert.Error(err) assert.False(vcmock.IsMockError(err)) + + // Force to delete missing container + err = delete(context.Background(), "non-existing-test", true) + assert.NoError(err) } func TestDeleteMissingContainerTypeAnnotation(t *testing.T) {