Use the const labels.LabelUncompressed
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
parent
6b333fd210
commit
778e8f2af4
@ -30,6 +30,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/log"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/pkg/epoch"
|
||||
@ -42,7 +43,6 @@ type walkingDiff struct {
|
||||
}
|
||||
|
||||
var emptyDesc = ocispec.Descriptor{}
|
||||
var uncompressed = "containerd.io/uncompressed"
|
||||
|
||||
// NewWalkingDiff is a generic implementation of diff.Comparer. The diff is
|
||||
// calculated by mounting both the upper and lower mount sets and walking the
|
||||
@ -154,7 +154,7 @@ func (s *walkingDiff) Compare(ctx context.Context, lower, upper []mount.Mount, o
|
||||
if config.Labels == nil {
|
||||
config.Labels = map[string]string{}
|
||||
}
|
||||
config.Labels[uncompressed] = dgstr.Digest().String()
|
||||
config.Labels[labels.LabelUncompressed] = dgstr.Digest().String()
|
||||
} else {
|
||||
if errOpen = archive.WriteDiff(ctx, cw, lowerRoot, upperRoot, writeDiffOpts...); errOpen != nil {
|
||||
return fmt.Errorf("failed to write diff: %w", errOpen)
|
||||
@ -181,10 +181,10 @@ func (s *walkingDiff) Compare(ctx context.Context, lower, upper []mount.Mount, o
|
||||
if info.Labels == nil {
|
||||
info.Labels = make(map[string]string)
|
||||
}
|
||||
// Set uncompressed label if digest already existed without label
|
||||
if _, ok := info.Labels[uncompressed]; !ok {
|
||||
info.Labels[uncompressed] = config.Labels[uncompressed]
|
||||
if _, err := s.store.Update(ctx, info, "labels."+uncompressed); err != nil {
|
||||
// Set "containerd.io/uncompressed" label if digest already existed without label
|
||||
if _, ok := info.Labels[labels.LabelUncompressed]; !ok {
|
||||
info.Labels[labels.LabelUncompressed] = config.Labels[labels.LabelUncompressed]
|
||||
if _, err := s.store.Update(ctx, info, "labels."+labels.LabelUncompressed); err != nil {
|
||||
return fmt.Errorf("error setting uncompressed label: %w", err)
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,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/log"
|
||||
"github.com/containerd/containerd/metadata"
|
||||
"github.com/containerd/containerd/mount"
|
||||
@ -77,7 +78,6 @@ type windowsDiff struct {
|
||||
}
|
||||
|
||||
var emptyDesc = ocispec.Descriptor{}
|
||||
var uncompressed = "containerd.io/uncompressed"
|
||||
|
||||
// NewWindowsDiff is the Windows container layer implementation
|
||||
// for comparing and applying filesystem layers
|
||||
@ -255,7 +255,7 @@ func (s windowsDiff) Compare(ctx context.Context, lower, upper []mount.Mount, op
|
||||
if config.Labels == nil {
|
||||
config.Labels = map[string]string{}
|
||||
}
|
||||
config.Labels[uncompressed] = dgstr.Digest().String()
|
||||
config.Labels[labels.LabelUncompressed] = dgstr.Digest().String()
|
||||
} else {
|
||||
if err = archive.WriteDiff(ctx, cw, "", layers[0], archive.AsWindowsContainerLayerPair(), archive.WithParentLayers(layers[1:])); err != nil {
|
||||
return emptyDesc, fmt.Errorf("failed to write diff: %w", err)
|
||||
@ -281,10 +281,10 @@ func (s windowsDiff) Compare(ctx context.Context, lower, upper []mount.Mount, op
|
||||
if info.Labels == nil {
|
||||
info.Labels = make(map[string]string)
|
||||
}
|
||||
// Set uncompressed label if digest already existed without label
|
||||
if _, ok := info.Labels[uncompressed]; !ok {
|
||||
info.Labels[uncompressed] = config.Labels[uncompressed]
|
||||
if _, err := s.store.Update(ctx, info, "labels."+uncompressed); err != nil {
|
||||
// Set "containerd.io/uncompressed" label if digest already existed without label
|
||||
if _, ok := info.Labels[labels.LabelUncompressed]; !ok {
|
||||
info.Labels[labels.LabelUncompressed] = config.Labels[labels.LabelUncompressed]
|
||||
if _, err := s.store.Update(ctx, info, "labels."+labels.LabelUncompressed); err != nil {
|
||||
return emptyDesc, fmt.Errorf("error setting uncompressed label: %w", err)
|
||||
}
|
||||
}
|
||||
|
5
image.go
5
image.go
@ -28,6 +28,7 @@ import (
|
||||
"github.com/containerd/containerd/diff"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/labels"
|
||||
"github.com/containerd/containerd/pkg/kmutex"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/rootfs"
|
||||
@ -392,10 +393,10 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string, opts ...Unpa
|
||||
cinfo := content.Info{
|
||||
Digest: layer.Blob.Digest,
|
||||
Labels: map[string]string{
|
||||
"containerd.io/uncompressed": layer.Diff.Digest.String(),
|
||||
labels.LabelUncompressed: layer.Diff.Digest.String(),
|
||||
},
|
||||
}
|
||||
if _, err := cs.Update(ctx, cinfo, "labels.containerd.io/uncompressed"); err != nil {
|
||||
if _, err := cs.Update(ctx, cinfo, "labels."+labels.LabelUncompressed); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,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/log"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
@ -261,11 +262,11 @@ func resolveLayers(ctx context.Context, store content.Store, layerFiles []string
|
||||
}
|
||||
layers[i] = desc
|
||||
descs[desc.Digest] = &layers[i]
|
||||
filters = append(filters, "labels.\"containerd.io/uncompressed\"=="+desc.Digest.String())
|
||||
filters = append(filters, fmt.Sprintf("labels.\"%s\"==%s", labels.LabelUncompressed, desc.Digest.String()))
|
||||
}
|
||||
|
||||
err := store.Walk(ctx, func(info content.Info) error {
|
||||
dgst, ok := info.Labels["containerd.io/uncompressed"]
|
||||
dgst, ok := info.Labels[labels.LabelUncompressed]
|
||||
if ok {
|
||||
desc := descs[digest.Digest(dgst)]
|
||||
if desc != nil {
|
||||
@ -305,7 +306,7 @@ func resolveLayers(ctx context.Context, store content.Store, layerFiles []string
|
||||
}
|
||||
ref := fmt.Sprintf("compress-blob-%s-%s", desc.Digest.Algorithm().String(), desc.Digest.Encoded())
|
||||
labels := map[string]string{
|
||||
"containerd.io/uncompressed": desc.Digest.String(),
|
||||
labels.LabelUncompressed: desc.Digest.String(),
|
||||
}
|
||||
layers[i], err = compressBlob(ctx, store, s, ref, content.WithLabels(labels))
|
||||
if err != nil {
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
"github.com/containerd/containerd/diff"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/labels"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/pkg/kmutex"
|
||||
@ -302,16 +303,16 @@ func (u *Unpacker) unpack(
|
||||
}
|
||||
|
||||
// inherits annotations which are provided as snapshot labels.
|
||||
labels := snapshots.FilterInheritedLabels(desc.Annotations)
|
||||
if labels == nil {
|
||||
labels = make(map[string]string)
|
||||
snapshotLabels := snapshots.FilterInheritedLabels(desc.Annotations)
|
||||
if snapshotLabels == nil {
|
||||
snapshotLabels = make(map[string]string)
|
||||
}
|
||||
labels[labelSnapshotRef] = chainID
|
||||
snapshotLabels[labelSnapshotRef] = chainID
|
||||
|
||||
var (
|
||||
key string
|
||||
mounts []mount.Mount
|
||||
opts = append(unpack.SnapshotOpts, snapshots.WithLabels(labels))
|
||||
opts = append(unpack.SnapshotOpts, snapshots.WithLabels(snapshotLabels))
|
||||
)
|
||||
|
||||
for try := 1; try <= 3; try++ {
|
||||
@ -400,10 +401,10 @@ func (u *Unpacker) unpack(
|
||||
cinfo := content.Info{
|
||||
Digest: desc.Digest,
|
||||
Labels: map[string]string{
|
||||
"containerd.io/uncompressed": diff.Digest.String(),
|
||||
labels.LabelUncompressed: diff.Digest.String(),
|
||||
},
|
||||
}
|
||||
if _, err := cs.Update(ctx, cinfo, "labels.containerd.io/uncompressed"); err != nil {
|
||||
if _, err := cs.Update(ctx, cinfo, "labels."+labels.LabelUncompressed); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -36,6 +36,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/log"
|
||||
"github.com/containerd/containerd/remotes"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
@ -366,12 +367,12 @@ func (c *Converter) fetchBlob(ctx context.Context, desc ocispec.Descriptor) erro
|
||||
cinfo := content.Info{
|
||||
Digest: desc.Digest,
|
||||
Labels: map[string]string{
|
||||
"containerd.io/uncompressed": state.diffID.String(),
|
||||
labels.LabelUncompressed: state.diffID.String(),
|
||||
labelDockerSchema1EmptyLayer: strconv.FormatBool(state.empty),
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := c.contentStore.Update(ctx, cinfo, "labels.containerd.io/uncompressed", fmt.Sprintf("labels.%s", labelDockerSchema1EmptyLayer)); err != nil {
|
||||
if _, err := c.contentStore.Update(ctx, cinfo, "labels."+labels.LabelUncompressed, fmt.Sprintf("labels.%s", labelDockerSchema1EmptyLayer)); err != nil {
|
||||
return fmt.Errorf("failed to update uncompressed label: %w", err)
|
||||
}
|
||||
|
||||
@ -390,7 +391,7 @@ func (c *Converter) reuseLabelBlobState(ctx context.Context, desc ocispec.Descri
|
||||
}
|
||||
desc.Size = cinfo.Size
|
||||
|
||||
diffID, ok := cinfo.Labels["containerd.io/uncompressed"]
|
||||
diffID, ok := cinfo.Labels[labels.LabelUncompressed]
|
||||
if !ok {
|
||||
return false, nil
|
||||
}
|
||||
@ -409,7 +410,7 @@ func (c *Converter) reuseLabelBlobState(ctx context.Context, desc ocispec.Descri
|
||||
bState := blobState{empty: isEmpty}
|
||||
|
||||
if bState.diffID, err = digest.Parse(diffID); err != nil {
|
||||
log.G(ctx).WithField("id", desc.Digest).Warnf("failed to parse digest from label containerd.io/uncompressed: %v", diffID)
|
||||
log.G(ctx).WithField("id", desc.Digest).Warnf("failed to parse digest from label %s: %v", labels.LabelUncompressed, diffID)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user