Skip to content

Commit e6c1660

Browse files
authored
Merge pull request moby#50725 from dmcgowan/fix-containerd-prune-events
Fix image prune events for containerd backend
2 parents ed61fba + da2b1a2 commit e6c1660

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

daemon/containerd/image_prune.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import (
1212
cerrdefs "github.com/containerd/errdefs"
1313
"github.com/containerd/log"
1414
"github.com/distribution/reference"
15+
"github.com/moby/moby/api/types/events"
1516
"github.com/moby/moby/api/types/filters"
1617
"github.com/moby/moby/api/types/image"
17-
"github.com/moby/moby/v2/daemon/container"
18-
"github.com/moby/moby/v2/errdefs"
1918
"github.com/opencontainers/go-digest"
2019
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
20+
21+
"github.com/moby/moby/v2/daemon/container"
22+
"github.com/moby/moby/v2/errdefs"
2123
)
2224

2325
var imagesAcceptedFilters = map[string]bool{
@@ -243,25 +245,34 @@ func (i *ImageService) pruneAll(ctx context.Context, imagesToPrune map[string]c8
243245
continue
244246
}
245247

248+
familiarName := imageFamiliarName(img)
249+
i.logImageEvent(img, familiarName, events.ActionUnTag)
246250
report.ImagesDeleted = append(report.ImagesDeleted,
247251
image.DeleteResponse{
248-
Untagged: imageFamiliarName(img),
252+
Untagged: familiarName,
249253
},
250254
)
251255

256+
var deleted bool
252257
// Check which blobs have been deleted and sum their sizes
253258
for _, blob := range blobs {
254259
_, err := i.content.ReaderAt(ctx, blob)
255260

256261
if cerrdefs.IsNotFound(err) {
257-
report.ImagesDeleted = append(report.ImagesDeleted,
258-
image.DeleteResponse{
259-
Deleted: blob.Digest.String(),
260-
},
261-
)
262+
if c8dimages.IsManifestType(blob.MediaType) || c8dimages.IsIndexType(blob.MediaType) {
263+
deleted = true
264+
report.ImagesDeleted = append(report.ImagesDeleted,
265+
image.DeleteResponse{
266+
Deleted: blob.Digest.String(),
267+
},
268+
)
269+
}
262270
report.SpaceReclaimed += uint64(blob.Size)
263271
}
264272
}
273+
if deleted {
274+
i.logImageEvent(img, familiarName, events.ActionDelete)
275+
}
265276
}
266277

267278
return &report, errors.Join(errs...)

0 commit comments

Comments
 (0)