Skip to content

Commit 0d62b98

Browse files
committed
Restrict EnsureContent to the requested platform
Signed-off-by: apostasie <spam_blackhole@farcloser.world>
1 parent 5be956c commit 0d62b98

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

pkg/cmd/image/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func Convert(ctx context.Context, client *containerd.Client, srcRawRef, targetRa
7676
convertOpts = append(convertOpts, converter.WithPlatform(platMC))
7777

7878
// Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3425
79-
err = EnsureAllContent(ctx, client, srcRef, options.GOptions)
79+
err = EnsureAllContent(ctx, client, srcRef, platMC, options.GOptions)
8080
if err != nil {
8181
return err
8282
}

pkg/cmd/image/ensure.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
containerd "github.com/containerd/containerd/v2/client"
2828
"github.com/containerd/containerd/v2/core/images"
2929
"github.com/containerd/log"
30+
"github.com/containerd/platforms"
3031

3132
"github.com/containerd/nerdctl/v2/pkg/api/types"
3233
"github.com/containerd/nerdctl/v2/pkg/containerdutil"
@@ -37,7 +38,7 @@ import (
3738
"github.com/containerd/nerdctl/v2/pkg/referenceutil"
3839
)
3940

40-
func EnsureAllContent(ctx context.Context, client *containerd.Client, srcName string, options types.GlobalCommandOptions) error {
41+
func EnsureAllContent(ctx context.Context, client *containerd.Client, srcName string, platMC platforms.MatchComparer, options types.GlobalCommandOptions) error {
4142
// Get the image from the srcName
4243
imageService := client.ImageService()
4344
img, err := imageService.Get(ctx, srcName)
@@ -51,9 +52,11 @@ func EnsureAllContent(ctx context.Context, client *containerd.Client, srcName st
5152
imagesList, _ := read(ctx, provider, snapshotter, img.Target)
5253
// Iterate through the list
5354
for _, i := range imagesList {
54-
err = ensureOne(ctx, client, srcName, img.Target, i.platform, options)
55-
if err != nil {
56-
return err
55+
if platMC.Match(i.platform) {
56+
err = ensureOne(ctx, client, srcName, img.Target, i.platform, options)
57+
if err != nil {
58+
return err
59+
}
5760
}
5861
}
5962

pkg/cmd/image/push.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ func Push(ctx context.Context, client *containerd.Client, rawRef string, options
6767

6868
// Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3489
6969
// XXX what if the image is a CID, or only otherwise available on ipfs?
70-
err = EnsureAllContent(ctx, client, parsedReference.String(), options.GOptions)
70+
platMC, err := platformutil.NewMatchComparer(options.AllPlatforms, options.Platforms)
71+
if err != nil {
72+
return err
73+
}
74+
75+
err = EnsureAllContent(ctx, client, parsedReference.String(), platMC, options.GOptions)
7176
if err != nil {
7277
return err
7378
}

pkg/cmd/image/save.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func Save(ctx context.Context, client *containerd.Client, images []string, optio
5050
}
5151

5252
// Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3425
53-
err = EnsureAllContent(ctx, client, found.Image.Name, options.GOptions)
53+
err = EnsureAllContent(ctx, client, found.Image.Name, platMC, options.GOptions)
5454
if err != nil {
5555
return err
5656
}

pkg/cmd/image/tag.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/containerd/nerdctl/v2/pkg/api/types"
2828
"github.com/containerd/nerdctl/v2/pkg/idutil/imagewalker"
29+
"github.com/containerd/nerdctl/v2/pkg/platformutil"
2930
"github.com/containerd/nerdctl/v2/pkg/referenceutil"
3031
)
3132

@@ -61,7 +62,12 @@ func Tag(ctx context.Context, client *containerd.Client, options types.ImageTagO
6162
defer done(ctx)
6263

6364
// Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3425
64-
err = EnsureAllContent(ctx, client, srcName, options.GOptions)
65+
platMC, err := platformutil.NewMatchComparer(true, nil)
66+
if err != nil {
67+
return err
68+
}
69+
70+
err = EnsureAllContent(ctx, client, srcName, platMC, options.GOptions)
6571
if err != nil {
6672
log.G(ctx).Warn("Unable to fetch missing layers before committing. " +
6773
"If you try to save or push this image, it might fail. See https://github.com/containerd/nerdctl/issues/3439.")

pkg/imgutil/commit/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func Commit(ctx context.Context, client *containerd.Client, container containerd
128128
}
129129

130130
// Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3425
131-
err = image.EnsureAllContent(ctx, client, baseImg.Name(), globalOptions)
131+
err = image.EnsureAllContent(ctx, client, baseImg.Name(), platformMC, globalOptions)
132132
if err != nil {
133133
log.G(ctx).Warn("Unable to fetch missing layers before committing. " +
134134
"If you try to save or push this image, it might fail. See https://github.com/containerd/nerdctl/issues/3439.")

0 commit comments

Comments
 (0)