From 365c291f1a3181fb127dbd8ebb3e03150863aa13 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Wed, 7 Dec 2016 17:38:36 +0100 Subject: [PATCH] server: Make RemovePodSandbox idempotent And in particular make it not fail when removing an already removed sandbox pod. According to the CRI spec: [RemovePodSandbox] is idempotent, and must not return an error if the sandbox has already been removed. We now only print a warning instead of returning an error. We still return an error when the passed pod ID is empty. Fixes #240 Signed-off-by: Samuel Ortiz --- server/sandbox.go | 7 ++++++- server/sandbox_remove.go | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/server/sandbox.go b/server/sandbox.go index 27589126..73c6919a 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -1,6 +1,7 @@ package server import ( + "errors" "fmt" "github.com/docker/docker/pkg/stringid" @@ -26,6 +27,10 @@ const ( podDefaultNamespace = "default" ) +var ( + errSandboxIDEmpty = errors.New("PodSandboxId should not be empty") +) + func (s *sandbox) addContainer(c *oci.Container) { s.containers.Add(c.Name(), c) } @@ -60,7 +65,7 @@ type podSandboxRequest interface { func (s *Server) getPodSandboxFromRequest(req podSandboxRequest) (*sandbox, error) { sbID := req.GetPodSandboxId() if sbID == "" { - return nil, fmt.Errorf("PodSandboxId should not be empty") + return nil, errSandboxIDEmpty } sandboxID, err := s.podIDIndex.Get(sbID) diff --git a/server/sandbox_remove.go b/server/sandbox_remove.go index b71cf43a..df9c5128 100644 --- a/server/sandbox_remove.go +++ b/server/sandbox_remove.go @@ -18,7 +18,13 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR logrus.Debugf("RemovePodSandboxRequest %+v", req) sb, err := s.getPodSandboxFromRequest(req) if err != nil { - return nil, err + if err == errSandboxIDEmpty { + return nil, err + } + + resp := &pb.RemovePodSandboxResponse{} + logrus.Warnf("could not get sandbox %s, it's probably been removed already: %v", req.GetPodSandboxId(), err) + return resp, nil } podInfraContainer := sb.infraContainer