From 24304da5eec9513d7c08af233fa10224d57e5e73 Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Wed, 3 Aug 2022 16:06:41 -0400 Subject: [PATCH] server: return already created ID for duplicated requests turns out, kubelet does behave like this in some scenerios (static pods). Instead of failing forever, return the already created pod. Signed-off-by: Peter Hunt --- server/container_create.go | 4 ++-- server/sandbox_run_linux.go | 4 ++-- test/timeout.bats | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/container_create.go b/server/container_create.go index a244abce30e..f61629011f5 100644 --- a/server/container_create.go +++ b/server/container_create.go @@ -374,9 +374,9 @@ func (s *Server) CreateContainer(ctx context.Context, req *types.CreateContainer return nil, fmt.Errorf("failed to get ID of container with reserved name (%s), after failing to reserve name with %v: %w", ctr.Name(), getErr, getErr) } // if we're able to find the container, and it's created, this is actually a duplicate request - // from a client that does not behave like the kubelet (like crictl) + // Just return that container if reservedCtr := s.GetContainer(reservedID); reservedCtr != nil && reservedCtr.Created() { - return nil, err + return &types.CreateContainerResponse{ContainerId: reservedID}, nil } cachedID, resourceErr := s.getResourceOrWait(ctx, ctr.Name(), "container") if resourceErr == nil { diff --git a/server/sandbox_run_linux.go b/server/sandbox_run_linux.go index ba9e84e75e4..3ce88c397c2 100644 --- a/server/sandbox_run_linux.go +++ b/server/sandbox_run_linux.go @@ -368,9 +368,9 @@ func (s *Server) runPodSandbox(ctx context.Context, req *types.RunPodSandboxRequ return nil, fmt.Errorf("failed to get ID of pod with reserved name (%s), after failing to reserve name with %v: %w", sbox.Name(), getErr, getErr) } // if we're able to find the sandbox, and it's created, this is actually a duplicate request - // from a client that does not behave like the kubelet (like crictl) + // Just return that sandbox if reservedSbox := s.GetSandbox(reservedID); reservedSbox != nil && reservedSbox.Created() { - return nil, err + return &types.RunPodSandboxResponse{PodSandboxId: reservedID}, nil } cachedID, resourceErr := s.getResourceOrWait(ctx, sbox.Name(), "sandbox") if resourceErr == nil { diff --git a/test/timeout.bats b/test/timeout.bats index fbcdbdeb51b..2c08c695381 100644 --- a/test/timeout.bats +++ b/test/timeout.bats @@ -159,10 +159,11 @@ function wait_clean() { @test "should not wait for actual duplicate pod request" { start_crio - crictl runp "$TESTDATA"/sandbox_config.json + pod_1=$(crictl runp "$TESTDATA"/sandbox_config.json) SECONDS=0 - ! crictl runp "$TESTDATA"/sandbox_config.json + pod_2=$(crictl runp "$TESTDATA"/sandbox_config.json) [[ "$SECONDS" -lt 240 ]] + [[ "$pod_1" == "$pod_2" ]] } @test "should clean up container after timeout if not re-requested" {