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

pull the image with the <image>@<digest> format #4256

Merged
merged 1 commit into from
Aug 12, 2024
Merged

Conversation

Yiyuanzzz
Copy link
Contributor

@Yiyuanzzz Yiyuanzzz commented Jul 24, 2024

Summary

Currently, when agent receives a container image with a tag, the agent first attempts to resolve that tag to its digest. If successful, that digest is sent back to the control plane, while subsequently pulling and launching that image via digest rather than the original tag. This behavior results in the container being shown as launched with the <image>@<digest> rather than the customer defined <image>:<tag> format , so customers have lost information previously available to them, notably the image tag, thus Control Plane will be changing image@sha256:abcd to image:latest@sha256:abcd for subsequence tasks.

  • On newer Docker versions (>= 1.13), Docker simply ignores the tag during image pull.
    docker image pull busybox:latest@sha256:abcd is the same as docker image pull busybox@sha256:abcd
  • On older Docker versions (< 1.13), the behavior is to fail pulling the image IFF the manifest does not match the tag, potentially resulting in an image pull failure for customers who’s tags no longer matches the digest. So, Agent should ignore the tag when pulling the image. Just like how newer Docker versions do.

This pr makes agent to pull the image with the <image>@<digest> format instead of <image>:tag@<digest> format no matter what docker version is used

Implementation details

  • Update methodCanonicalRef agent/utils/reference package that returns a canonical image reference without tag given an image reference and a manifest digest.
  • Add a new methodDigestExists agent/utils/reference package that check if image reference contains digest
  • Update *DockerTaskEngine.pullAndUpdateContainerReference method that is used for pulling container images so that it uses the container's image reference to prepare a canonical reference without tag to the image to be pulled when image name contains tag and digest e.t.<image>:tag@<digest>. The method tags the pulled image with Container.Image if a different image reference was used to pull the image and container image name not contains digest (<image>:tag@<digest> will not be tagged)
  • Test updates and new tests.

Testing

  • updated TestPullContainerWithAndWithoutDigestInteg to check that *DockerTaskEngine.pullContainer can pull images for containers with <image>:tag@<digest> format
  • update *DockerTaskEngine.pullContainer pulls the same image with or without a tag and the image can be inspected with container.Image field in both cases.
  • Ran tasks with image in <image>@<digest>, <image>:tag> and <image>:tag@<digest>format with an Agent built with changes in this PR, Checked that all tasks ran as expected. Images were pulled using digests and tagged with the image reference in the task definition.
  • Create a service with desired task count 2 with image <image>:tag>, verified that a additional STSC is not being made for the second task.

New tests cover the changes:

Description for the changelog

Does this PR include breaking model changes? If so, Have you added transformation functions?

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Yiyuanzzz Yiyuanzzz requested a review from a team as a code owner July 24, 2024 22:20
@Yiyuanzzz Yiyuanzzz force-pushed the tss-tag branch 3 times, most recently from acc0bb8 to 1dec67c Compare July 26, 2024 06:11
@Yiyuanzzz Yiyuanzzz changed the title [wip]pull the image with the <image>@<digest> format pull the image with the <image>@<digest> format Jul 26, 2024
agent/api/container/container_test.go Outdated Show resolved Hide resolved
agent/engine/docker_task_engine.go Outdated Show resolved Hide resolved
agent/api/container/container.go Outdated Show resolved Hide resolved
agent/engine/docker_task_engine.go Show resolved Hide resolved
agent/engine/docker_task_engine_test.go Outdated Show resolved Hide resolved
agent/utils/reference/reference.go Outdated Show resolved Hide resolved
agent/engine/docker_task_engine.go Show resolved Hide resolved
agent/engine/engine_integ_test.go Outdated Show resolved Hide resolved
agent/api/container/container.go Show resolved Hide resolved
image := "ubuntu@sha256:ed6d2c43c8fbcd3eaa44c9dab6d94cb346234476230dc1681227aa72d07181ee"
assert.False(t, (&Container{Image: image}).DigestResolutionRequired())
imageDigest := "sha256:ed6d2c43c8fbcd3eaa44c9dab6d94cb346234476230dc1681227aa72d07181ee"
Copy link
Contributor

Choose a reason for hiding this comment

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

Referencing to the previous comment, can there be case where we have image but not imageDigest? What should be the expected behavior in that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

(non blocking) nit: we may consider adding unit test case for the above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants