Skip to content

Commit c35159e

Browse files
committed
c8d/manifests: Fix Content size including missing content
Content size should only include size of content that is present in the local store. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 0510499 commit c35159e

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

daemon/containerd/image_list.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,16 @@ func (i *ImageService) multiPlatformSummary(ctx context.Context, img c8dimages.I
256256
summary.Manifests = append(summary.Manifests, mfstSummary)
257257
}()
258258

259-
contentSize, err := img.Size(ctx)
260-
if err != nil {
261-
if !cerrdefs.IsNotFound(err) {
262-
logger.WithError(err).Warn("failed to determine size")
263-
}
264-
} else {
259+
var contentSize int64
260+
if err := i.walkPresentChildren(ctx, target, func(ctx context.Context, desc ocispec.Descriptor) error {
261+
contentSize += desc.Size
262+
return nil
263+
}); err == nil {
265264
mfstSummary.Size.Content = contentSize
266265
summary.TotalSize += contentSize
267266
mfstSummary.Size.Total += contentSize
267+
} else {
268+
logger.WithError(err).Warn("failed to calculate content size")
268269
}
269270

270271
isPseudo, err := img.IsPseudoImage(ctx)

daemon/containerd/image_list_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestImageListCheckTotalSize(t *testing.T) {
126126
ctx = logtest.WithT(ctx, t)
127127
service := fakeImageService(t, ctx, cs)
128128

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

132132
all, err := service.Images(ctx, imagetypes.ListOptions{Manifests: true, SharedSize: true})
@@ -173,6 +173,32 @@ func TestImageListCheckTotalSize(t *testing.T) {
173173
// TODO: This should also include the Size.Unpacked, but the test snapshotter doesn't do anything yet
174174
assert.Check(t, is.Equal(all[0].Manifests[0].Size.Total, amd64ManifestSize+amd64ConfigSize+amd64LayerSize))
175175
assert.Check(t, is.Equal(all[0].Manifests[1].Size.Total, amd64ManifestSize+amd64ConfigSize+amd64LayerSize))
176+
177+
t.Run("without layers", func(t *testing.T) {
178+
var layers []ocispec.Descriptor
179+
err = service.walkPresentChildren(ctx, img.Target, func(ctx context.Context, desc ocispec.Descriptor) error {
180+
if c8dimages.IsLayerType(desc.MediaType) {
181+
layers = append(layers, desc)
182+
}
183+
return nil
184+
})
185+
assert.NilError(t, err)
186+
187+
for _, layer := range layers {
188+
err := cs.Delete(ctx, layer.Digest)
189+
assert.NilError(t, err, "failed to delete layer %s", layer.Digest)
190+
}
191+
192+
all, err := service.Images(ctx, imagetypes.ListOptions{Manifests: true, SharedSize: true})
193+
assert.NilError(t, err)
194+
195+
assert.Assert(t, is.Len(all, 1))
196+
assert.Check(t, is.Equal(all[0].Size, allTotalSize-indexSize-arm64LayerSize-amd64LayerSize))
197+
198+
assert.Assert(t, is.Len(all[0].Manifests, 2))
199+
assert.Check(t, is.Equal(all[0].Manifests[0].Size.Content, arm64ManifestSize+arm64ConfigSize))
200+
assert.Check(t, is.Equal(all[0].Manifests[1].Size.Content, amd64ManifestSize+amd64ConfigSize))
201+
})
176202
}
177203

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

0 commit comments

Comments
 (0)