Skip to content

Commit 95d3155

Browse files
Kirtana AshokKirtana Ashok
authored andcommitted
Remove entry for container from container store on error
If containerd does not see a container but criservice's container store does, then we should try to recover from this error state by removing the container from criservice's container store as well. Signed-off-by: Kirtana Ashok <[email protected]> (cherry picked from commit d9f3e38) Signed-off-by: Kirtana Ashok <[email protected]>
1 parent ee0637a commit 95d3155

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pkg/cri/server/container_remove.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,29 @@ import (
3333
// RemoveContainer removes the container.
3434
func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveContainerRequest) (_ *runtime.RemoveContainerResponse, retErr error) {
3535
start := time.Now()
36-
container, err := c.containerStore.Get(r.GetContainerId())
36+
ctrID := r.GetContainerId()
37+
container, err := c.containerStore.Get(ctrID)
3738
if err != nil {
3839
if !errdefs.IsNotFound(err) {
39-
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", r.GetContainerId(), err)
40+
return nil, fmt.Errorf("an error occurred when try to find container %q: %w", ctrID, err)
4041
}
4142
// Do not return error if container metadata doesn't exist.
42-
log.G(ctx).Tracef("RemoveContainer called for container %q that does not exist", r.GetContainerId())
43+
log.G(ctx).Tracef("RemoveContainer called for container %q that does not exist", ctrID)
4344
return &runtime.RemoveContainerResponse{}, nil
4445
}
4546
id := container.ID
4647
i, err := container.Container.Info(ctx)
4748
if err != nil {
48-
return nil, fmt.Errorf("get container info: %w", err)
49+
if !errdefs.IsNotFound(err) {
50+
return nil, fmt.Errorf("get container info: %w", err)
51+
}
52+
// Since containerd doesn't see the container and criservice's content store does,
53+
// we should try to recover from this state by removing entry for this container
54+
// from the container store as well and return successfully.
55+
log.G(ctx).WithError(err).Warn("get container info failed")
56+
c.containerStore.Delete(ctrID)
57+
c.containerNameIndex.ReleaseByKey(ctrID)
58+
return &runtime.RemoveContainerResponse{}, nil
4959
}
5060

5161
// Forcibly stop the containers if they are in running or unknown state

0 commit comments

Comments
 (0)