Skip to content

Commit 74f2f1b

Browse files
authored
Merge pull request containerd#10530 from k8s-infra-cherrypick-robot/cherry-pick-10521-to-release/1.6
[release/1.6] Make `StopContainer` RPC idempotent
2 parents f8c9d89 + 7134b03 commit 74f2f1b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/cri/server/container_stop.go

Lines changed: 8 additions & 1 deletion
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)