Skip to content

c8d: Add platform parameter to history, save and load#48295

Merged
thaJeztah merged 3 commits intomoby:masterfrom
vvoland:c8d-saveload-platform
Sep 12, 2024
Merged

c8d: Add platform parameter to history, save and load#48295
thaJeztah merged 3 commits intomoby:masterfrom
vvoland:c8d-saveload-platform

Conversation

@vvoland
Copy link
Contributor

@vvoland vvoland commented Aug 6, 2024

- What I did
Add the ability to select a specific platform for docker history, docker save and docker load.

- How I did it
See commits.

- How to verify it

- Description for the changelog

`GET /images/{name}/history` now supports a `platform` parameter (JSON encoded OCI Platform type) that allows to specify a platform to show the history of.
`POST /images/{name}/load` and `GET /images/{name}/get` now support a `platform` parameter (JSON encoded OCI Platform type) that allows to specify a platform to load/save. Not passing this parameter will result in loading/saving the full multi-platform image.

- A picture of a cute animal (not mandatory but encouraged)

@vvoland vvoland added status/2-code-review kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. area/images Image Distribution containerd-integration Issues and PRs related to containerd integration labels Aug 6, 2024
@vvoland vvoland added this to the 28.0.0 milestone Aug 6, 2024
@vvoland vvoland self-assigned this Aug 6, 2024
@vvoland
Copy link
Contributor Author

vvoland commented Aug 7, 2024

Unrelated failure, looks flaky, but haven't seen that one yet.

=== FAIL: github.com/docker/docker/container TestStateTimeoutWait (0.22s)
    state_test.go:147: Stop callback doesn't fire in 200 milliseconds

@vvoland vvoland force-pushed the c8d-saveload-platform branch 5 times, most recently from 7ae06b0 to 4d31b8c Compare August 8, 2024 11:02
@vvoland vvoland requested review from laurazard and thaJeztah August 8, 2024 11:14
@vvoland vvoland force-pushed the c8d-saveload-platform branch 4 times, most recently from f145088 to aba3908 Compare August 8, 2024 16:08
@vvoland vvoland marked this pull request as draft August 8, 2024 16:09
@vvoland vvoland force-pushed the c8d-saveload-platform branch from aba3908 to 3275617 Compare August 23, 2024 13:34
@vvoland vvoland added area/go-sdk impact/go-sdk Noteworthy (compatibility changes) in the Go SDK impact/changelog labels Aug 23, 2024
@vvoland vvoland force-pushed the c8d-saveload-platform branch 4 times, most recently from 3d5c3ef to e5c6cb0 Compare August 23, 2024 15:11
@vvoland vvoland force-pushed the c8d-saveload-platform branch from 033d0f0 to d0b8814 Compare September 6, 2024 14:05
@vvoland vvoland marked this pull request as ready for review September 6, 2024 17:57
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Did a pass, but happy to hear your thoughts on some of them.


p, err := json.Marshal(*opts.Platform)
if err != nil {
return image.LoadResponse{}, err
Copy link
Member

Choose a reason for hiding this comment

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

Should we return a errdefs error here? Also probably would be good to wrap the error as we did for the other one (invalid platform:)

Copy link
Contributor Author

@vvoland vvoland Sep 9, 2024

Choose a reason for hiding this comment

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

Not sure - other usages of json's Marshal/Unmarshal/NewDecoder/NewDecoder in client package also return the raw error directly and don't wrap it in any way so I went with the same approach.

Copy link
Member

Choose a reason for hiding this comment

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

Seems fine not to wrap it.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we could probably make a pass at typing those errors.

As to the wrapping; it was because I noticed that for ImageHistory we add a prefix;

return nil, fmt.Errorf("invalid platform: %v", err)

Without that, the error may not give a clue where the problem is (just a plain JSON marshal error).


p, err := json.Marshal(*opts.Platform)
if err != nil {
return nil, fmt.Errorf("invalid platform: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Same here for considering to use an errdefs.

☝️ Actually starting to wonder if it would make sense to have a utility for this; yes, it would be minimal (just json marshalling and handling errors), but would help producing the right errors and being consistent WDYT?

☝️ And I just realise we have httputils.DecodePlatform, so to some extent it would be nice if we had the reverse to that, but I guess httputils is part of api/server, so if we do, we should look where a suitable location would be if we want to put them together 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here for errdefs 😄

Comment on lines 55 to 57
if platform != nil {
return errdefs.NotImplemented(errors.New("platform parameter is not supported with the graphdriver image store"))
}
Copy link
Member

Choose a reason for hiding this comment

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

Same here

☝️ ❓ wondering now - could we somehow actually implement this? i.e. if a platform is provided and it matches then proceed - if it doesn't matches, then produce the same error as we do if we have multi-arch support (containerd image store) enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm actually we can. Updated.

Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM (left a couple nits, and +1 on @thaJeztah's comments)

@vvoland vvoland force-pushed the c8d-saveload-platform branch from d0b8814 to c25d20b Compare September 9, 2024 16:31
lss layer.Store
rs refstore.Store
loggerImgEvent LogImageEvent
platform *platforms.Platform
Copy link
Member

Choose a reason for hiding this comment

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

Not sure platform is needed here since we have the matcher.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used in error message:

return errors.New("no suitable export target found for platform " + platforms.FormatAll(*l.platform))

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, would be great if matchers would expose more information about what they're matching and/or perhaps return an error instead of only have a boolean.

@vvoland vvoland force-pushed the c8d-saveload-platform branch 2 times, most recently from 319064b to ead3ee3 Compare September 11, 2024 07:55
@vvoland vvoland force-pushed the c8d-saveload-platform branch from 2709581 to 0d1cff7 Compare September 11, 2024 10:32
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

some minor comments for consideration


p, err := json.Marshal(*opts.Platform)
if err != nil {
return image.LoadResponse{}, err
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we could probably make a pass at typing those errors.

As to the wrapping; it was because I noticed that for ImageHistory we add a prefix;

return nil, fmt.Errorf("invalid platform: %v", err)

Without that, the error may not give a clue where the problem is (just a plain JSON marshal error).

"github.com/containerd/platforms"

"github.com/containerd/containerd/images"
Copy link
Member

Choose a reason for hiding this comment

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

🙈 stray empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh, thanks! I really need to sort out my Goland settings 🙈

lss layer.Store
rs refstore.Store
loggerImgEvent LogImageEvent
platform *platforms.Platform
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, would be great if matchers would expose more information about what they're matching and/or perhaps return an error instead of only have a boolean.

Add `Platform` parameter that allows to select a specific platform to
show the history for.

This is a breaking change to the Go client as it changes the signature
of `ImageHistory`.

Signed-off-by: Paweł Gronowski <[email protected]>
Add `Platform` parameter that allows to select a specific platform to
save/load.

This is a breaking change to the Go client as it changes the signatures
of `ImageLoad` and `ImageSave`.

Signed-off-by: Paweł Gronowski <[email protected]>
Allows load to filter image manifests to load based on their platform.
For save, verify that the image platform matches the requested platform,
otherwise error out.

Signed-off-by: Paweł Gronowski <[email protected]>
@vvoland vvoland force-pushed the c8d-saveload-platform branch from 0d1cff7 to 521fa83 Compare September 11, 2024 17:44
@thaJeztah thaJeztah requested a review from cpuguy83 September 12, 2024 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/go-sdk area/images Image Distribution containerd-integration Issues and PRs related to containerd integration impact/changelog impact/go-sdk Noteworthy (compatibility changes) in the Go SDK kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review

Projects

Development

Successfully merging this pull request may close these issues.

4 participants