#10681 by-digest ctr image export of org.opencontainers.image.ref.name #13167
#10681 by-digest ctr image export of org.opencontainers.image.ref.name #13167lauralorenz wants to merge 2 commits intocontainerd:mainfrom
ctr image export of org.opencontainers.image.ref.name #13167Conversation
63edfc9 to
bf6bd02
Compare
d6fad45 to
8e1847e
Compare
8e1847e to
dcc9d60
Compare
dcc9d60 to
867e97e
Compare
Uses the definition of valid grammar for this field from the OCI image annotations spec: https://github.com/opencontainers/image-spec/blob/e72ae99d5fc74e7f7f8e320a44f76968da86a545/annotations.md#pre-defined-annotation-keys On this commit the test will fail per the bug containerd#10681 `manifest annotation org.opencontainers.image.ref.name ="@sha256:7b3ccabffc97de872a30dfd234fd972a66d247c8cfc69b0550f276481852627c" does not match required grammar` Signed-off-by: Laura Lorenz <lauralorenz@google.com>
ee79e05 to
fa1529a
Compare
ctr image export of org.opencontainers.image.ref.name ctr image export of org.opencontainers.image.ref.name
|
|
||
| func ociReferenceName(name string) string { | ||
| // OCI defines the reference name as only a tag excluding the | ||
| // OCI suggests the reference name as only a tag excluding the |
There was a problem hiding this comment.
da73208 to
4614b67
Compare
|
/rerun |
|
/retest |
|
@lauralorenz: Cannot trigger testing until a trusted user reviews the PR and leaves an DetailsIn response to this:
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-sigs/prow repository. |
|
/ok-to-test |
|
/retest |
4614b67 to
aa630ff
Compare
|
/retest |
|
It looks like a couple of the commits are in the style of "address reviews". We generally prefer to have commits that tell a story of the change. Preserving the changes from review (and I expect these were driven by the LLM review I sent you? 😅) isn't particularly valuable. Can you incorporate the fixes into the commits where they were relevant? Edit: Having looked through the commits, I think this could either be all squashed into one commit or have one commit for the test and another for the fix. Either would be fine, but we don't need more than two commits here. Once the commits are fixed this LGTM. |
|
Roger that, squashing 🫡 and will keep that in mind next time! |
aa630ff to
cc3f640
Compare
tianon
left a comment
There was a problem hiding this comment.
Alternatively, I could change it to always prefer the full name in all of those cases, which is implied to be requested in the issue, if we don't like this.
I'm obviously biased (author of the issue and I apply a patch in my own builds of containerd that does exactly that 😂).
To be clear: I am not a containerd maintainer (so take all my review with the according [non]weight) 🙇
| } | ||
| } | ||
|
|
||
| func assertOCIIndexAnnotationRefName(t *testing.T, r io.Reader) { |
There was a problem hiding this comment.
Maybe this is standard in the containerd repo, but it seems weird IMO to have a single-use helper function 🤔 why not inline this? are the other tests doing this?
There was a problem hiding this comment.
I don't feel too strongly either way, originally it was simply to match style in the other tests but in those cases the helper functions are reused. I do think it's a bit easier to read the test case itself this way since the helper function does a bunch of uninteresting file parsing.
| "regexp" | ||
| ) | ||
|
|
||
| var OCIAnnotationRegex = regexp.MustCompile(`^[A-Za-z0-9]+(?:(?:[-._:@+]|--)[A-Za-z0-9]+)*(?:/[A-Za-z0-9]+(?:(?:[-._:@+]|--)[A-Za-z0-9]+)*)*$`) |
There was a problem hiding this comment.
This is definitely eyebrow-raising, IMO - this looks like it's probably that ref.name grammar, expressed as a regex?
I don't know what the containerd project norm is here, but I'd suggest the name be more specific to that (because ref.name is the only OCI annotation that matches this grammar), and maybe even link to the grammar? It also feels a little strange for it to live in a completely separate file, not right next to (or even inside) the single function that actually uses it, and definitely doesn't need it exported (this is a module nobody is likely to import, but it's good hygiene regardless).
There was a problem hiding this comment.
X-post with #13167 (comment) that I have at least renamed/unexported this variable.
Regarding code structure: I initially put it in an existing helper file (as it felt like a helper/util to me) but realized later I needed it to be platform agnostic at those helper files are built per platform. I don't feel strongly about it being broken out though, and have folded it into the related assertion now, so please take another look.
|
|
||
| const newLine = "\n" | ||
|
|
||
| var OCIAnnotationRegex = regexp.MustCompile(`^[A-Za-z0-9]+(?:(?:[-._:@+]|--)[A-Za-z0-9]+)*(?:/[A-Za-z0-9]+(?:(?:[-._:@+]|--)[A-Za-z0-9]+)*)*$`) |
There was a problem hiding this comment.
+1 to @tianon's comment, I think we should probably clarify the naming of this var (since there's many different annotation keys) and document where this regex is derived from, maybe https://github.com/opencontainers/image-spec/blob/v1.1.1/annotations.md#pre-defined-annotation-keys ?
There was a problem hiding this comment.
X-post with #13167 (comment)
I've renamed this variable and added in a comment with the reference
cc3f640 to
7652bf6
Compare
On export, if the image is by-digest without any tag, set the org.opencontainers.image.ref.name as the full name. This prevents setting this field with a leading non-alphanum, which is incorrect OCI grammar. Fixes containerd#10681. Signed-off-by: Laura Lorenz <lauralorenz@google.com>
7652bf6 to
75d32fd
Compare
|
/retest |
Fixes #10681
Adds an integration test and fixes the issue where
ctr image exports for images by digest had a non-valid grammar set in theirorg.opencontainers.image.ref.namefield in their index.json.The way I chose to handle this is so that if an export is called for something that has only a sha256 digest, it will return the full name (as requested in the issue), but that in all other cases it stays the same (which in general would mean that this would refer to the image's
tag, or thetag@sha256:<hash>. (see examples below)Alternatively, I could change it to always prefer the full name in all of those cases, which is implied to be requested in the issue, if we don't like this. However, if we want to discuss that please check the Implementer's Note at the index.json spec in OCI image-spec, which to me makes it seem like it may be beneficial to leave this as the tag as often as possible.
PS: I spent some time writing tests against import since the ociAnnotationRef function is used there, but its only in a specific case (docker image layouts) and it seems to not work (or at least not be very testable with the test harness for import we have).
Current behavior / bad
Behavior in this PR / good