MCPcopy
hub / github.com/containerd/containerd / annotateDistributionSourceHandler

Function annotateDistributionSourceHandler

core/remotes/handlers.go:358–402  ·  view source on GitHub ↗

annotateDistributionSourceHandler add distribution source label into annotation of config or blob descriptor.

(f images.HandlerFunc, provider content.InfoProvider)

Source from the content-addressed store, hash-verified

356// annotateDistributionSourceHandler add distribution source label into
357// annotation of config or blob descriptor.
358func annotateDistributionSourceHandler(f images.HandlerFunc, provider content.InfoProvider) images.HandlerFunc {
359 return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
360 children, err := f(ctx, desc)
361 if err != nil {
362 return nil, err
363 }
364
365 // Distribution source is only used for config or blob but may be inherited from
366 // a manifest or manifest list
367 if !images.IsManifestType(desc.MediaType) && !images.IsIndexType(desc.MediaType) {
368 return children, nil
369 }
370
371 parentSourceAnnotations := desc.Annotations
372 var parentLabels map[string]string
373 if pi, err := provider.Info(ctx, desc.Digest); err != nil {
374 if !errdefs.IsNotFound(err) {
375 return nil, err
376 }
377 } else {
378 parentLabels = pi.Labels
379 }
380
381 for i := range children {
382 child := children[i]
383
384 info, err := provider.Info(ctx, child.Digest)
385 if err != nil {
386 if !errdefs.IsNotFound(err) {
387 return nil, err
388 }
389 }
390 copyDistributionSourceLabels(info.Labels, &child)
391
392 // Annotate with parent labels for cross repo mount or fetch.
393 // Parent sources may apply to all children since most registries
394 // enforce that children exist before the manifests.
395 copyDistributionSourceLabels(parentSourceAnnotations, &child)
396 copyDistributionSourceLabels(parentLabels, &child)
397
398 children[i] = child
399 }
400 return children, nil
401 }
402}
403
404func copyDistributionSourceLabels(from map[string]string, to *ocispec.Descriptor) {
405 for k, v := range from {

Callers 1

PushContentFunction · 0.85

Calls 4

IsManifestTypeFunction · 0.92
IsIndexTypeFunction · 0.92
InfoMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…