Skip to content

Commit

Permalink
Merge pull request #48376 from vvoland/48293-27.x
Browse files Browse the repository at this point in the history
[27.x backport] c8d/load: Multi-platform fixes
  • Loading branch information
vvoland authored Aug 27, 2024
2 parents 9fd71f5 + ecd2b6f commit 2a13a38
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
19 changes: 16 additions & 3 deletions daemon/containerd/image_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ func (i *ImageService) LoadImage(ctx context.Context, inTar io.ReadCloser, outSt
return nil
}

imgPlat, err := platformImg.ImagePlatform(ctx)
if err != nil {
logger.WithError(err).Warn("failed to read image platform, skipping unpack")
return nil
}

// Only unpack the image if it matches the host platform
if !i.hostPlatformMatcher().Match(imgPlat) {
return nil
}

unpacked, err := platformImg.IsUnpacked(ctx, i.snapshotter)
if err != nil {
logger.WithError(err).Warn("failed to check if image is unpacked")
Expand All @@ -305,12 +316,14 @@ func (i *ImageService) LoadImage(ctx context.Context, inTar io.ReadCloser, outSt
logger.WithField("alreadyUnpacked", unpacked).WithError(err).Debug("unpack")
return nil
})
if err != nil {
return errors.Wrap(err, "failed to unpack loaded image")
}

fmt.Fprintf(progress, "%s: %s\n", loadedMsg, name)
i.LogImageEvent(img.Target.Digest.String(), img.Target.Digest.String(), events.ActionLoad)

if err != nil {
// The image failed to unpack, but is already imported, log the error but don't fail the whole load.
fmt.Fprintf(progress, "Error unpacking image %s: %v\n", name, err)
}
}

return nil
Expand Down
8 changes: 8 additions & 0 deletions daemon/containerd/platform_matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ func (c allPlatformsWithPreferenceMatcher) Match(_ ocispec.Platform) bool {
func (c allPlatformsWithPreferenceMatcher) Less(p1, p2 ocispec.Platform) bool {
return c.preferred.Less(p1, p2)
}

func (i *ImageService) hostPlatformMatcher() platforms.MatchComparer {
// Allow to override the host platform for testing purposes.
if i.defaultPlatformOverride != nil {
return i.defaultPlatformOverride
}
return platforms.Default()
}

0 comments on commit 2a13a38

Please sign in to comment.