Skip to content

parsing ref consistently for refCache, including adding docker.io/library prefix#7728

Closed
pacoxu wants to merge 3 commits intocontainerd:mainfrom
pacoxu:image-clean
Closed

parsing ref consistently for refCache, including adding docker.io/library prefix#7728
pacoxu wants to merge 3 commits intocontainerd:mainfrom
pacoxu:image-clean

Conversation

@pacoxu
Copy link
Copy Markdown
Contributor

@pacoxu pacoxu commented Nov 28, 2022

Fixes #7698

For the refCache below, the ref needs to be consistent.

There is a test case in #7698, I can quickly reproduce it with the second method there.

Before restarting and importing image, the refCahe is using ref: import-2022-11-28@sha256:c8a01d8610c642f0e6b83af5f6185b3eed34e322354be5a515da1a21453ac966" and crictl cannot remove it correctly.

After restarting containerd, the cache became ref: docker.io/library/import-2022-11-28@sha256:c8a01d8610c642f0e6b83af5f6185b3eed34e322354be5a515da1a21453ac966" and crictl can remove it correctly.


I add another cleanup in services/images/local.go without docker.io/library/ prefix.

@k8s-ci-robot
Copy link
Copy Markdown

Hi @pacoxu. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@pacoxu pacoxu changed the title crictl remove images: clean refCache during removing [wip]crictl remove images: clean refCache during removing Nov 28, 2022
@pacoxu pacoxu changed the title [wip]crictl remove images: clean refCache during removing parsing ref consistently for refCache, including adding docker.io/library prefix Nov 28, 2022
@pacoxu
Copy link
Copy Markdown
Contributor Author

pacoxu commented Nov 28, 2022

/cc @pmengelbert
for the issue

/cc @mxpv @dmcgowan
for you are recent contributors pkg/cri/store/image/image.go

@k8s-ci-robot
Copy link
Copy Markdown

@pacoxu: GitHub didn't allow me to request PR reviews from the following users: pmengelbert.

Note that only containerd members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @pmengelbert
for the issue

/cc @mxpv @dmcgowan
for you are recent contributors pkg/cri/store/image/image.go

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@pacoxu
Copy link
Copy Markdown
Contributor Author

pacoxu commented Nov 29, 2022

@sozercan
Copy link
Copy Markdown

sozercan commented Dec 1, 2022

/cc @cpuguy83

@k8s-ci-robot k8s-ci-robot requested a review from cpuguy83 December 1, 2022 18:52
Comment thread pkg/cri/store/image/image.go Outdated
@ruiwen-zhao
Copy link
Copy Markdown
Member

Mostly for my own education, can you help me understand why restarting containerd changed the ref in the cache? Is another path of code triggered upon containerd start?

@pacoxu
Copy link
Copy Markdown
Contributor Author

pacoxu commented Dec 5, 2022

Mostly for my own education, can you help me understand why restarting containerd changed the ref in the cache? Is another path of code triggered upon containerd start?

As I described in #7728 (comment), when we first import it with ctr, ref cache add cache with prefix.

Or we can fix it during import only?

@ruiwen-zhao
Copy link
Copy Markdown
Member

Mostly for my own education, can you help me understand why restarting containerd changed the ref in the cache? Is another path of code triggered upon containerd start?

As I described in #7728 (comment), when we first import it with ctr, ref cache add cache with prefix.

Or we can fix it during import only?

Sorry maybe I am misunderstanding the issue here. According to #7698 and section "II. Manually load an image with --digests=true", the issue seems to be that crictl only removes repoTags but fails to remove the actual image, which seems to be problematic because cri attempts to remove all refereneces [1]. Is my understanding correct? If so then we should try to fix cri's image removal, no?

[1] https://github.com/containerd/containerd/blob/main/pkg/cri/server/image_remove.go#L49

@pacoxu
Copy link
Copy Markdown
Contributor Author

pacoxu commented Dec 14, 2022

I did some tests with some more logs.

The first crictl rmi $imgeid shows all ref removing are triggered. But import image is not deleted indeed.

12月 14 17:46:15 paco-centos-9 containerd[4192410]: time="2022-12-14T17:46:15.735311390+08:00" level=debug msg="image remove i 0,ref docker.io/library/hello:world"
12月 14 17:46:15 paco-centos-9 containerd[4192410]: time="2022-12-14T17:46:15.735862343+08:00" level=debug msg="image remove Delete err <nil>"
12月 14 17:46:15 paco-centos-9 containerd[4192410]: time="2022-12-14T17:46:15.735974214+08:00" level=debug msg="image remove i 1,ref docker.io/library/import-2022-12-14@sha256:a0010348fb08fdacb9c3fbe798e18d20c19e98aeb3c3bf7c471279f63ab1ee59"
12月 14 17:46:15 paco-centos-9 containerd[4192410]: time="2022-12-14T17:46:15.736032431+08:00" level=debug msg="image remove Delete err image \"docker.io/library/import-2022-12-14@sha256:a0010348fb08fdacb9c3fbe798e18d20c19e98aeb3c3bf7c471279f63ab1ee59\": not found"
12月 14 17:46:15 paco-centos-9 containerd[4192410]: time="2022-12-14T17:46:15.736090162+08:00" level=debug msg="image remove i 2,ref docker.io/library/import-2022-12-14@sha256:a0010348fb08fdacb9c3fbe798e18d20c19e98aeb3c3bf7c471279f63ab1ee59"
12月 14 17:46:15 paco-centos-9 containerd[4192410]: time="2022-12-14T17:46:15.736120975+08:00" level=debug msg="image remove Delete err image \"docker.io/library/import-2022-12-14@sha256:a0010348fb08fdacb9c3fbe798e18d20c19e98aeb3c3bf7c471279f63ab1ee59\": not found"
12月 14 17:46:15 paco-centos-9 containerd[4192410]: time="2022-12-14T17:46:15.736145294+08:00" level=debug msg="image remove i 3,ref sha256:c55b4d09bd7bbc82fec32fe98a363c99f476cc6c5eaed89968aaadc1f84e443e"
12月 14 17:46:15 paco-centos-9 containerd[4192410]: time="2022-12-14T17:46:15.744530837+08:00" level=debug msg="image remove Delete err <nil>"

After restarting containerd, the removing is done when runnging crictl rmi $imgeid.

12月 14 17:34:03 paco-centos-9 containerd[4192410]: time="2022-12-14T17:34:03.709711741+08:00" level=debug msg="Loaded image \"import-2022-12-14@sha256:a0010348fb08fdacb9c3fbe798e18d20c19e98aeb3c3bf7c471279f63ab1ee59\""
12月 14 17:34:16 paco-centos-9 containerd[4192410]: time="2022-12-14T17:34:16.171106366+08:00" level=debug msg="image remove i 0,ref import-2022-12-14@sha256:a0010348fb08fdacb9c3fbe798e18d20c19e98aeb3c3bf7c471279f63ab1ee59"
12月 14 17:34:16 paco-centos-9 containerd[4192410]: time="2022-12-14T17:34:16.171214731+08:00" level=debug msg="delete image" name="import-2022-12-14@sha256:a0010348fb08fdacb9c3fbe798e18d20c19e98aeb3c3bf7c471279f63ab1ee59"

@pacoxu
Copy link
Copy Markdown
Contributor Author

pacoxu commented Dec 14, 2022

It seems that the local image removing is without docker.io/library/ prefix.

BTW,

  • nerdctl inspect shows no docker.io/library/ prefix.
  • crictl inspect shows docker.io/library/ prefix.
  • ctr i ls shows no docker.io/library/ prefix.

@pacoxu
Copy link
Copy Markdown
Contributor Author

pacoxu commented Dec 14, 2022

So I add another cleanup in services/images/local.go without docker.io/library/ prefix.

Comment thread pkg/cri/store/image/image.go Outdated
Comment thread services/images/local.go Outdated

if err := l.store.Delete(ctx, req.Name); err != nil {
return nil, errdefs.ToGRPC(err)
if strings.HasPrefix(req.Name, "docker.io/library/") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about this change. This service doesn't do any caching. Does it have to worry about the prefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is related to

  • nerdctl inspect shows no docker.io/library/ prefix.
  • crictl inspect shows docker.io/library/ prefix.
  • ctr i ls shows no docker.io/library/ prefix.

When the user removes an image thought crictl, it adds a prefix for it by default.

  • So I have to double-check to delete the image without the prefix here as well.

If docker.io/library/xxx:yyy equals xxx:yyy, this logic change will have no side effect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to say: don't strip it (unless this is causing severe issues). Stripping the docker.io/library (and docker.io/) prefixes mostly originates from remaining the UX on docker, which (when there was only 1 registry: the docker index (later "docker hub")), so images had no prefix. ctr probably strips the prefix to have a closer match with docker commands, but for most cases (and APIs), this should probably be considered part of the presentation, not what APIs returns, and make sure the API returns the canonical (full) image reference.

Adding to the above; the docker.io prefix as a whole is causing a lot of headaches (e.g., docker.io is not actually the domain of the registry (which currently is at registry-1.docker.com). We're actively exploring what options we have to get out of this confusing situation (but it's complicated especially to remain backward compatible with existing container runtimes/tools). From that perspective, it'd be good to not introduce more places where special handling is performed (unless there's a strong reason it's needed).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @ingshtrom (FYI)

(for others: @ingshtrom is one of my colleagues at docker exploring options around this 😅)

Copy link
Copy Markdown
Contributor Author

@pacoxu pacoxu Jan 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • nerdctl inspect shows no docker.io/library/ prefix.
  • crictl inspect shows docker.io/library/ prefix.
  • ctr i ls shows no docker.io/library/ prefix.

Another way to fix the issue mentioned is to make crictl not adding the prefix. I need to look into the code if this is doable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nerdctl is designed to provide a UX that matches docker. It should probably be looked at where that UX should be applied. Containerd in itself is (should be) less opinionated, which may mean: always assume canonical references. Some amount of compatibility is probably OK (which may mean convert to (normalise to) a canonical reference on the way in, and leave it to products on top of containerd to decide on the UX they want to provide (which may be "remove the prefix" when presenting).

We should really be careful not to leak docker's UX into containerd.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saved the original change in https://github.com/containerd/containerd/compare/main...pacoxu:image-clean-original?expand=1.

I reverted the docker.io/library trim in services/images/local.go. And I will look into crictl code to see if it can be optimized.

@pacoxu pacoxu requested review from kzys and removed request for ruiwen-zhao December 26, 2022 03:02
@pacoxu
Copy link
Copy Markdown
Contributor Author

pacoxu commented Jan 15, 2023

Comment thread pkg/cri/store/image/image.go Outdated
// the image does not exist in containerd.
func (s *Store) update(ref string, img *Image) error {
// parsing ref consistently for refCache, including adding `docker.io/library` prefix
if !strings.HasPrefix(ref, "sha256:") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@pacoxu pacoxu force-pushed the image-clean branch 3 times, most recently from 089fe40 to 97253bc Compare January 16, 2023 06:23
Comment thread pkg/cri/store/image/image.go Outdated
// the image does not exist in containerd.
func (s *Store) update(ref string, img *Image) error {
refName := strings.Split(ref, ":")[0]
switch refName {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will ref be something like alpine:3.9@sha256:414e0518bb9228d35e4cd5165567fb91d26c6a214e9c95899e1e056fcd349011?

I searched the code a bit and looks like ref here will only be tag or digest or image ID, so we should be fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be tag or digest or image ID here if I understand correctly.

@ruiwen-zhao
Copy link
Copy Markdown
Member

Thanks Paco! LGTM except for the two minor comments.

@ruiwen-zhao
Copy link
Copy Markdown
Member

/lgtm

Comment thread reference/docker/reference_test.go Outdated
@pacoxu pacoxu force-pushed the image-clean branch 2 times, most recently from 542734b to c99fbfb Compare March 8, 2023 09:46
@pacoxu pacoxu marked this pull request as draft March 8, 2023 10:22
@k8s-ci-robot
Copy link
Copy Markdown

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2024

This PR is stale because it has been open 90 days with no activity. This PR will be closed in 7 days unless new comments are made or the stale label is removed.

@github-actions github-actions Bot added the Stale label May 7, 2024
@github-actions
Copy link
Copy Markdown

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done
Archived in project

Development

Successfully merging this pull request may close these issues.

To remove certain images using CRI, containerd requires a restart

7 participants