Skip to content

c8d: ImageService.GetImage: fix filtering by platform#47183

Draft
thaJeztah wants to merge 1 commit intomoby:masterfrom
thaJeztah:fix_platform_filter
Draft

c8d: ImageService.GetImage: fix filtering by platform#47183
thaJeztah wants to merge 1 commit intomoby:masterfrom
thaJeztah:fix_platform_filter

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Jan 23, 2024

Before this patch, it would find all images (and platform) are found, and return the first image (or the old default: "linux/amd64");

With this patch, an error is returned if a platform is set, and no results were found:

No such image: alpine:latest for platform: windows/s390x

Looking at consumers of this function, there may be something to fix though;

moby/daemon/create.go

Lines 85 to 86 in 1786517

if opts.params.Platform == nil && opts.params.Config.Image != "" {
img, err := daemon.imageService.GetImage(ctx, opts.params.Config.Image, imagetypes.GetImageOpts{Platform: opts.params.Platform})

if opts.params.Platform == nil && opts.params.Config.Image != "" {
    img, err := daemon.imageService.GetImage(ctx, opts.params.Config.Image, imagetypes.GetImageOpts{Platform: opts.params.Platform})

The code above looks to check for NO platform to be passed in parameters, but then to pass that platform as imagetypes.GetImageOpts.Platform.

That code was added in 300c11c but that was a refactor, combining multiple branches, so before that we passed platform unconditionally (but only used the image in some cases, so that was an optimization).

Should we;

  • always lookup the image?
  • should GetImage use OnlyPlatformWithFallback as default (if no platform is specified)? To select any image, but prefer local platform?

- What I did

- How I did it

- How to verify it

- Description for the changelog

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

Before this patch, it would find all images (and platform) are found,
and return the first image (or the old default: "linux/amd64");

With this patch, an error is returned if a platform is set, and no
results were found:

    No such image: alpine:latest for platform: windows/s390x

Looking at consumers of this function, there may be something to fix though;
https://github.com/moby/moby/blob/178651733852a26bc11e6fa272b48ff37ecc7447/daemon/create.go#L85-L86

    if opts.params.Platform == nil && opts.params.Config.Image != "" {
        img, err := daemon.imageService.GetImage(ctx, opts.params.Config.Image, imagetypes.GetImageOpts{Platform: opts.params.Platform})

The code above looks to check for _NO_ platform to be passed in parameters, but
then to pass that platform as `imagetypes.GetImageOpts.Platform`.

That code was added in 300c11c but that was a
refactor, combining multiple branches, so before that we passed platform
unconditionally (but only used the image in some cases, so that was an
optimization).

Should we;

- always lookup the image?
- should `GetImage` use OnlyPlatformWithFallback as default (if no platform
  is specified)? To select any image, but _prefer_ local platform?

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/images Image Distribution kind/bugfix PR's that fix bugs status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant