Skip to content

Commit b3b6f15

Browse files
committed
Make StopPodSandbox RPC idempotent
Similar to sandbox removal, the stop of a sandbox should be a noop if the sandbox has not been found. Found during: kubernetes-sigs/cri-tools#1535 Signed-off-by: Sascha Grunert <[email protected]> (cherry picked from commit c6cea95) Signed-off-by: Sascha Grunert <[email protected]>
1 parent 54b9c74 commit b3b6f15

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pkg/cri/sbserver/sandbox_stop.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"time"
2424

25+
"github.com/containerd/errdefs"
2526
"github.com/containerd/log"
2627
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
2728

@@ -33,8 +34,15 @@ import (
3334
func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (*runtime.StopPodSandboxResponse, error) {
3435
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
3536
if err != nil {
36-
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w",
37-
r.GetPodSandboxId(), err)
37+
if !errdefs.IsNotFound(err) {
38+
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w",
39+
r.GetPodSandboxId(), err)
40+
}
41+
42+
// The StopPodSandbox RPC is idempotent, and must not return an error
43+
// if all relevant resources have already been reclaimed. Ref:
44+
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L45-L46
45+
return &runtime.StopPodSandboxResponse{}, nil
3846
}
3947

4048
if err := c.stopPodSandbox(ctx, sandbox); err != nil {

pkg/cri/server/sandbox_stop.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ import (
3838
func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (*runtime.StopPodSandboxResponse, error) {
3939
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
4040
if err != nil {
41-
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w",
42-
r.GetPodSandboxId(), err)
41+
if !errdefs.IsNotFound(err) {
42+
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w",
43+
r.GetPodSandboxId(), err)
44+
}
45+
46+
// The StopPodSandbox RPC is idempotent, and must not return an error
47+
// if all relevant resources have already been reclaimed. Ref:
48+
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L45-L46
49+
return &runtime.StopPodSandboxResponse{}, nil
4350
}
4451

4552
if err := c.stopPodSandbox(ctx, sandbox); err != nil {

0 commit comments

Comments
 (0)