system prune: refactor to use "register" functions#6236
system prune: refactor to use "register" functions#6236thaJeztah merged 4 commits intodocker:masterfrom
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
2eaba6c to
1293c45
Compare
|
Interesting; bad test? |
| // Make sure pruners are registered for tests (they're included automatically when building). | ||
| _ "github.com/docker/cli/cli/command/builder" | ||
| _ "github.com/docker/cli/cli/command/container" | ||
| _ "github.com/docker/cli/cli/command/image" | ||
| _ "github.com/docker/cli/cli/command/network" | ||
| _ "github.com/docker/cli/cli/command/volume" |
There was a problem hiding this comment.
We should probably rewrite these tests to use mockups for these (to be looked at in a follow-up).
7262c39 to
bf779eb
Compare
Introduce a "prune" package in which we maintain a list of prune functions that are registered. Known prune "content-types" are included in a pre-defined order, after which additional content can be registered. Using this approach no longer requires the "RunPrune" functions to be exported, and allows additional content-types to be introduced without having to import those packages into the system package, so keeping things more decoupled. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
bf779eb to
d4a9a76
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This adds a "dry-run" / "pre-check" option for prune-functions, which delegates constructing the confirmation message (what is about to be pruned) and validation of the given options to the prune-functions. This helps separating concerns, and doesn't enforce knowledge about what's supported by each content-type onto the system prune command. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Move the version-check for pruners to the pruner, which can return a [ErrNotImplemented] error to indicate they won't be run with the API version that's used. This helps separating concerns, and doesn't enforce knowledge about what's supported by each content-type onto the system prune command. [ErrNotImplemented]: https://pkg.go.dev/github.com/docker/docker@v28.3.3+incompatible/errdefs#ErrNotImplemented Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
These are no longer used, and unlikely to be used externally. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
d4a9a76 to
3b6a556
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the system prune functionality to use a registration-based approach instead of directly importing and calling prune functions from different packages. The changes introduce a new pruner package that maintains a registry of prune functions, allowing for better decoupling and separation of concerns.
- Introduces a
prunerpackage with registration system for prune functions - Delegates confirmation message generation and validation to individual pruners
- Moves API version checks to individual pruners rather than centralized logic
- Removes exported
RunPrunefunctions that are no longer needed
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cli/command/system/pruner/pruner.go |
New package defining the pruner registry system and interfaces |
cli/command/system/prune.go |
Refactored to use the new pruner registry instead of direct imports |
cli/command/{volume,network,image,container,builder}/prune.go |
Updated to register prune functions and replace exported RunPrune with internal pruneFn |
cli/command/system/prune_test.go |
Added imports to ensure pruners are registered for tests |
Benehiko
left a comment
There was a problem hiding this comment.
LGTM, I couldn't see anything obvious in the PR that could be problematic.
|
@vvoland have time to give this a second pair of eyes? |
system prune: use register function for prune functions
Introduce a "prune" package in which we maintain a list of prune
functions that are registered. Known prune "content-types" are
included in a pre-defined order, after which additional content
can be registered.
Using this approach no longer requires the "RunPrune" functions
to be exported, and allows additional content-types to be
introduced without having to import those packages into the
system package, so keeping things more decoupled.
system prune: delegate confirmation message and validation
This adds a "dry-run" / "pre-check" option for prune-functions,
which delegates constructing the confirmation message (what is
about to be pruned) and validation of the given options to the
prune-functions.
This helps separating concerns, and doesn't enforce knowledge
about what's supported by each content-type onto the system
prune command.
system prune: delegate version check
Move the version-check for pruners to the pruner, which can
return a ErrNotImplemented error to indicate they won't
be run with the API version that's used.
This helps separating concerns, and doesn't enforce knowledge
about what's supported by each content-type onto the system
prune command.
cli/command: remove exported "RunPrune" functions
These are no longer used, and unlikely to be used externally.
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)