Dedupe "containerd.io/uncompressed" constants and literals

Dedupe the several "containerd.io/uncompressed" constants and literals
into `github.com/containerd/containerd/labels.LabelUncompressed`

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2023-07-25 02:55:49 +09:00
parent 8656037191
commit 67f3e79553
18 changed files with 63 additions and 50 deletions

9
cache/blobs.go vendored
View File

@@ -8,6 +8,7 @@ import (
"github.com/containerd/containerd/diff"
"github.com/containerd/containerd/diff/walking"
"github.com/containerd/containerd/labels"
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/mount"
"github.com/moby/buildkit/session"
@@ -25,8 +26,6 @@ import (
var g flightcontrol.Group[struct{}]
var gFileList flightcontrol.Group[[]string]
const containerdUncompressed = "containerd.io/uncompressed"
var ErrNoBlobs = errors.Errorf("no blobs for snapshot")
// computeBlobChain ensures every ref in a parent chain has an associated blob in the content store. If
@@ -231,10 +230,10 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
return struct{}{}, err
}
if diffID, ok := info.Labels[containerdUncompressed]; ok {
desc.Annotations[containerdUncompressed] = diffID
if diffID, ok := info.Labels[labels.LabelUncompressed]; ok {
desc.Annotations[labels.LabelUncompressed] = diffID
} else if mediaType == ocispecs.MediaTypeImageLayer {
desc.Annotations[containerdUncompressed] = desc.Digest.String()
desc.Annotations[labels.LabelUncompressed] = desc.Digest.String()
} else {
return struct{}{}, errors.Errorf("unknown layer compression type")
}

View File

@@ -10,6 +10,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
labelspkg "github.com/containerd/containerd/labels"
"github.com/containerd/containerd/mount"
"github.com/moby/buildkit/util/bklog"
"github.com/moby/buildkit/util/compression"
@@ -69,7 +70,7 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper
if labels == nil {
labels = map[string]string{}
}
labels[containerdUncompressed] = dgstr.Digest().String()
labels[labelspkg.LabelUncompressed] = dgstr.Digest().String()
} else {
if err = overlay.WriteUpperdir(ctx, bufW, upperdir, lower); err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to write diff")
@@ -101,9 +102,9 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper
cinfo.Labels = make(map[string]string)
}
// Set uncompressed label if digest already existed without label
if _, ok := cinfo.Labels[containerdUncompressed]; !ok {
cinfo.Labels[containerdUncompressed] = labels[containerdUncompressed]
if _, err := sr.cm.ContentStore.Update(ctx, cinfo, "labels."+containerdUncompressed); err != nil {
if _, ok := cinfo.Labels[labelspkg.LabelUncompressed]; !ok {
cinfo.Labels[labelspkg.LabelUncompressed] = labels[labelspkg.LabelUncompressed]
if _, err := sr.cm.ContentStore.Update(ctx, cinfo, "labels."+labelspkg.LabelUncompressed); err != nil {
return emptyDesc, false, errors.Wrap(err, "error setting uncompressed label")
}
}

View File

@@ -109,7 +109,7 @@ func MergeNydus(ctx context.Context, ref ImmutableRef, comp compression.Config,
compressedDgst := cw.Digest()
if err := cw.Commit(ctx, 0, compressedDgst, content.WithLabels(map[string]string{
containerdUncompressed: uncompressedDgst.Digest().String(),
labels.LabelUncompressed: uncompressedDgst.Digest().String(),
})); err != nil {
if !errdefs.IsAlreadyExists(err) {
return nil, errors.Wrap(err, "commit to content store")
@@ -129,7 +129,7 @@ func MergeNydus(ctx context.Context, ref ImmutableRef, comp compression.Config,
Size: info.Size,
MediaType: ocispecs.MediaTypeImageLayerGzip,
Annotations: map[string]string{
containerdUncompressed: uncompressedDgst.Digest().String(),
labels.LabelUncompressed: uncompressedDgst.Digest().String(),
// Use this annotation to identify nydus bootstrap layer.
converter.LayerAnnotationNydusBootstrap: "true",
},

3
cache/manager.go vendored
View File

@@ -13,6 +13,7 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/filters"
"github.com/containerd/containerd/gc"
"github.com/containerd/containerd/labels"
"github.com/containerd/containerd/leases"
"github.com/docker/docker/pkg/idtools"
"github.com/moby/buildkit/cache/metadata"
@@ -1657,7 +1658,7 @@ func sortDeleteRecords(toDelete []*deleteRecord) {
}
func diffIDFromDescriptor(desc ocispecs.Descriptor) (digest.Digest, error) {
diffIDStr, ok := desc.Annotations["containerd.io/uncompressed"]
diffIDStr, ok := desc.Annotations[labels.LabelUncompressed]
if !ok {
return "", errors.Errorf("missing uncompressed annotation for %s", desc.Digest)
}

27
cache/manager_test.go vendored
View File

@@ -25,6 +25,7 @@ import (
"github.com/containerd/containerd/diff/apply"
"github.com/containerd/containerd/diff/walking"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/labels"
"github.com/containerd/containerd/leases"
ctdmetadata "github.com/containerd/containerd/metadata"
"github.com/containerd/containerd/mount"
@@ -731,7 +732,7 @@ func TestSetBlob(t *testing.T) {
err = snap.(*immutableRef).setBlob(ctx, ocispecs.Descriptor{
Digest: digest.FromBytes([]byte("foobar")),
Annotations: map[string]string{
"containerd.io/uncompressed": digest.FromBytes([]byte("foobar2")).String(),
labels.LabelUncompressed: digest.FromBytes([]byte("foobar2")).String(),
},
})
require.Error(t, err)
@@ -742,7 +743,7 @@ func TestSetBlob(t *testing.T) {
require.NoError(t, err)
snapRef = snap.(*immutableRef)
require.Equal(t, desc.Annotations["containerd.io/uncompressed"], string(snapRef.getDiffID()))
require.Equal(t, desc.Annotations[labels.LabelUncompressed], string(snapRef.getDiffID()))
require.Equal(t, desc.Digest, snapRef.getBlob())
require.Equal(t, desc.MediaType, snapRef.getMediaType())
require.Equal(t, snapRef.getDiffID(), snapRef.getChainID())
@@ -768,7 +769,7 @@ func TestSetBlob(t *testing.T) {
require.NoError(t, err)
snapRef2 := snap2.(*immutableRef)
require.Equal(t, desc2.Annotations["containerd.io/uncompressed"], string(snapRef2.getDiffID()))
require.Equal(t, desc2.Annotations[labels.LabelUncompressed], string(snapRef2.getDiffID()))
require.Equal(t, desc2.Digest, snapRef2.getBlob())
require.Equal(t, desc2.MediaType, snapRef2.getMediaType())
require.Equal(t, digest.FromBytes([]byte(snapRef.getChainID()+" "+snapRef2.getDiffID())), snapRef2.getChainID())
@@ -786,7 +787,7 @@ func TestSetBlob(t *testing.T) {
require.NoError(t, err)
snapRef3 := snap3.(*immutableRef)
require.Equal(t, desc3.Annotations["containerd.io/uncompressed"], string(snapRef3.getDiffID()))
require.Equal(t, desc3.Annotations[labels.LabelUncompressed], string(snapRef3.getDiffID()))
require.Equal(t, desc3.Digest, snapRef3.getBlob())
require.Equal(t, desc3.MediaType, snapRef3.getMediaType())
require.Equal(t, digest.FromBytes([]byte(snapRef.getChainID()+" "+snapRef3.getDiffID())), snapRef3.getChainID())
@@ -804,7 +805,7 @@ func TestSetBlob(t *testing.T) {
b5, desc5, err := mapToBlob(map[string]string{"foo5": "bar5"}, true)
require.NoError(t, err)
desc5.Annotations["containerd.io/uncompressed"] = snapRef2.getDiffID().String()
desc5.Annotations[labels.LabelUncompressed] = snapRef2.getDiffID().String()
err = content.WriteBlob(ctx, co.cs, "ref5", bytes.NewBuffer(b5), desc5)
require.NoError(t, err)
@@ -833,7 +834,7 @@ func TestSetBlob(t *testing.T) {
require.NoError(t, err)
snapRef6 := snap6.(*immutableRef)
require.Equal(t, desc6.Annotations["containerd.io/uncompressed"], string(snapRef6.getDiffID()))
require.Equal(t, desc6.Annotations[labels.LabelUncompressed], string(snapRef6.getDiffID()))
require.Equal(t, desc6.Digest, snapRef6.getBlob())
require.Equal(t, digest.FromBytes([]byte(snapRef3.getChainID()+" "+snapRef6.getDiffID())), snapRef6.getChainID())
require.Equal(t, digest.FromBytes([]byte(snapRef3.getBlobChainID()+" "+digest.FromBytes([]byte(snapRef6.getBlob()+" "+snapRef6.getDiffID())))), snapRef6.getBlobChainID())
@@ -843,7 +844,7 @@ func TestSetBlob(t *testing.T) {
_, err = cm.GetByBlob(ctx, ocispecs.Descriptor{
Digest: digest.FromBytes([]byte("notexist")),
Annotations: map[string]string{
"containerd.io/uncompressed": digest.FromBytes([]byte("notexist")).String(),
labels.LabelUncompressed: digest.FromBytes([]byte("notexist")).String(),
},
}, snap3)
require.Error(t, err)
@@ -1584,7 +1585,7 @@ func TestConversion(t *testing.T) {
}
require.Equal(t, recreatedDesc.Digest, orgDesc.Digest, testName)
require.NotNil(t, recreatedDesc.Annotations)
require.Equal(t, recreatedDesc.Annotations["containerd.io/uncompressed"], orgDesc.Digest.String(), testName)
require.Equal(t, recreatedDesc.Annotations[labels.LabelUncompressed], orgDesc.Digest.String(), testName)
return nil
})
}
@@ -1965,7 +1966,7 @@ func checkInfo(ctx context.Context, t *testing.T, cs content.Store, info content
if info.Labels == nil {
return
}
uncompressedDgst, ok := info.Labels[containerdUncompressed]
uncompressedDgst, ok := info.Labels[labels.LabelUncompressed]
if !ok {
return
}
@@ -1987,7 +1988,7 @@ func checkDescriptor(ctx context.Context, t *testing.T, cs content.Store, desc o
}
// Check annotations exist
uncompressedDgst, ok := desc.Annotations[containerdUncompressed]
uncompressedDgst, ok := desc.Annotations[labels.LabelUncompressed]
require.True(t, ok, "uncompressed digest annotation not found: %q", desc.Digest)
var uncompressedSize int64
if compressionType == compression.EStargz {
@@ -2579,7 +2580,7 @@ func mapToBlobWithCompression(m map[string]string, compress func(io.Writer) (io.
MediaType: mediaType,
Size: int64(buf.Len()),
Annotations: map[string]string{
"containerd.io/uncompressed": sha.Digest().String(),
labels.LabelUncompressed: sha.Digest().String(),
},
}, nil
}
@@ -2631,7 +2632,7 @@ func fileToBlob(file *os.File, compress bool) ([]byte, ocispecs.Descriptor, erro
MediaType: mediaType,
Size: int64(buf.Len()),
Annotations: map[string]string{
"containerd.io/uncompressed": sha.Digest().String(),
labels.LabelUncompressed: sha.Digest().String(),
},
}, nil
}
@@ -2688,7 +2689,7 @@ func mapToSystemTarBlob(t *testing.T, m map[string]string) ([]byte, ocispecs.Des
MediaType: ocispecs.MediaTypeImageLayer,
Size: int64(len(tarout)),
Annotations: map[string]string{
"containerd.io/uncompressed": digest.FromBytes(tarout).String(),
labels.LabelUncompressed: digest.FromBytes(tarout).String(),
},
}, nil
}

5
cache/refs.go vendored
View File

@@ -12,6 +12,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/labels"
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/pkg/userns"
@@ -39,7 +40,7 @@ import (
"golang.org/x/sync/errgroup"
)
var additionalAnnotations = append(compression.EStargzAnnotations, containerdUncompressed)
var additionalAnnotations = append(compression.EStargzAnnotations, labels.LabelUncompressed)
// Ref is a reference to cacheable objects.
type Ref interface {
@@ -733,7 +734,7 @@ func (sr *immutableRef) ociDesc(ctx context.Context, dhs DescHandlers, preferNon
diffID := sr.getDiffID()
if diffID != "" {
desc.Annotations["containerd.io/uncompressed"] = string(diffID)
desc.Annotations[labels.LabelUncompressed] = string(diffID)
}
createdAt := sr.GetCreatedAt()

View File

@@ -10,6 +10,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/labels"
"github.com/moby/buildkit/cache/remotecache"
v1 "github.com/moby/buildkit/cache/remotecache/v1"
"github.com/moby/buildkit/session"
@@ -72,7 +73,7 @@ func (ce *exporter) Finalize(ctx context.Context) (map[string]string, error) {
return nil, errors.Errorf("invalid descriptor without annotations")
}
var diffID digest.Digest
v, ok := dgstPair.Descriptor.Annotations["containerd.io/uncompressed"]
v, ok := dgstPair.Descriptor.Annotations[labels.LabelUncompressed]
if !ok {
return nil, errors.Errorf("invalid descriptor without uncompressed annotation")
}

View File

@@ -9,6 +9,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/labels"
"github.com/moby/buildkit/cache/remotecache"
v1 "github.com/moby/buildkit/cache/remotecache/v1"
"github.com/moby/buildkit/session"
@@ -147,7 +148,7 @@ func (ci *importer) makeDescriptorProviderPair(l v1.CacheLayer) (*v1.DescriptorP
if l.Annotations.DiffID == "" {
return nil, errors.Errorf("cache layer with missing diffid")
}
annotations["containerd.io/uncompressed"] = l.Annotations.DiffID.String()
annotations[labels.LabelUncompressed] = l.Annotations.DiffID.String()
if !l.Annotations.CreatedAt.IsZero() {
txt, err := l.Annotations.CreatedAt.MarshalText()
if err != nil {

View File

@@ -11,6 +11,7 @@ import (
"time"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/labels"
"github.com/moby/buildkit/cache/remotecache"
v1 "github.com/moby/buildkit/cache/remotecache/v1"
"github.com/moby/buildkit/session"
@@ -133,7 +134,7 @@ func (ce *exporter) Finalize(ctx context.Context) (map[string]string, error) {
return nil, errors.Errorf("invalid descriptor without annotations")
}
var diffID digest.Digest
v, ok := dgstPair.Descriptor.Annotations["containerd.io/uncompressed"]
v, ok := dgstPair.Descriptor.Annotations[labels.LabelUncompressed]
if !ok {
return nil, errors.Errorf("invalid descriptor without uncompressed annotation")
}
@@ -226,7 +227,7 @@ func (ci *importer) makeDescriptorProviderPair(l v1.CacheLayer) (*v1.DescriptorP
if l.Annotations.DiffID == "" {
return nil, errors.Errorf("cache layer with missing diffid")
}
annotations["containerd.io/uncompressed"] = l.Annotations.DiffID.String()
annotations[labels.LabelUncompressed] = l.Annotations.DiffID.String()
if !l.Annotations.CreatedAt.IsZero() {
txt, err := l.Annotations.CreatedAt.MarshalText()
if err != nil {

View File

@@ -10,6 +10,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/labels"
v1 "github.com/moby/buildkit/cache/remotecache/v1"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/solver"
@@ -221,7 +222,7 @@ func (ci *contentCacheImporter) importInlineCache(ctx context.Context, dt []byte
if createdBy := createdMsg[i]; createdBy != "" {
m.Annotations["buildkit/description"] = createdBy
}
m.Annotations["containerd.io/uncompressed"] = img.Rootfs.DiffIDs[i].String()
m.Annotations[labels.LabelUncompressed] = img.Rootfs.DiffIDs[i].String()
layers[m.Digest] = v1.DescriptorProviderPair{
Descriptor: m,
Provider: ci.provider,

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"github.com/containerd/containerd/labels"
"github.com/moby/buildkit/cache/remotecache"
v1 "github.com/moby/buildkit/cache/remotecache/v1"
"github.com/moby/buildkit/session"
@@ -67,7 +68,7 @@ func (ce *exporter) ExportForLayers(ctx context.Context, layers []digest.Digest)
}
// fallback for uncompressed digests
for _, v := range descs {
if uc := v.Descriptor.Annotations["containerd.io/uncompressed"]; uc == string(k) {
if uc := v.Descriptor.Annotations[labels.LabelUncompressed]; uc == string(k) {
descs2[v.Descriptor.Digest] = v
layerBlobDigests[i] = v.Descriptor.Digest
}

View File

@@ -17,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/smithy-go"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/labels"
"github.com/moby/buildkit/cache/remotecache"
v1 "github.com/moby/buildkit/cache/remotecache/v1"
"github.com/moby/buildkit/session"
@@ -185,7 +186,7 @@ func (e *exporter) Finalize(ctx context.Context) (map[string]string, error) {
if dgstPair.Descriptor.Annotations == nil {
return nil, errors.Errorf("invalid descriptor without annotations")
}
v, ok := dgstPair.Descriptor.Annotations["containerd.io/uncompressed"]
v, ok := dgstPair.Descriptor.Annotations[labels.LabelUncompressed]
if !ok {
return nil, errors.Errorf("invalid descriptor without uncompressed annotation")
}
@@ -274,7 +275,7 @@ func (i *importer) makeDescriptorProviderPair(l v1.CacheLayer) (*v1.DescriptorPr
return nil, errors.Errorf("cache layer with missing diffid")
}
annotations := map[string]string{}
annotations["containerd.io/uncompressed"] = l.Annotations.DiffID.String()
annotations[labels.LabelUncompressed] = l.Annotations.DiffID.String()
if !l.Annotations.CreatedAt.IsZero() {
txt, err := l.Annotations.CreatedAt.MarshalText()
if err != nil {

View File

@@ -12,6 +12,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/labels"
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/pkg/epoch"
"github.com/containerd/containerd/platforms"
@@ -454,7 +455,7 @@ func getLayers(ctx context.Context, descs []ocispecs.Descriptor, manifest ocispe
for i, desc := range descs {
layers[i].Diff = ocispecs.Descriptor{
MediaType: ocispecs.MediaTypeImageLayer,
Digest: digest.Digest(desc.Annotations["containerd.io/uncompressed"]),
Digest: digest.Digest(desc.Annotations[labels.LabelUncompressed]),
}
layers[i].Blob = manifest.Layers[i]
}

View File

@@ -12,6 +12,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/diff"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/labels"
"github.com/containerd/containerd/platforms"
intoto "github.com/in-toto/in-toto-golang/in_toto"
"github.com/moby/buildkit/cache"
@@ -443,8 +444,8 @@ func (ic *ImageWriter) commitAttestationsManifest(ctx context.Context, opts *Ima
Digest: digest,
Size: int64(len(data)),
Annotations: map[string]string{
"containerd.io/uncompressed": digest.String(),
"in-toto.io/predicate-type": statement.PredicateType,
labels.LabelUncompressed: digest.String(),
"in-toto.io/predicate-type": statement.PredicateType,
},
}
@@ -552,7 +553,7 @@ func attestationsConfig(layers []ocispecs.Descriptor) ([]byte, error) {
img.Variant = intotoPlatform.Variant
img.RootFS.Type = "layers"
for _, layer := range layers {
img.RootFS.DiffIDs = append(img.RootFS.DiffIDs, digest.Digest(layer.Annotations["containerd.io/uncompressed"]))
img.RootFS.DiffIDs = append(img.RootFS.DiffIDs, digest.Digest(layer.Annotations[labels.LabelUncompressed]))
}
dt, err := json.Marshal(img)
return dt, errors.Wrap(err, "failed to create attestations image config")
@@ -577,7 +578,7 @@ func patchImageConfig(dt []byte, descs []ocispecs.Descriptor, history []ocispecs
var rootFS ocispecs.RootFS
rootFS.Type = "layers"
for _, desc := range descs {
rootFS.DiffIDs = append(rootFS.DiffIDs, digest.Digest(desc.Annotations["containerd.io/uncompressed"]))
rootFS.DiffIDs = append(rootFS.DiffIDs, digest.Digest(desc.Annotations[labels.LabelUncompressed]))
}
dt, err := json.Marshal(rootFS)
if err != nil {
@@ -735,7 +736,7 @@ func RemoveInternalLayerAnnotations(in map[string]string, oci bool) map[string]s
for k, v := range in {
// oci supports annotations but don't export internal annotations
switch k {
case "containerd.io/uncompressed", "buildkit/createdat":
case labels.LabelUncompressed, "buildkit/createdat":
continue
default:
if strings.HasPrefix(k, "containerd.io/distribution.source.") {

View File

@@ -12,6 +12,7 @@ import (
cdcompression "github.com/containerd/containerd/archive/compression"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/labels"
"github.com/containerd/stargz-snapshotter/estargz"
"github.com/moby/buildkit/util/iohelper"
digest "github.com/opencontainers/go-digest"
@@ -21,7 +22,6 @@ import (
var EStargzAnnotations = []string{estargz.TOCJSONDigestAnnotation, estargz.StoreUncompressedSizeAnnotation}
const containerdUncompressed = "containerd.io/uncompressed"
const estargzLabel = "buildkit.io/compression/estargz"
func (c estargzType) Compress(ctx context.Context, comp Config) (compressorFunc Compressor, finalize Finalizer) {
@@ -105,8 +105,8 @@ func (c estargzType) Compress(ctx context.Context, comp Config) (compressorFunc
if info.Labels == nil {
info.Labels = make(map[string]string)
}
info.Labels[containerdUncompressed] = cInfo.uncompressedDigest.String()
if _, err := cs.Update(ctx, info, "labels."+containerdUncompressed); err != nil {
info.Labels[labels.LabelUncompressed] = cInfo.uncompressedDigest.String()
if _, err := cs.Update(ctx, info, "labels."+labels.LabelUncompressed); err != nil {
return nil, err
}
@@ -114,7 +114,7 @@ func (c estargzType) Compress(ctx context.Context, comp Config) (compressorFunc
a := make(map[string]string)
a[estargz.TOCJSONDigestAnnotation] = cInfo.tocDigest.String()
a[estargz.StoreUncompressedSizeAnnotation] = fmt.Sprintf("%d", cInfo.uncompressedSize)
a[containerdUncompressed] = cInfo.uncompressedDigest.String()
a[labels.LabelUncompressed] = cInfo.uncompressedDigest.String()
return a, nil
}
}

View File

@@ -56,14 +56,14 @@ func (c nydusType) Compress(ctx context.Context, comp Config) (compressorFunc Co
if info.Labels == nil {
info.Labels = make(map[string]string)
}
info.Labels[containerdUncompressed] = uncompressedDgst
if _, err := cs.Update(ctx, info, "labels."+containerdUncompressed); err != nil {
info.Labels[labels.LabelUncompressed] = uncompressedDgst
if _, err := cs.Update(ctx, info, "labels."+labels.LabelUncompressed); err != nil {
return nil, errors.Wrap(err, "update info to content store")
}
// Fill annotations
annotations := map[string]string{
containerdUncompressed: uncompressedDgst,
labels.LabelUncompressed: uncompressedDgst,
// Use this annotation to identify nydus blob layer.
nydusify.LayerAnnotationNydusBlob: "true",
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/labels"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/reference"
"github.com/containerd/containerd/remotes"
@@ -273,7 +274,7 @@ func getLayers(ctx context.Context, provider content.Provider, desc ocispecs.Des
if desc.Annotations == nil {
desc.Annotations = map[string]string{}
}
desc.Annotations["containerd.io/uncompressed"] = diffIDs[i].String()
desc.Annotations[labels.LabelUncompressed] = diffIDs[i].String()
layers[i] = desc
}
return layers, nil

View File

@@ -14,6 +14,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/diff"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/labels"
"github.com/containerd/containerd/mount"
log "github.com/moby/buildkit/util/bklog"
digest "github.com/opencontainers/go-digest"
@@ -121,7 +122,7 @@ func (s *winDiffer) Compare(ctx context.Context, lower, upper []mount.Mount, opt
if config.Labels == nil {
config.Labels = map[string]string{}
}
config.Labels["containerd.io/uncompressed"] = dgstr.Digest().String()
config.Labels[labels.LabelUncompressed] = dgstr.Digest().String()
} else {
w, discard, done := makeWindowsLayer(ctx, cw)
if err = archive.WriteDiff(ctx, w, lowerRoot, upperRoot); err != nil {