Skip to content

Commit

Permalink
Merge pull request containerd#10528 from saschagrunert/10521-1.7
Browse files Browse the repository at this point in the history
[release/1.7]  Make `StopContainer` RPC idempotent
  • Loading branch information
kzys authored Jul 31, 2024
2 parents 93416bd + 6da4e40 commit 97a5245
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/cri/sbserver/container_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func (c *criService) StopContainer(ctx context.Context, r *runtime.StopContainer
// Get container config from container store.
container, err := c.containerStore.Get(r.GetContainerId())
if err != nil {
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", r.GetContainerId(), err)
if !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", r.GetContainerId(), err)
}

// The StopContainer RPC is idempotent, and must not return an error if
// the container has already been stopped. Ref:
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L67-L68
return &runtime.StopContainerResponse{}, nil
}

if err := c.stopContainer(ctx, container, time.Duration(r.GetTimeout())*time.Second); err != nil {
Expand Down
9 changes: 8 additions & 1 deletion pkg/cri/server/container_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func (c *criService) StopContainer(ctx context.Context, r *runtime.StopContainer
// Get container config from container store.
container, err := c.containerStore.Get(r.GetContainerId())
if err != nil {
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", r.GetContainerId(), err)
if !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", r.GetContainerId(), err)
}

// The StopContainer RPC is idempotent, and must not return an error if
// the container has already been stopped. Ref:
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L67-L68
return &runtime.StopContainerResponse{}, nil
}

if err := c.stopContainer(ctx, container, time.Duration(r.GetTimeout())*time.Second); err != nil {
Expand Down

0 comments on commit 97a5245

Please sign in to comment.