Skip to content

containerd integration: Implement ImageDelete for containerd#43820

Merged
cpuguy83 merged 1 commit intomoby:masterfrom
thaJeztah:image_delete
Aug 3, 2022
Merged

containerd integration: Implement ImageDelete for containerd#43820
cpuguy83 merged 1 commit intomoby:masterfrom
thaJeztah:image_delete

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Jul 15, 2022

- What I did

Implemented image deletion for containerd

@thaJeztah thaJeztah added this to the v-next milestone Jul 15, 2022
@thaJeztah thaJeztah force-pushed the image_delete branch 2 times, most recently from 3473542 to 224b540 Compare July 18, 2022 18:57
@thaJeztah thaJeztah marked this pull request as ready for review July 19, 2022 08:22
@thaJeztah thaJeztah added the containerd-integration Issues and PRs related to containerd integration label Jul 21, 2022
Comment on lines +45 to +46
// FIXME(thaJeztah): implement ImageDelete "force"
// FIXME(thaJeztah): implement ImageDelete "prune"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me create tracking issues for these

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic("not implemented")
func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error) {
// 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussion in the maintainers meeting; we need to add more tracking issues for; partial IDs etc. (some of that logic is implemented in GetImage() as part of #43818)

@thaJeztah
Copy link
Member Author

@corhere @tianon @rumpl PTAL

// 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

records := []types.ImageDeleteResponseItem{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@thaJeztah thaJeztah Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah, I don't always agree with that rule (sometimes it's really more convenient to initialise it if later on we need to append() (edit: ignore me on that one), and make(...) is a bit cumbersome (or sometimes overdoing it).

That said; it looks like (at least currently) it'll only ever create a single instance, so I don't think we need this variable at all; we can just return []types.ImageDeleteResponseItem{}{d} at the end of the function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes it's really more convenient to initialise it if later on we need to append()

Hmm? append() works on nil slices, same as non-nil but empty slices. You might be thinking of maps, where assigning to a nil map panics.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just edited, indeed had maps in mind 🙈

ref := reference.TagNameOnly(parsedRef)

if err := i.client.ImageService().Delete(ctx, ref.String(), images.SynchronousDelete()); err != nil {
return []types.ImageDeleteResponseItem{}, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come an empty slice is returned here but the error-return for ParseNotmalizedNamed (line 52) returns nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch; at a glance, I think can be just nil as well, unless there's some expectation somewhere (nil vs nil type)? Overall the returned value shouldn't be used if there's an error.

Let me have a look at that.

for _, ref := range refs {
imgDel, err := i.ImageDelete(ref.String(), false, true)
imgDel, err := i.ImageDelete(ctx, ref.String(), false, true)
if imageDeleteFailed(ref.String(), err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like imageDeleteFailed() needs to be updated so it doesn't log a spurious warning when the context is canceled.

case err == nil:
return false
case errdefs.IsConflict(err):
case errdefs.IsConflict(err), errors.Is(err, context.Canceled):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case errdefs.IsConflict(err), errors.Is(err, context.Canceled):
case errdefs.IsConflict(err), errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):

Annoyingly, you need to enumerate all the possible context errors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL; I actually had the DeadlineExceeded, and started to think if that one would be one to actually log, so removed it; let me add it back 😂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's back (it was literally CMD+Z - last edit I made 😂 )

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Member Author

@AkihiroSuda @tonistiigi PTAL

@cpuguy83 cpuguy83 merged commit 7e8df0e into moby:master Aug 3, 2022
@thaJeztah thaJeztah deleted the image_delete branch August 3, 2022 22:49
crazy-max pushed a commit to crazy-max/moby that referenced this pull request Sep 29, 2022
containerd integration: Implement ImageDelete for containerd
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/images Image Distribution containerd-integration Issues and PRs related to containerd integration status/2-code-review

Projects

Development

Successfully merging this pull request may close these issues.

4 participants