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

Made the digest exporter report image digest if there is only one image. #1237

Merged
merged 3 commits into from
Sep 6, 2019

Conversation

chhsia0
Copy link
Contributor

@chhsia0 chhsia0 commented Aug 23, 2019

Changes

Currently the image digest exporter does not implemented the behavior described
in resources.md, which says "if there are multiple versions of the image,
the latest will be used." Instead, it reports the digest of index.json, which
is an image index. This behavior introduces a usability issue: one of the major
public container registry --- dockerhub --- does not support OCI image indices,
and there are very few tools (if any) that support converting OCI image indices
to docker manifest lists. E.g., skopeo currently only support pushing an OCI image
index that contains only one image. If the index has more than one images, it
requires the user to specify one:
containers/skopeo#107
containers/image#400

Essentially, these limitations make the image digest exporter less useful. To make
it more usable, the exporter could instead implement the following behavior:

  1. If there is only one image in index.json, report the image's digest.

  2. If there are multiple images, report the digest of the full index.

The advantage of this behavior is that, we can immediately use it (in conjunction
of GoogleContainerTools/kaniko#744), yet if multi-image
manifests are more widely supported in the future, the image digest exporter can
still support that without any modification.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes
are included, additive changes
must be approved by at least two OWNERS
and backwards incompatible changes
must be approved by more than 50% of the OWNERS,
and they must first be added
in a backwards compatible way.

Release Notes

Although the exported digest changes for any single-image index, the the digests of either the index or the image are eventually used to refer to the image, so there should be no actual user impact.

…ne image.

Currently the image digest exporter does not implemented the behavior described
in the resources doc, which says "if there are multiple versions of the image,
the latest will be used." Instead, it reports the digest of `index.json`, which
is an image index. This behavior introduces a usability issue: one of the major
public container registry --- dockerhub --- does not support OCI image indices,
and there are very few tools (if any) that support converting OCI image indices
to docker manifest lists. Skopeo currently only support pushing an OCI image
index that contain only one image. If the index has more than one images, it
requires the user to specify one:
containers/skopeo#107
containers/image#400

Essentially, these limitations make the image digest exporter useless. To make
this feature useful, the exporter could instead implement the following behavior:

1. If there is only one image in `index.json`, report the image's digest.

2. If there are multiple images, report the digest of the full index.

The advantage of this behavior is that, we can immediately use it (in conjunction
of GoogleContainerTools/kaniko#744), yet if multi-image
manifests are more widely supported, the image digest exporter can still support
that without any modification.
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Aug 23, 2019
@tekton-robot tekton-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 23, 2019
@tekton-robot
Copy link
Collaborator

Hi @chhsia0. Thanks for your PR.

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

@chhsia0
Copy link
Contributor Author

chhsia0 commented Aug 23, 2019

/assign @dibyom

@@ -55,9 +56,19 @@ func main() {
log.Printf("ImageResource %s doesn't have an index.json file: %s", imageResource.Name, err)
continue
}
digest, err := ii.Digest()
// If there is only one image in the index, report the digest of the image; otherwise, report the digest of the whole index.
digest, err := func() (v1.Hash, error) {
Copy link

Choose a reason for hiding this comment

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

Suggest moving this to a package-level function, with a name, and passing ii as an argument to it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

and unit tests! :)

Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

+1 to what @sbwsg said, otherwise looks good! Thanks @chhsia0 :D

Also p.s. I think you've seen this already but note that we're probably going to change the way that resourceResults works pretty dramatically in the future (proposal to remove in 0.9 release)

@@ -55,9 +56,19 @@ func main() {
log.Printf("ImageResource %s doesn't have an index.json file: %s", imageResource.Name, err)
continue
}
digest, err := ii.Digest()
// If there is only one image in the index, report the digest of the image; otherwise, report the digest of the whole index.
digest, err := func() (v1.Hash, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

and unit tests! :)

@afrittoli
Copy link
Member

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 28, 2019
@chhsia0
Copy link
Contributor Author

chhsia0 commented Aug 30, 2019

Sorry about the delay. Will add a test and fix the problems on Monday.

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 4, 2019
@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/imagedigestexporter/digest.go Do not exist 83.3%
cmd/imagedigestexporter/main.go Do not exist 0.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/imagedigestexporter/digest.go Do not exist 83.3%
cmd/imagedigestexporter/main.go Do not exist 0.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/imagedigestexporter/digest.go Do not exist 83.3%
cmd/imagedigestexporter/main.go Do not exist 0.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/imagedigestexporter/digest.go Do not exist 71.4%
cmd/imagedigestexporter/main.go Do not exist 0.0%

@chhsia0
Copy link
Contributor Author

chhsia0 commented Sep 5, 2019

Error message from the e2e test:

I0905 04:46:45.989] >>>> taskrun multiple-build-push-kaniko-run
I0905 04:46:49.188] Tailing logs for taskrun: multiple-build-push-kaniko-run...
...
I0905 04:46:49.316] [step-image-digest-exporter-n9qvv] Build Failed: 2019/09/05 04:45:27 Unexpected error getting image digest for skaffold-image-leeroy-web-2: {
I0905 04:46:49.316]   "schemaVersion": 2,
I0905 04:46:49.316]   "manifests": [
I0905 04:46:49.317]     {
I0905 04:46:49.317]       "mediaType": "application/vnd.oci.image.index.v1+json",
I0905 04:46:49.317]       "size": 314,
I0905 04:46:49.317]       "digest": "sha256:05f95b26ed10668b7183c1e2da98610e91372fa9f510046d4ce5812addad86b5"
... skipping 2 lines ...
I0905 04:46:49.317] }
I0905 04:46:49.317] EOF         
I0905 04:46:49.318] : invalid character 'E' after top-level value

Judging from the message, I suspect that the EOF comes from the following line:


However I could not understand how the EOF ended up there. The block scalar YAML syntax and the shell's here document syntax looks correct to me.
@sbwsg @bobcatfish Could you take a look?

@ghost
Copy link

ghost commented Sep 5, 2019

@chhsia0 I think it's the whitespace at the end of that line with the EOF. I don't know why your change has caused the image digest exporter to become sensitive to that but removing it locally and running the example on your branch works for me.

@chhsia0
Copy link
Contributor Author

chhsia0 commented Sep 5, 2019

🤦‍♂
@sbwsg Thank you very much! Should have looked at it more carefully 😅
My change makes it become sensitive because the manifest is now parsed.

@tekton-robot
Copy link
Collaborator

The following is the coverage report on pkg/.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
cmd/imagedigestexporter/digest.go Do not exist 83.3%
cmd/imagedigestexporter/main.go Do not exist 0.0%

@ghost
Copy link

ghost commented Sep 5, 2019

Good stuff!

/lgtm

@tekton-robot tekton-robot assigned ghost Sep 5, 2019
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 5, 2019
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chhsia0, vdemeester

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 6, 2019
@tekton-robot tekton-robot merged commit 1ac3262 into tektoncd:master Sep 6, 2019
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. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm 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.

7 participants