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

Make UpdatedImage update after conversion of MIME type #836

Merged
merged 1 commit into from
Mar 13, 2020

Conversation

lumjjb
Copy link
Contributor

@lumjjb lumjjb commented Mar 3, 2020

Addressing Issue #746

Signed-off-by: Brandon Lum lumjjb@gmail.com

@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 3, 2020

Copy link
Collaborator

@mtrmac mtrmac left a 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?)

@@ -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
Copy link
Collaborator

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.

Copy link
Contributor Author

@lumjjb lumjjb Mar 3, 2020

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

Copy link
Collaborator

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.

Copy link
Contributor Author

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!

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)
Copy link
Collaborator

@mtrmac mtrmac Mar 3, 2020

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
}

Copy link
Contributor Author

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.

@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 3, 2020

Am updating incrementally. Will ping you when ready for review again

@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 4, 2020

@mtrmac ready for another look!

@lumjjb lumjjb force-pushed the change_updated_image branch 2 times, most recently from c799ea4 to 6aba69a Compare March 4, 2020 16:02
@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 4, 2020

Rebased

Copy link
Collaborator

@mtrmac mtrmac left a 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)?

image/docker_schema1.go Show resolved Hide resolved
image/oci.go Show resolved Hide resolved
image/oci.go Outdated Show resolved Hide resolved
@mtrmac
Copy link
Collaborator

mtrmac commented Mar 5, 2020

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 ManifestUpdateOptions are more or less idempotent — but there are some RFEs floating around for more editing functionality (“add a layer”) that should not be applied twice, and just being clear about the order of operations should make it easier to make future changes.

@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 5, 2020

Thanks for the comments @mtrmac changes made!

(edit keyboard cat)

@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 6, 2020

Rebased! All comments should be addressed.

Copy link
Collaborator

@mtrmac mtrmac left a 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.

image/manifest.go Show resolved Hide resolved
@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 7, 2020

Apparently github suggestions feature doesn't add signature. repushed..

@lumjjb lumjjb force-pushed the change_updated_image branch 2 times, most recently from 419f7a5 to 6dc995c Compare March 10, 2020 17:31
@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 10, 2020

rebased

@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 12, 2020

rebased. @vrothberg any chance you've managed to take a look at this?

@vrothberg
Copy link
Member

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.

Copy link
Member

@vrothberg vrothberg left a 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?

Co-Authored-By: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Brandon Lum <lumjjb@gmail.com>
@lumjjb
Copy link
Contributor Author

lumjjb commented Mar 13, 2020

@vrothberg done! Thanks!

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.

3 participants