MCPcopy Index your code
hub / github.com/containerd/containerd / fetch

Method fetch

client/pull.go:192–286  ·  view source on GitHub ↗
(ctx context.Context, rCtx *RemoteContext, ref string, limit int)

Source from the content-addressed store, hash-verified

190}
191
192func (c *Client) fetch(ctx context.Context, rCtx *RemoteContext, ref string, limit int) (images.Image, error) {
193 ctx, span := tracing.StartSpan(ctx, tracing.Name(pullSpanPrefix, "fetch"))
194 defer span.End()
195 store := c.ContentStore()
196 name, desc, err := rCtx.Resolver.Resolve(ctx, ref)
197 if err != nil {
198 return images.Image{}, fmt.Errorf("failed to resolve reference %q: %w", ref, err)
199 }
200
201 fetcher, err := rCtx.Resolver.Fetcher(ctx, name)
202 if err != nil {
203 return images.Image{}, fmt.Errorf("failed to get fetcher for %q: %w", name, err)
204 }
205
206 var (
207 handler images.Handler
208
209 isConvertible bool
210 converterFunc func(context.Context, ocispec.Descriptor) (ocispec.Descriptor, error)
211 limiter *semaphore.Weighted
212 )
213 if desc.MediaType == images.MediaTypeDockerSchema1Manifest {
214 return images.Image{}, fmt.Errorf("%w: media type %q is no longer supported since containerd v2.1, please rebuild the image as %q or %q",
215 errdefs.ErrNotImplemented,
216 images.MediaTypeDockerSchema1Manifest, images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest)
217 }
218 // Get all the children for a descriptor
219 childrenHandler := images.ChildrenHandler(store)
220 if rCtx.ReferrersProvider != nil {
221 childrenHandler = images.SetReferrers(rCtx.ReferrersProvider, childrenHandler)
222 }
223 // Set any children labels for that content
224 childrenHandler = images.SetChildrenMappedLabels(store, childrenHandler, rCtx.ChildLabelMap)
225 if rCtx.AllMetadata {
226 // Filter manifests by platforms but allow to handle manifest
227 // and configuration for not-target platforms
228 childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher)
229 } else {
230 // Filter children by platforms if specified.
231 childrenHandler = images.FilterPlatforms(childrenHandler, rCtx.PlatformMatcher)
232 }
233 // Sort and limit manifests if a finite number is needed
234 if limit > 0 {
235 childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit)
236 }
237
238 // set isConvertible to true if there is application/octet-stream media type
239 convertibleHandler := images.HandlerFunc(
240 func(_ context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
241 if desc.MediaType == docker.LegacyConfigMediaType {
242 isConvertible = true
243 }
244
245 return []ocispec.Descriptor{}, nil
246 },
247 )
248
249 appendDistSrcLabelHandler, err := docker.AppendDistributionSourceLabel(store, ref)

Callers 2

PullMethod · 0.95
FetchMethod · 0.95

Calls 15

ContentStoreMethod · 0.95
StartSpanFunction · 0.92
NameFunction · 0.92
ChildrenHandlerFunction · 0.92
SetReferrersFunction · 0.92
SetChildrenMappedLabelsFunction · 0.92
FilterPlatformsFunction · 0.92
LimitManifestsFunction · 0.92
HandlerFuncFuncType · 0.92
FetchHandlerFunction · 0.92

Tested by

no test coverage detected