Skip to content

Commit df84e54

Browse files
Merge pull request #3577 from dmcgowan/change-default-manifest-download
[carry #3127] Update pull default to skip all platform manifests
2 parents dfd76b3 + a40c383 commit df84e54

7 files changed

Lines changed: 62 additions & 32 deletions

File tree

client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,8 @@ type RemoteContext struct {
333333
// MaxConcurrentDownloads is the max concurrent content downloads for each pull.
334334
MaxConcurrentDownloads int
335335

336-
// AppendDistributionSourceLabel allows fetcher to add distribute source
337-
// label for each blob content, which doesn't work for legacy schema1.
338-
AppendDistributionSourceLabel bool
336+
// AllMetadata downloads all manifests and known-configuration files
337+
AllMetadata bool
339338
}
340339

341340
func defaultRemoteContext() *RemoteContext {

client_opts.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,10 @@ func WithMaxConcurrentDownloads(max int) RemoteOpt {
195195
}
196196
}
197197

198-
// WithAppendDistributionSourceLabel allows fetcher to add distribute source
199-
// label for each blob content, which doesn't work for legacy schema1.
200-
func WithAppendDistributionSourceLabel() RemoteOpt {
198+
// WithAllMetadata downloads all manifests and known-configuration files
199+
func WithAllMetadata() RemoteOpt {
201200
return func(_ *Client, c *RemoteContext) error {
202-
c.AppendDistributionSourceLabel = true
201+
c.AllMetadata = true
203202
return nil
204203
}
205204
}

client_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,6 @@ func TestImagePullSomePlatforms(t *testing.T) {
287287
count := 0
288288
for _, manifest := range manifests {
289289
children, err := images.Children(ctx, cs, manifest)
290-
if err != nil {
291-
t.Fatal(err)
292-
}
293290

294291
found := false
295292
for _, matcher := range m {
@@ -315,6 +312,8 @@ func TestImagePullSomePlatforms(t *testing.T) {
315312
}
316313
ra.Close()
317314
}
315+
} else if err == nil {
316+
t.Fatal("manifest should not have pulled children content")
318317
}
319318
}
320319

cmd/ctr/commands/content/fetch.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/containerd/containerd/pkg/progress"
3535
"github.com/containerd/containerd/platforms"
3636
"github.com/containerd/containerd/remotes"
37-
digest "github.com/opencontainers/go-digest"
37+
"github.com/opencontainers/go-digest"
3838
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3939
"github.com/urfave/cli"
4040
)
@@ -66,6 +66,14 @@ Most of this is experimental and there are few leaps to make this work.`,
6666
Name: "all-platforms",
6767
Usage: "pull content from all platforms",
6868
},
69+
cli.BoolFlag{
70+
Name: "all-metadata",
71+
Usage: "Pull metadata for all platforms",
72+
},
73+
cli.BoolFlag{
74+
Name: "metadata-only",
75+
Usage: "Pull all metadata including manifests and configs",
76+
},
6977
),
7078
Action: func(clicontext *cli.Context) error {
7179
var (
@@ -80,6 +88,7 @@ Most of this is experimental and there are few leaps to make this work.`,
8088
if err != nil {
8189
return err
8290
}
91+
8392
_, err = Fetch(ctx, client, ref, config)
8493
return err
8594
},
@@ -93,8 +102,12 @@ type FetchConfig struct {
93102
ProgressOutput io.Writer
94103
// Labels to set on the content
95104
Labels []string
105+
// PlatformMatcher matches platforms, supersedes Platforms
106+
PlatformMatcher platforms.MatchComparer
96107
// Platforms to fetch
97108
Platforms []string
109+
// Whether or not download all metadata
110+
AllMetadata bool
98111
}
99112

100113
// NewFetchConfig returns the default FetchConfig from cli flags
@@ -117,6 +130,15 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig,
117130
}
118131
config.Platforms = p
119132
}
133+
134+
if clicontext.Bool("metadata-only") {
135+
config.AllMetadata = true
136+
// Any with an empty set is None
137+
config.PlatformMatcher = platforms.Any()
138+
} else if clicontext.Bool("all-metadata") {
139+
config.AllMetadata = true
140+
}
141+
120142
return config, nil
121143
}
122144

@@ -149,11 +171,18 @@ func Fetch(ctx context.Context, client *containerd.Client, ref string, config *F
149171
containerd.WithResolver(config.Resolver),
150172
containerd.WithImageHandler(h),
151173
containerd.WithSchema1Conversion,
152-
containerd.WithAppendDistributionSourceLabel(),
153174
}
154175

155-
for _, platform := range config.Platforms {
156-
opts = append(opts, containerd.WithPlatform(platform))
176+
if config.AllMetadata {
177+
opts = append(opts, containerd.WithAllMetadata())
178+
}
179+
180+
if config.PlatformMatcher != nil {
181+
opts = append(opts, containerd.WithPlatformMatcher(config.PlatformMatcher))
182+
} else {
183+
for _, platform := range config.Platforms {
184+
opts = append(opts, containerd.WithPlatform(platform))
185+
}
157186
}
158187

159188
img, err := client.Fetch(pctx, ref, opts...)

cmd/ctr/commands/images/pull.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ command. As part of this process, we do the following:
5151
},
5252
cli.BoolFlag{
5353
Name: "all-platforms",
54-
Usage: "pull content from all platforms",
54+
Usage: "pull content and metadata from all platforms",
55+
},
56+
cli.BoolFlag{
57+
Name: "all-metadata",
58+
Usage: "Pull metadata for all platforms",
5559
},
5660
),
5761
Action: func(context *cli.Context) error {
@@ -78,6 +82,7 @@ command. As part of this process, we do the following:
7882
if err != nil {
7983
return err
8084
}
85+
8186
img, err := content.Fetch(ctx, client, ref, config)
8287
if err != nil {
8388
return err

image_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ func TestImagePullWithDistSourceLabel(t *testing.T) {
9999
pMatcher := platforms.Default()
100100

101101
// pull content without unpack and add distribution source label
102-
image, err := client.Pull(ctx, imageName,
103-
WithPlatformMatcher(pMatcher),
104-
WithAppendDistributionSourceLabel())
102+
image, err := client.Pull(ctx, imageName, WithPlatformMatcher(pMatcher))
105103
if err != nil {
106104
t.Fatal(err)
107105
}
@@ -183,7 +181,7 @@ func TestImageUsage(t *testing.T) {
183181
imageName = imageName + "@" + image.Target().Digest.String()
184182

185183
// Fetch single platforms, but all manifests pulled
186-
if _, err := client.Fetch(ctx, imageName, WithPlatformMatcher(testPlatform)); err != nil {
184+
if _, err := client.Fetch(ctx, imageName, WithPlatformMatcher(testPlatform), WithAllMetadata()); err != nil {
187185
t.Fatal(err)
188186
}
189187

pull.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,14 @@ func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, lim
140140
childrenHandler := images.ChildrenHandler(store)
141141
// Set any children labels for that content
142142
childrenHandler = images.SetChildrenLabels(store, childrenHandler)
143-
// Filter manifests by platforms but allow to handle manifest
144-
// and configuration for not-target platforms
145-
childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher)
143+
if rCtx.AllMetadata {
144+
// Filter manifests by platforms but allow to handle manifest
145+
// and configuration for not-target platforms
146+
childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher)
147+
} else {
148+
// Filter children by platforms if specified.
149+
childrenHandler = images.FilterPlatforms(childrenHandler, rCtx.PlatformMatcher)
150+
}
146151
// Sort and limit manifests if a finite number is needed
147152
if limit > 0 {
148153
childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit)
@@ -159,22 +164,18 @@ func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, lim
159164
},
160165
)
161166

167+
appendDistSrcLabelHandler, err := docker.AppendDistributionSourceLabel(store, ref)
168+
if err != nil {
169+
return images.Image{}, err
170+
}
171+
162172
handlers := append(rCtx.BaseHandlers,
163173
remotes.FetchHandler(store, fetcher),
164174
convertibleHandler,
165175
childrenHandler,
176+
appendDistSrcLabelHandler,
166177
)
167178

168-
// append distribution source label to blob data
169-
if rCtx.AppendDistributionSourceLabel {
170-
appendDistSrcLabelHandler, err := docker.AppendDistributionSourceLabel(store, ref)
171-
if err != nil {
172-
return images.Image{}, err
173-
}
174-
175-
handlers = append(handlers, appendDistSrcLabelHandler)
176-
}
177-
178179
handler = images.Handlers(handlers...)
179180

180181
converterFunc = func(ctx context.Context, desc ocispec.Descriptor) (ocispec.Descriptor, error) {

0 commit comments

Comments
 (0)