Merge pull request #10521 from saschagrunert/idempotence-ctr

Make `StopContainer` RPC idempotent
This commit is contained in:
Maksym Pavlenko 2024-07-30 20:12:26 +00:00 committed by GitHub
commit 7bcc78526d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,9 +40,16 @@ func (c *criService) StopContainer(ctx context.Context, r *runtime.StopContainer
// Get container config from container store. // Get container config from container store.
container, err := c.containerStore.Get(r.GetContainerId()) container, err := c.containerStore.Get(r.GetContainerId())
if err != nil { if err != nil {
if !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", r.GetContainerId(), 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 { if err := c.stopContainer(ctx, container, time.Duration(r.GetTimeout())*time.Second); err != nil {
return nil, err return nil, err
} }