Skip to content

Commit a40c383

Browse files
committed
Add option to pull all metadata
Add flags to pull and fetch to grab all metadata. Add fetch option to pull only metadata. Signed-off-by: Derek McGowan <[email protected]>
1 parent aae2d0d commit a40c383

6 files changed

Lines changed: 43 additions & 34 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
}

cmd/ctr/commands/content/fetch.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ Most of this is experimental and there are few leaps to make this work.`,
6767
Usage: "pull content from all platforms",
6868
},
6969
cli.BoolFlag{
70-
Name: "all-manifests",
71-
Usage: "Pull manifests from all platforms and layers for a specific platform",
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",
7276
},
7377
),
7478
Action: func(clicontext *cli.Context) error {
@@ -84,6 +88,7 @@ Most of this is experimental and there are few leaps to make this work.`,
8488
if err != nil {
8589
return err
8690
}
91+
8792
_, err = Fetch(ctx, client, ref, config)
8893
return err
8994
},
@@ -97,10 +102,12 @@ type FetchConfig struct {
97102
ProgressOutput io.Writer
98103
// Labels to set on the content
99104
Labels []string
105+
// PlatformMatcher matches platforms, supersedes Platforms
106+
PlatformMatcher platforms.MatchComparer
100107
// Platforms to fetch
101108
Platforms []string
102-
// Whether or not download all manifests
103-
IsAllManifests bool
109+
// Whether or not download all metadata
110+
AllMetadata bool
104111
}
105112

106113
// NewFetchConfig returns the default FetchConfig from cli flags
@@ -124,7 +131,13 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig,
124131
config.Platforms = p
125132
}
126133

127-
config.IsAllManifests = clicontext.Bool("all-manifests")
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+
}
128141

129142
return config, nil
130143
}
@@ -160,12 +173,16 @@ func Fetch(ctx context.Context, client *containerd.Client, ref string, config *F
160173
containerd.WithSchema1Conversion,
161174
}
162175

163-
if config.IsAllManifests {
164-
opts = append(opts, containerd.WithAppendDistributionSourceLabel())
176+
if config.AllMetadata {
177+
opts = append(opts, containerd.WithAllMetadata())
165178
}
166179

167-
for _, platform := range config.Platforms {
168-
opts = append(opts, containerd.WithPlatform(platform))
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+
}
169186
}
170187

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

cmd/ctr/commands/images/pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +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",
5555
},
5656
cli.BoolFlag{
57-
Name: "all-manifests",
58-
Usage: "Pull manifests from all platforms and layers for a specific platform",
57+
Name: "all-metadata",
58+
Usage: "Pull metadata for all platforms",
5959
},
6060
),
6161
Action: func(context *cli.Context) error {

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: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ 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-
if rCtx.AppendDistributionSourceLabel {
143+
if rCtx.AllMetadata {
144144
// Filter manifests by platforms but allow to handle manifest
145145
// and configuration for not-target platforms
146146
childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher)
@@ -164,22 +164,18 @@ func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, lim
164164
},
165165
)
166166

167+
appendDistSrcLabelHandler, err := docker.AppendDistributionSourceLabel(store, ref)
168+
if err != nil {
169+
return images.Image{}, err
170+
}
171+
167172
handlers := append(rCtx.BaseHandlers,
168173
remotes.FetchHandler(store, fetcher),
169174
convertibleHandler,
170175
childrenHandler,
176+
appendDistSrcLabelHandler,
171177
)
172178

173-
// append distribution source label to blob data
174-
if rCtx.AppendDistributionSourceLabel {
175-
appendDistSrcLabelHandler, err := docker.AppendDistributionSourceLabel(store, ref)
176-
if err != nil {
177-
return images.Image{}, err
178-
}
179-
180-
handlers = append(handlers, appendDistSrcLabelHandler)
181-
}
182-
183179
handler = images.Handlers(handlers...)
184180

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

0 commit comments

Comments
 (0)