Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIT-2663: optimized image load with re-tag support #2786

Conversation

harshanarayana
Copy link
Contributor

@harshanarayana harshanarayana commented May 25, 2022

Currently, the way the kind load docker-image works is by detecting if there is an image with a matching image name and tab already exists in the cluster. However it is possible that the same image might be already present in the cluster with a different tag.

With ctr 1.3.0+ supporting ctr image tag feature, we can avoid loading the images by just re-tagging the image hash with the new name.

Current changes fallback to using the default mode it currently has on following cases to retain compatibility.

  1. If the ctr in the kind image is not supporting ctr images tag command
  2. If the command to retrieve the RepoTags from Image ID runs into an error
  3. If the Image ID itself is missing on the node
  4. In case if the re-tag fails, it will fall back to loading the image all over again like the current workflow

Closes #2663

Missing Image

❯ bin/kind load docker-image --name helm-test docker.io/library/ubuntu:18.04
Image: "ubuntu:18.04" with ID "sha256:c6ad7e71ba7d4969784c76f57c4cc9083aa96bb969d802f2ea38f4aaed90ff93" not yet present on node "helm-test-control-plane", loading...

Image Exists with Different Tag and Name

❯ bin/kind load docker-image --name helm-test docker.io/library/different-repo-ubuntu:18.04
Image with ID: sha256:c6ad7e71ba7d4969784c76f57c4cc9083aa96bb969d802f2ea38f4aaed90ff93 already present on the node helm-test-control-plane but is missing the tag different-repo-ubuntu:18.04. re-tagging...

No image re-tag or load required

❯ bin/kind load docker-image --name helm-test docker.io/library/different-repo-ubuntu:18.04                                                                                                                                                                        
Image: "docker.io/library/different-repo-ubuntu:18.04" with ID "sha256:c6ad7e71ba7d4969784c76f57c4cc9083aa96bb969d802f2ea38f4aaed90ff93" found to be already present on all nodes.

Sanitizing Registry Images

❯ kind load docker-image --name upstream-k8s kind/test-ubuntu:1.2.3
Image with ID: sha256:c6ad7e71ba7d4969784c76f57c4cc9083aa96bb969d802f2ea38f4aaed90ff93 already present on the node upstream-k8s-control-plane but is missing the tag kind/test-ubuntu:1.2.3. re-tagging...

root@upstream-k8s-control-plane:/# crictl images | grep ubun | grep kind
docker.io/kind/test-ubuntu                            1.2.3                                      c6ad7e71ba7d4       65.5MB

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 25, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @harshanarayana!

It looks like this is your first PR to kubernetes-sigs/kind 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kind has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 25, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @harshanarayana. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

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.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 25, 2022
@harshanarayana harshanarayana force-pushed the feature/GIT-2663/optimize-image-load branch 2 times, most recently from e029852 to 29634dc Compare May 25, 2022 15:11
@BenTheElder
Copy link
Member

Thanks for the PR 😄

With ctr 1.3.0+ supporting ctr image tag feature, we can avoid loading the images by just re-tagging the image hash with the new name.

1.3.0 is older than I thought, we've had 1.3.0+ for a very long time, let's drop the check.

In case if the re-tag fails, it will fall back to loading the image all over again like the current workflow

Trying to imagine a scenario where this makes sense 🤔
What were you thinking would happen in this case?

Containerd internally tracks the docker images with docker.io/library which can be missing on the local image cache. In such cases, the detection of duplicate image just re-tags the image again. This is only when the dockerhub images are loaded without docker.io/library prefix.

This is going to be common, we should handle this translation.
Kubernetes also does this internally, it is carried over from docker.

We need to take care to remember that while containerd does this, in podman on the host side the default registry is actually configurable, so we should only perform this normalization when interacting with containerd.

@harshanarayana
Copy link
Contributor Author

@BenTheElder Thanks for the quick review and feedbacks.

let's drop the check.

All righty. Let me take care of that.

What were you thinking would happen in this case?

Thinking about worst or the worst cases such as containerd getting restarted causing re-tag to fail or some other docker issue causing the command invocation on the container to fail. Just a precaution. Instead of returning an error, I am doing the next best thing of reloading again. Or do you think it is enough to return an error? Since we use the --force argument with ctr if the tag already exists, it will handle it and not return an error. So other than the worst case I mentioned above, I can't think of any other reason why ctr images tag would fail.

This is going to be common, we should handle this translation.

Sure. Let me take care of it. So, all we need to do is when the ID to repoTag match is being done, in the image if the registry part is missing, we default to docker.io/library and process it. Right ? Or do you see any other special handling to be done ?

@k8s-ci-robot k8s-ci-robot added area/provider/podman Issues or PRs related to podman size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 26, 2022
@harshanarayana
Copy link
Contributor Author

This is going to be common, we should handle this translation.

Refactored a bit of code that podman provider had into a common utils and using that in both places now. Relocated the tests as well to address the changes accordingly.

@harshanarayana
Copy link
Contributor Author

@BenTheElder PTAL when you can. Changes have been addressed

@harshanarayana harshanarayana marked this pull request as ready for review June 2, 2022 11:52
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 2, 2022
@k8s-ci-robot k8s-ci-robot requested a review from amwat June 2, 2022 11:52
@harshanarayana
Copy link
Contributor Author

/cc @BenTheElder

@BenTheElder
Copy link
Member

Sorry, I've been out and mostly unavailable.

Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

one major nit, thanks for working on this
cc @aojea to help keep after reviews

pkg/cluster/nodeutils/util.go Outdated Show resolved Hide resolved
@harshanarayana harshanarayana force-pushed the feature/GIT-2663/optimize-image-load branch from 3bc6249 to a911f33 Compare June 10, 2022 16:21
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 10, 2022
@harshanarayana
Copy link
Contributor Author

@BenTheElder @aojea PTAL at this PR when time permits. I've updated the changes as suggested by @BenTheElder

@harshanarayana harshanarayana force-pushed the feature/GIT-2663/optimize-image-load branch 3 times, most recently from 71340aa to e93e714 Compare June 23, 2022 06:27
@harshanarayana harshanarayana force-pushed the feature/GIT-2663/optimize-image-load branch from e93e714 to d0fe0ad Compare June 24, 2022 04:44
@harshanarayana
Copy link
Contributor Author

/test pull-kind-build

@@ -37,6 +38,10 @@ import (
"sigs.k8s.io/kind/pkg/internal/runtime"
)

var (
imageTagFetcher = nodeutils.ImageTags
Copy link
Member

Choose a reason for hiding this comment

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

instead of a global, we can pass the function, or split the function under test into two and pass the results of calling this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me refactor is to pass the function across and use that instead. Would make it cleaner.

@harshanarayana harshanarayana force-pushed the feature/GIT-2663/optimize-image-load branch 2 times, most recently from 3cdda28 to 3921058 Compare June 24, 2022 06:04
@harshanarayana
Copy link
Contributor Author

harshanarayana commented Jun 24, 2022

❯ ./kind load docker-image --name test-cluster ubuntu:18.04
Image: "ubuntu:18.04" with ID "sha256:c6ad7e71ba7d4969784c76f57c4cc9083aa96bb969d802f2ea38f4aaed90ff93" not yet present on node "test-cluster-control-plane", loading...

❯ ./kind load docker-image --name test-cluster kind/test-ubuntu:1.2.3
Image with ID: sha256:c6ad7e71ba7d4969784c76f57c4cc9083aa96bb969d802f2ea38f4aaed90ff93 already present on the node test-cluster-control-plane but is missing the tag kind/test-ubuntu:1.2.3. re-tagging...

❯ ./kind load docker-image --name test-cluster different-repo-ubuntu
ERROR: image: "different-repo-ubuntu" not present locally

❯ ./kind load docker-image --name test-cluster different-repo-ubuntu:18.04
Image with ID: sha256:c6ad7e71ba7d4969784c76f57c4cc9083aa96bb969d802f2ea38f4aaed90ff93 already present on the node test-cluster-control-plane but is missing the tag different-repo-ubuntu:18.04. re-tagging...
root@test-cluster-control-plane:/# crictl images | grep ubun
docker.io/library/ubuntu                   18.04                c6ad7e71ba7d4       65.5MB

root@test-cluster-control-plane:/# crictl images | grep ubun
docker.io/kind/test-ubuntu                 1.2.3                c6ad7e71ba7d4       65.5MB
docker.io/library/ubuntu                   18.04                c6ad7e71ba7d4       65.5MB

root@test-cluster-control-plane:/# crictl images | grep ubun
docker.io/kind/test-ubuntu                 1.2.3                c6ad7e71ba7d4       65.5MB
docker.io/library/different-repo-ubuntu    18.04                c6ad7e71ba7d4       65.5MB
docker.io/library/ubuntu                   18.04                c6ad7e71ba7d4       65.5MB
root@test-cluster-control-plane:/#

@BenTheElder
Copy link
Member

Thank you for working on this, very sorry I've been so unavailable at the moment and not getting back to this reasonably.

I will be on vacation for a few weeks and then my work situation will change a bit. antonio can hopefully pick up remaining review / bikeshed :-)

@harshanarayana harshanarayana force-pushed the feature/GIT-2663/optimize-image-load branch from 3921058 to 1e12339 Compare July 8, 2022 14:30
GIT-2663: sanitizeImage function to help generate fully qualified image names

GIT-2663: sanitizeImage function to help generate fully qualified image names

GIT-2663: add comments for sanitizeImage function and add UTs

GIT-2663: add comments for sanitizeImage function and add UTs

GIT-2663: add comments for sanitizeImage function and add UTs

GIT-2663: add comments for sanitizeImage function and add UTs

GIT-2663: add comments for sanitizeImage function and add UTs

GIT-2663: add comments for sanitizeImage function and add UTs

GIT-2663: cleanup image retag required check

GIT-2663: cleanup image retag required check
@harshanarayana harshanarayana force-pushed the feature/GIT-2663/optimize-image-load branch from 1e12339 to d1c2a79 Compare July 8, 2022 14:37
@harshanarayana
Copy link
Contributor Author

/test pull-kind-e2e-kubernetes-1-20

@harshanarayana
Copy link
Contributor Author

/test pull-kind-e2e-kubernetes

@harshanarayana
Copy link
Contributor Author

@aojea @BenTheElder PTAL when time permits. The suggested changes have been addressed.

@harshanarayana
Copy link
Contributor Author

/test pull-kind-e2e-kubernetes

Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@BenTheElder BenTheElder added this to the v0.15.0 milestone Aug 2, 2022
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 2, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BenTheElder, harshanarayana

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 2, 2022
@harshanarayana
Copy link
Contributor Author

/test pull-kind-e2e-kubernetes

@k8s-ci-robot k8s-ci-robot merged commit 8179056 into kubernetes-sigs:main Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/provider/podman Issues or PRs related to podman cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kind load docker-image should add a tag instead of loading the image when possible
4 participants