Skip to content

Commit

Permalink
Merge pull request containerd#10527 from saschagrunert/10520-1.7
Browse files Browse the repository at this point in the history
[release/1.7] Make `StopPodSandbox` RPC idempotent
  • Loading branch information
kzys authored Jul 31, 2024
2 parents 2096604 + b3b6f15 commit 93416bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pkg/cri/sbserver/sandbox_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"time"

"github.com/containerd/errdefs"
"github.com/containerd/log"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"

Expand All @@ -33,8 +34,15 @@ import (
func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (*runtime.StopPodSandboxResponse, error) {
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
if err != nil {
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w",
r.GetPodSandboxId(), err)
if !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w",
r.GetPodSandboxId(), err)
}

// The StopPodSandbox RPC is idempotent, and must not return an error
// if all relevant resources have already been reclaimed. Ref:
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L45-L46
return &runtime.StopPodSandboxResponse{}, nil
}

if err := c.stopPodSandbox(ctx, sandbox); err != nil {
Expand Down
11 changes: 9 additions & 2 deletions pkg/cri/server/sandbox_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ import (
func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (*runtime.StopPodSandboxResponse, error) {
sandbox, err := c.sandboxStore.Get(r.GetPodSandboxId())
if err != nil {
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w",
r.GetPodSandboxId(), err)
if !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("an error occurred when try to find sandbox %q: %w",
r.GetPodSandboxId(), err)
}

// The StopPodSandbox RPC is idempotent, and must not return an error
// if all relevant resources have already been reclaimed. Ref:
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L45-L46
return &runtime.StopPodSandboxResponse{}, nil
}

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

0 comments on commit 93416bd

Please sign in to comment.