diff --git a/daemon/containerd/image_delete.go b/daemon/containerd/image_delete.go index a88669920b..83d39d36cb 100644 --- a/daemon/containerd/image_delete.go +++ b/daemon/containerd/image_delete.go @@ -45,7 +45,7 @@ import ( // TODO(thaJeztah): implement ImageDelete "force" options; see https://github.com/moby/moby/issues/43850 // TODO(thaJeztah): implement ImageDelete "prune" options; see https://github.com/moby/moby/issues/43849 // TODO(thaJeztah): add support for image delete using image (short)ID; see https://github.com/moby/moby/issues/43854 -// TODO(thaJeztah): mage delete should send image "untag" events and prometheus counters; see https://github.com/moby/moby/issues/43855 +// TODO(thaJeztah): image delete should send prometheus counters; see https://github.com/moby/moby/issues/45268 func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error) { parsedRef, err := reference.ParseNormalizedNamed(imageRef) if err != nil { @@ -53,10 +53,19 @@ func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force, } ref := reference.TagNameOnly(parsedRef) + desc, err := i.resolveDescriptor(ctx, imageRef) + if err != nil { + return nil, err + } + + imgID := string(desc.Digest) err = i.client.ImageService().Delete(ctx, ref.String(), images.SynchronousDelete()) if err != nil { return nil, err } + i.LogImageEvent(imgID, imgID, "untag") + i.LogImageEvent(imgID, imgID, "delete") + return []types.ImageDeleteResponseItem{{Untagged: reference.FamiliarString(parsedRef)}}, nil } diff --git a/daemon/containerd/image_tag.go b/daemon/containerd/image_tag.go index eab9107dcc..24dcb20a80 100644 --- a/daemon/containerd/image_tag.go +++ b/daemon/containerd/image_tag.go @@ -39,6 +39,7 @@ func (i *ImageService) TagImage(ctx context.Context, imageID image.ID, newTag re // Check if image we would replace already resolves to the same target. // No need to do anything. if replacedImg.Target.Digest == target.Digest { + i.LogImageEvent(imageID.String(), reference.FamiliarString(newTag), "tag") return nil } @@ -59,12 +60,15 @@ func (i *ImageService) TagImage(ctx context.Context, imageID image.ID, newTag re }) logger.Info("image created") + defer i.LogImageEvent(imageID.String(), reference.FamiliarString(newTag), "tag") + // The tag succeeded, check if the source image is dangling sourceDanglingImg, err := is.Get(context.Background(), danglingImageName(target.Digest)) if err != nil { if !cerrdefs.IsNotFound(err) { logger.WithError(err).Warn("unexpected error when checking if source image is dangling") } + return nil }