Skip to content

Commit

Permalink
Make StopContainer RPC idempotent
Browse files Browse the repository at this point in the history
Similar to container removal, the stop of a container should be a noop if
the container has not been found.

Found during: kubernetes-sigs/cri-tools#1536

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Jul 31, 2024
1 parent 54b9c74 commit da80406
Showing 1 changed file with 8 additions and 1 deletion.
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 da80406

Please sign in to comment.