Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Container life cycle should not rely on the existence of other image references. #990

Closed
Random-Liu opened this issue Dec 6, 2018 · 4 comments · Fixed by #991
Closed
Labels
Milestone

Comments

@Random-Liu
Copy link
Member

Random-Liu commented Dec 6, 2018

Containerd manages images based on references. Image names (tag, id etc.), container references are all valid independent references.

They are independent, means that you can remove all image references, and the container can still run happily because the snapshots are still referenced. This also means that we can't assume image references (and the content) exist across the whole life cycle of a container using the image.

However, we are doing so in some container operations:

This causes issue like containerd/containerd#2858.

There are 2 options to fix this:

  • Option 1: Add logic in the cri plugin to avoid deleting image references when container is still using an image.
    • Problem 1: This is racy. It is always possible that after you check and make sure that an image is not in use, a new container is created referencing the image. Need to add synchronization for this case.
    • Problem 2: Users can always delete image references by talking with containerd directly. We don't have any control to that.
  • Option 2: Always assume that image reference may be gone after container creation, and never rely on it in the container lifecycle.

Given the problem of option 1, I prefer option 2.

For option 2:

  1. For StopContainer, only StopSignal is needed, we should add it into container metadata during container creation;
  2. For ContainerStatus, the image id to tag conversion is best effort anyway, just don't return error.

Note that adding StopSignal into metadata is adding a new field into our metadata checkpoint. We should handle in place upgrade properly.

@mikebrow
Copy link
Member

mikebrow commented Dec 6, 2018

agree option 2

@Random-Liu
Copy link
Member Author

Random-Liu commented Dec 7, 2018

At a second thought, I think we need both option 1 and 2.

We need option 1, because that is Docker's behavior, I think people expect that in crictl. And even for Kubernetes garbage collection, it is an important piece to avoid race condition:

  1. Kubelet compares container and image list, and find an unused image;
  2. New container created using the image;
  3. Kubelet garbage collects the image.

Currently, for Docker, 3) will fail; but for containerd 3) will remove the image.

We still need option 2, because users may still use ctr to remove the image. That is not expected behavior, but we should live with it, at least container lifecycle shouldn't be affected. And because that is caused by unexpected behavior, I think it is fine to not handle #991 (comment).

And I think we should cherry-pick option 2 into supported branches, because it is low risk and fixes issues in most cases. We can only keep option 1 in master.

@mikebrow
Copy link
Member

mikebrow commented Dec 7, 2018

ok, thx for investigating! agree option 1 with tolerance for option 2.

@mikebrow
Copy link
Member

mikebrow commented Dec 7, 2018

suggest adding an issue to enable the garbage collect of the in use image.. (breaking the behavior exhibited by docker in refusing to remove images in use)

thaJeztah added a commit to thaJeztah/containerd that referenced this issue Feb 13, 2019
…06d9200e95

includes backports of:

- containerd/cri#984 filter events for non k8s.io namespaces (resolves firecracker-microvm/firecracker-containerd#35)
- containerd/cri#991 Remove container lifecycle image dependency (fixes containerd/cri#990)
- containerd/cri#1016 [release/1.0] Specify platform for image pull (fixes containerd/cri#1015)
- containerd/cri#1027 Fix the log ending newline handling (fixes containerd/cri#1026)
- containerd/cri#1042 Set /etc/hostname (fixes containerd/cri#1041)
- containerd/cri#1045 Fix env performance issue (fixes containerd/cri#1044)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants