Skip to content

Commit

Permalink
c8d/manifests: Fix Content size including missing content
Browse files Browse the repository at this point in the history
Content size should only include size of content that is present in the
local store.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
  • Loading branch information
vvoland committed Feb 25, 2025
1 parent 0510499 commit c35159e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
13 changes: 7 additions & 6 deletions daemon/containerd/image_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,16 @@ func (i *ImageService) multiPlatformSummary(ctx context.Context, img c8dimages.I
summary.Manifests = append(summary.Manifests, mfstSummary)
}()

contentSize, err := img.Size(ctx)
if err != nil {
if !cerrdefs.IsNotFound(err) {
logger.WithError(err).Warn("failed to determine size")
}
} else {
var contentSize int64
if err := i.walkPresentChildren(ctx, target, func(ctx context.Context, desc ocispec.Descriptor) error {
contentSize += desc.Size
return nil
}); err == nil {
mfstSummary.Size.Content = contentSize
summary.TotalSize += contentSize
mfstSummary.Size.Total += contentSize
} else {
logger.WithError(err).Warn("failed to calculate content size")
}

isPseudo, err := img.IsPseudoImage(ctx)
Expand Down
28 changes: 27 additions & 1 deletion daemon/containerd/image_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestImageListCheckTotalSize(t *testing.T) {
ctx = logtest.WithT(ctx, t)
service := fakeImageService(t, ctx, cs)

_, err = service.images.Create(ctx, imagesFromIndex(twoplatform)[0])
img, err := service.images.Create(ctx, imagesFromIndex(twoplatform)[0])
assert.NilError(t, err)

all, err := service.Images(ctx, imagetypes.ListOptions{Manifests: true, SharedSize: true})
Expand Down Expand Up @@ -173,6 +173,32 @@ func TestImageListCheckTotalSize(t *testing.T) {
// TODO: This should also include the Size.Unpacked, but the test snapshotter doesn't do anything yet
assert.Check(t, is.Equal(all[0].Manifests[0].Size.Total, amd64ManifestSize+amd64ConfigSize+amd64LayerSize))
assert.Check(t, is.Equal(all[0].Manifests[1].Size.Total, amd64ManifestSize+amd64ConfigSize+amd64LayerSize))

t.Run("without layers", func(t *testing.T) {
var layers []ocispec.Descriptor
err = service.walkPresentChildren(ctx, img.Target, func(ctx context.Context, desc ocispec.Descriptor) error {
if c8dimages.IsLayerType(desc.MediaType) {
layers = append(layers, desc)
}
return nil
})
assert.NilError(t, err)

for _, layer := range layers {
err := cs.Delete(ctx, layer.Digest)
assert.NilError(t, err, "failed to delete layer %s", layer.Digest)
}

all, err := service.Images(ctx, imagetypes.ListOptions{Manifests: true, SharedSize: true})
assert.NilError(t, err)

assert.Assert(t, is.Len(all, 1))
assert.Check(t, is.Equal(all[0].Size, allTotalSize-indexSize-arm64LayerSize-amd64LayerSize))

assert.Assert(t, is.Len(all[0].Manifests, 2))
assert.Check(t, is.Equal(all[0].Manifests[0].Size.Content, arm64ManifestSize+arm64ConfigSize))
assert.Check(t, is.Equal(all[0].Manifests[1].Size.Content, amd64ManifestSize+amd64ConfigSize))
})
}

func blobSize(t *testing.T, ctx context.Context, cs content.Store, dgst digest.Digest) int64 {
Expand Down

0 comments on commit c35159e

Please sign in to comment.