mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Fix image prune events for containerd backend
Ensure events for containerd backend are properly sent when deleted via image prune. Fix prune output to only show deleted images rather than the deletion of each blob. Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
@@ -12,12 +12,14 @@ import (
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/moby/moby/api/types/events"
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
"github.com/moby/moby/api/types/image"
|
||||
"github.com/moby/moby/v2/daemon/container"
|
||||
"github.com/moby/moby/v2/errdefs"
|
||||
"github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
|
||||
"github.com/moby/moby/v2/daemon/container"
|
||||
"github.com/moby/moby/v2/errdefs"
|
||||
)
|
||||
|
||||
var imagesAcceptedFilters = map[string]bool{
|
||||
@@ -243,25 +245,34 @@ func (i *ImageService) pruneAll(ctx context.Context, imagesToPrune map[string]c8
|
||||
continue
|
||||
}
|
||||
|
||||
familiarName := imageFamiliarName(img)
|
||||
i.logImageEvent(img, familiarName, events.ActionUnTag)
|
||||
report.ImagesDeleted = append(report.ImagesDeleted,
|
||||
image.DeleteResponse{
|
||||
Untagged: imageFamiliarName(img),
|
||||
Untagged: familiarName,
|
||||
},
|
||||
)
|
||||
|
||||
var deleted bool
|
||||
// Check which blobs have been deleted and sum their sizes
|
||||
for _, blob := range blobs {
|
||||
_, err := i.content.ReaderAt(ctx, blob)
|
||||
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
report.ImagesDeleted = append(report.ImagesDeleted,
|
||||
image.DeleteResponse{
|
||||
Deleted: blob.Digest.String(),
|
||||
},
|
||||
)
|
||||
if c8dimages.IsManifestType(blob.MediaType) || c8dimages.IsIndexType(blob.MediaType) {
|
||||
deleted = true
|
||||
report.ImagesDeleted = append(report.ImagesDeleted,
|
||||
image.DeleteResponse{
|
||||
Deleted: blob.Digest.String(),
|
||||
},
|
||||
)
|
||||
}
|
||||
report.SpaceReclaimed += uint64(blob.Size)
|
||||
}
|
||||
}
|
||||
if deleted {
|
||||
i.logImageEvent(img, familiarName, events.ActionDelete)
|
||||
}
|
||||
}
|
||||
|
||||
return &report, errors.Join(errs...)
|
||||
|
||||
Reference in New Issue
Block a user