Skip to content

c8d/delete: Add support for deleting specific platforms #49982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 26, 2025

Conversation

vvoland
Copy link
Contributor

@vvoland vvoland commented May 14, 2025

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

`DELETE /images/{name}` now supports a `platforms` query parameter. It accepts an array of JSON-encoded OCI Platform objects, allowing for selecting a specific platforms to delete content for.

- A picture of a cute animal (not mandatory but encouraged)

@vvoland vvoland added this to the 28.2.0 milestone May 14, 2025
@vvoland vvoland self-assigned this May 14, 2025
@vvoland vvoland added area/api impact/api impact/changelog containerd-integration Issues and PRs related to containerd integration area/go-sdk Changes affecting the Go SDK labels May 14, 2025
@vvoland vvoland force-pushed the c8d-image-remove-platform branch 10 times, most recently from fbfefe1 to 0b37530 Compare May 19, 2025 14:52
@vvoland vvoland marked this pull request as ready for review May 19, 2025 14:54
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Had some comments that I didn't submit yet 😓 (not sure if I fully completed review, but let me post these)

if pm.Match(c.ImagePlatform) {
return true
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this path could use a comment to outline we're intentionally not returning false after this, something like;

// No match for the image reference, but continue to check if used as mounted image

(better suggestions welcome!)

(because I was wondering if we forgot a return false here; the comment may help future visitors 😄

Copy link
Member

Choose a reason for hiding this comment

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

☝️ really wondering if this function needs splitting up, because there's a ton of conditions (not for this PR!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes actually I started by refactoring it to make the flow more linear, but turned out that I broke some edge cases in the process and didn't want to spend more time on that 🙈

@vvoland vvoland force-pushed the c8d-image-remove-platform branch 2 times, most recently from 2def89b to a2bc5f1 Compare May 21, 2025 14:24
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +170 to +172
if len(platformJSONs) == 0 {
return nil, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

No need to change; I guess this is a bit redundant (it won't loop if there's nothing to loop, so return output with its nil value)

@vvoland vvoland requested a review from dmcgowan May 21, 2025 15:46
// The same manifest can be referenced by different image indexes.
var response []imagetypes.DeleteResponse
for _, d := range toDelete {
if err := i.content.Delete(ctx, d.Digest); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid doing any direct deletion like this, removing root objects and updating reference labels is the preferred solution. There is no other transactional way to ensure nothing is using the content

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, it's not really ideal, but overall we assume that moby containerd namespace is exclusively accesses by dockerd.

There's a check that at least makes sure that it's not used by any container and that requires an explicit force.

Perhaps we should make it ONLY work with force now? That would make it clear that the operation is potentially dangerous, while still giving an escape hatch for users that want to get rid of platforms they don't need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added 23bfbdf - WDYT?

@vvoland vvoland force-pushed the c8d-image-remove-platform branch from 23bfbdf to 4321767 Compare May 21, 2025 18:03
@thaJeztah thaJeztah requested a review from dmcgowan May 22, 2025 12:07
@thaJeztah
Copy link
Member

@dmcgowan PTAL

vvoland added 5 commits May 26, 2025 17:43
Move to an internal testutils package

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Pass whole `RemoveOptions` struct instead of individual `force` and
`prune` parameters.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This change adds the ability to delete a specific platform from a
multi-platform image.

Previously, image deletion was an all-or-nothing operation - when
deleting a multi-platform image, all platforms would be removed
together. This change allows users to selectively remove individual
platforms from a multi-architecture image while keeping other platforms
intact.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
When deleting specific platforms from a multi-platform image, there's
potential risk as platform-specific content might be shared across
images/containers.

For now, require `force` parameter to make the user aware.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
@vvoland vvoland force-pushed the c8d-image-remove-platform branch from 4321767 to 072483f Compare May 26, 2025 15:43
start := time.Now()
defer func() {
if retErr == nil {
metrics.ImageActions.WithValues("delete").UpdateSince(start)
}
}()

if len(options.Platforms) > 0 && !options.Force {
return nil, cerrdefs.ErrInvalidArgument.WithMessage("Deleting specific platforms is currently considered potentially unsafe because platform-specific content might be shared across images/containers. Use --force to override.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted the error message

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

still LGTM

@thaJeztah
Copy link
Member

Let me bring this one in; an error was added if this option is used without --force that outlines possible consequences; we can revisit other options after this.

@thaJeztah thaJeztah merged commit a9649e7 into moby:master May 26, 2025
175 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api area/go-sdk Changes affecting the Go SDK containerd-integration Issues and PRs related to containerd integration impact/api impact/changelog status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy