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

fix(containerd): Use img platform in exporter instead of strict host platform #4477

Merged
merged 20 commits into from
Jul 19, 2023
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions pkg/fanal/image/daemon/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/images/archive"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/platforms"
Expand Down Expand Up @@ -56,8 +57,24 @@ func imageWriter(client *containerd.Client, img containerd.Image) imageSave {
return nil, xerrors.New("no image reference")
}
imgOpts := archive.WithImage(client.ImageService(), ref[0])
manifestOpts := archive.WithManifest(img.Target())
platOpts := archive.WithPlatform(platforms.DefaultStrict())
target := img.Target()
manifestOpts := archive.WithManifest(target)

manifest, err := images.Manifest(ctx, img.ContentStore(), target, img.Platform())
if err != nil {
return nil, xerrors.Errorf("error getting image manifest: %w", err)
}

ps, err := images.Platforms(ctx, img.ContentStore(), manifest.Config)
if err != nil {
return nil, xerrors.Errorf("error getting image platforms: %w", err)
}

if len(ps) == 0 {
return nil, xerrors.New("no platform")
}

platOpts := archive.WithPlatform(platforms.OnlyStrict(ps[0]))
AliDatadog marked this conversation as resolved.
Show resolved Hide resolved
pr, pw := io.Pipe()
go func() {
pw.CloseWithError(archive.Export(ctx, client.ContentStore(), pw, imgOpts, manifestOpts, platOpts))
Expand Down