-
Notifications
You must be signed in to change notification settings - Fork 379
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
Make UpdatedImage update after conversion of MIME type #836
Conversation
4a12f95
to
d0835a0
Compare
CI passed (https://travis-ci.org/containers/image/builds/657930395?utm_source=github_status&utm_medium=notification), pushing formatting nits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
(Non-blocking: Are you interested in writing tests for the newly supported features as well?)
image/docker_schema2_test.go
Outdated
@@ -485,7 +485,6 @@ func TestManifestSchema2UpdatedImage(t *testing.T) { | |||
assert.NoError(t, err, mime) | |||
} | |||
for _, mime := range []string{ | |||
manifest.DockerV2Schema2MediaType, // This indicates a confused caller, not a no-op |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not thrilled with dropping these checks — confused callers should be detected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking at this and there's some inconsistency with docker schema v1 where it does not have this check.. Is there a particular reason for it? Or should I change it to reflect confused callers as well?
https://github.com/containers/image/blob/master/image/docker_schema1_test.go#L362-L369
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trouble in there is that the manifest looks the same for both MIME types, i.e. by the time manifestSchema1FromManifest
is called, we can’t tell whether it is a bug trying to convert to “the same” MIME type or a generic caller just trying the next MIME type in the list without understanding that the two are really not different. (In particular, see how determineManifestConversion
works with dockerImageDestination.SupportedManifestMIMETypes
.)
Overall, I do think this check is valuable to detect mistakes, but not so valuable that it’s worth forcing every generic caller to understand this schema1 idiosyncrasy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh!! okay. Gotcha. Thanks, that comment in the schema1 file makes a lot more sense with this context!
image/docker_schema1.go
Outdated
case manifest.DockerV2Schema2MediaType: | ||
m2, err := copy.convertToManifestSchema2(options.InformationOnly.LayerInfos, options.InformationOnly.LayerDiffIDs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return memoryImageFromManifest(m2), nil | ||
|
||
return m2.UpdatedImage(ctx, options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it would be nice to have the “no conversion” edits (LayerInfos
+EmbeddedDockerReference
) visually/structurally separated from the “convert depending on MIME type” path. Doing that without duplicating the “no conversion needs to happen” check rather calls for a helper to do the conversion + UpdatedImage
call (and that helper could drop the ManifestMIMEType
edit request so that unexpected no-ops are detected, see elsewhere).
Maybe
converted, err := convertManifestIfRequired(options, map[string]func(context.Context, types.ManifestUpdateInformation) (types.Image, error) {
manifest.DockerV2Schema2MediaType: copy.convertToManifestSchema2,
imgspecv1.MediaTypeImageManifest: copy.convertToOCI, // a new helper
})
if err != nil { fail }
if converted != nil { return converted }
// ordinary edits for LayerInfos and EmbeddedDockerReference follow
with a
func convertManifestIfRequired(options types.ManifestUpdateOptions, converters map[string]func(context.Context, types.ManifestUpdateInformation) (types.Image, error) {
if options.ManifestMIMEType != "" {
if converter, ok := converters[options.ManifestMIMEType]; ok {
tmp, err := converter(options.InformationOnly)
if err != nil { fail }
optionsCopy := options
optionsCopy.ManifestMIMEType = ""
return tmp.UpdatedImage(ctx, optionsCopy)
}
}
return nil, nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea this makes sense. Let me make this change.
Am updating incrementally. Will ping you when ready for review again |
d93f12c
to
bb37992
Compare
@mtrmac ready for another look! |
c799ea4
to
6aba69a
Compare
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren’t the non-conversion edits now applied twice on conversions (once before the convertManifestIfRequired
call, and once inside it)?
This admittedly doesn’t matter now, strictly speaking, because |
Thanks for the comments @mtrmac changes made! (edit keyboard cat) |
de4d8ab
to
4cb48ba
Compare
Rebased! All comments should be addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
@vrothberg PTAL.
db932e6
to
28fdd9e
Compare
Apparently github suggestions feature doesn't add signature. repushed.. |
419f7a5
to
6dc995c
Compare
rebased |
6dc995c
to
0678df4
Compare
rebased. @vrothberg any chance you've managed to take a look at this? |
Thanks for the ping! I will have a look first thing tomorrow morning. |
0678df4
to
bb0dd02
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @lumjjb!
Could you squash the commits into one before merging?
bb0dd02
to
6c60e68
Compare
Co-Authored-By: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Brandon Lum <lumjjb@gmail.com>
6c60e68
to
6ad29b4
Compare
@vrothberg done! Thanks! |
Addressing Issue #746
Signed-off-by: Brandon Lum lumjjb@gmail.com