Skip to content

Commit 7134b03

Browse files
saschagrunertk8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
Make StopContainer RPC idempotent
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]>
1 parent 21a0a1f commit 7134b03

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: pkg/cri/server/container_stop.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ func (c *criService) StopContainer(ctx context.Context, r *runtime.StopContainer
3939
// Get container config from container store.
4040
container, err := c.containerStore.Get(r.GetContainerId())
4141
if err != nil {
42-
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", r.GetContainerId(), err)
42+
if !errdefs.IsNotFound(err) {
43+
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", r.GetContainerId(), err)
44+
}
45+
46+
// The StopContainer RPC is idempotent, and must not return an error if
47+
// the container has already been stopped. Ref:
48+
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L67-L68
49+
return &runtime.StopContainerResponse{}, nil
4350
}
4451

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

0 commit comments

Comments
 (0)