@@ -32,8 +32,8 @@ import (
3232 "github.com/containerd/containerd"
3333 "github.com/containerd/containerd/errdefs"
3434 containerdimages "github.com/containerd/containerd/images"
35- "github.com/containerd/containerd/labels"
3635 "github.com/containerd/containerd/log"
36+ snpkg "github.com/containerd/containerd/pkg/snapshotters"
3737 distribution "github.com/containerd/containerd/reference/docker"
3838 "github.com/containerd/containerd/remotes/docker"
3939 "github.com/containerd/containerd/remotes/docker/config"
@@ -129,7 +129,7 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
129129 pullOpts = append (pullOpts , c .encryptedImagesPullOpts ()... )
130130 if ! c .config .ContainerdConfig .DisableSnapshotAnnotations {
131131 pullOpts = append (pullOpts ,
132- containerd .WithImageHandlerWrapper (appendInfoHandlerWrapper (ref )))
132+ containerd .WithImageHandlerWrapper (snpkg . AppendInfoHandlerWrapper (ref )))
133133 }
134134
135135 if c .config .ContainerdConfig .DiscardUnpackedLayers {
@@ -495,73 +495,3 @@ func (c *criService) encryptedImagesPullOpts() []containerd.RemoteOpt {
495495 }
496496 return nil
497497}
498-
499- const (
500- // targetRefLabel is a label which contains image reference and will be passed
501- // to snapshotters.
502- targetRefLabel = "containerd.io/snapshot/cri.image-ref"
503- // targetManifestDigestLabel is a label which contains manifest digest and will be passed
504- // to snapshotters.
505- targetManifestDigestLabel = "containerd.io/snapshot/cri.manifest-digest"
506- // targetLayerDigestLabel is a label which contains layer digest and will be passed
507- // to snapshotters.
508- targetLayerDigestLabel = "containerd.io/snapshot/cri.layer-digest"
509- // targetImageLayersLabel is a label which contains layer digests contained in
510- // the target image and will be passed to snapshotters for preparing layers in
511- // parallel. Skipping some layers is allowed and only affects performance.
512- targetImageLayersLabel = "containerd.io/snapshot/cri.image-layers"
513- )
514-
515- // appendInfoHandlerWrapper makes a handler which appends some basic information
516- // of images like digests for manifest and their child layers as annotations during unpack.
517- // These annotations will be passed to snapshotters as labels. These labels will be
518- // used mainly by stargz-based snapshotters for querying image contents from the
519- // registry.
520- func appendInfoHandlerWrapper (ref string ) func (f containerdimages.Handler ) containerdimages.Handler {
521- return func (f containerdimages.Handler ) containerdimages.Handler {
522- return containerdimages .HandlerFunc (func (ctx context.Context , desc imagespec.Descriptor ) ([]imagespec.Descriptor , error ) {
523- children , err := f .Handle (ctx , desc )
524- if err != nil {
525- return nil , err
526- }
527- switch desc .MediaType {
528- case imagespec .MediaTypeImageManifest , containerdimages .MediaTypeDockerSchema2Manifest :
529- for i := range children {
530- c := & children [i ]
531- if containerdimages .IsLayerType (c .MediaType ) {
532- if c .Annotations == nil {
533- c .Annotations = make (map [string ]string )
534- }
535- c .Annotations [targetRefLabel ] = ref
536- c .Annotations [targetLayerDigestLabel ] = c .Digest .String ()
537- c .Annotations [targetImageLayersLabel ] = getLayers (ctx , targetImageLayersLabel , children [i :], labels .Validate )
538- c .Annotations [targetManifestDigestLabel ] = desc .Digest .String ()
539- }
540- }
541- }
542- return children , nil
543- })
544- }
545- }
546-
547- // getLayers returns comma-separated digests based on the passed list of
548- // descriptors. The returned list contains as many digests as possible as well
549- // as meets the label validation.
550- func getLayers (ctx context.Context , key string , descs []imagespec.Descriptor , validate func (k , v string ) error ) (layers string ) {
551- var item string
552- for _ , l := range descs {
553- if containerdimages .IsLayerType (l .MediaType ) {
554- item = l .Digest .String ()
555- if layers != "" {
556- item = "," + item
557- }
558- // This avoids the label hits the size limitation.
559- if err := validate (key , layers + item ); err != nil {
560- log .G (ctx ).WithError (err ).WithField ("label" , key ).Debugf ("%q is omitted in the layers list" , l .Digest .String ())
561- break
562- }
563- layers += item
564- }
565- }
566- return
567- }
0 commit comments