From 3fb566ca70b9668af681283e41e791ce369d6866 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Sat, 20 May 2017 15:14:51 +0200 Subject: [PATCH] server: sandbox_stop: ignore not found sandboxes This patch matches dockershim behavior Signed-off-by: Antonio Murdaca --- server/sandbox_stop.go | 12 +++++++++++- test/pod.bats | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/server/sandbox_stop.go b/server/sandbox_stop.go index d18cf51f..fb998b1d 100644 --- a/server/sandbox_stop.go +++ b/server/sandbox_stop.go @@ -16,7 +16,17 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque logrus.Debugf("StopPodSandboxRequest %+v", req) sb, err := s.getPodSandboxFromRequest(req.PodSandboxId) if err != nil { - return nil, err + if err == errSandboxIDEmpty { + return nil, err + } + + // If the sandbox isn't found we just return an empty response to adhere + // the the CRI interface which expects to not error out in not found + // cases. + + resp := &pb.StopPodSandboxResponse{} + logrus.Warnf("could not get sandbox %s, it's probably been stopped already: %v", req.PodSandboxId, err) + return resp, nil } podInfraContainer := sb.infraContainer diff --git a/test/pod.bats b/test/pod.bats index 762dee5c..4da5fc49 100644 --- a/test/pod.bats +++ b/test/pod.bats @@ -56,6 +56,29 @@ function teardown() { stop_crio } +@test "pod stop ignores not found sandboxes" { + start_crio + + run crioctl pod run --config "$TESTDATA"/sandbox_config.json + echo "$output" + [ "$status" -eq 0 ] + pod_id="$output" + run crioctl pod stop --id "$pod_id" + echo "$output" + [ "$status" -eq 0 ] + run crioctl pod remove --id "$pod_id" + echo "$output" + [ "$status" -eq 0 ] + + run crioctl pod stop --id "$pod_id" + echo "$output" + [ "$status" -eq 0 ] + + cleanup_ctrs + cleanup_pods + stop_crio +} + @test "pod list filtering" { start_crio run crioctl pod run --config "$TESTDATA"/sandbox_config.json -name pod1 --label "a=b" --label "c=d" --label "e=f"