Repository navigation
refactor: remove the helpers duplicated across pkg/compose and the internal packages - #14424
Merged
Merged
Conversation
pkg/compose carried its own copy of the event constructors that internal/progress already provides. Use the shared ones and move the generic waiting, healthy, exited and skipped events there too. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
pkg/compose kept private copies of the canonical, default and project-less container name helpers that internal/naming already provides. Use the shared ones, and host the project-prefix stripping that compose.go and monitor.go each implemented. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The label=key=value filter was rebuilt in pkg/compose, internal/inspect, internal/relay, cmd/compose and pkg/bridge. Build it once in internal/naming and use it everywhere. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
internal/projectloader and pkg/compose each rebuilt a service definition from the containers of a project with the same bootstrap and replica counting. Keep it in internal/projectloader and call it from both. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
internal/inspect and internal/containerops declared the same engine methods and one-off enum, and pkg/compose adapted them twice. Declare them in internal/engine, embed them in both Backend interfaces and keep a single adapter. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
images and volumes each looped over the project containers to keep those of the selected services, as internal/inspect already did for ps and top. Use one helper for all four. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
internal/containerops and pkg/compose both had a copy of forEachContainerConcurrent. Provide it once, generic, in internal/concurrency. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The quiet display, pkg/compose and three test files each defined an api.EventProcessor doing nothing. Provide it once as internal/progress.Noop. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
pull and push decoded the daemon's JSON message stream with the same loop and computed the completion percentage the same way. Move both to helpers. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Several places copied the keys of a map into a slice and sorted it by hand, some through their own generic helper. Use slices.Sorted(maps.Keys(m)), keeping the sorted order of the output. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…ambles pause and unpause listed and filtered their containers identically, and down, kill, stop and restart each re-spelled how to fall back to the project rebuilt from the engine. Each now has a single helper. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Ping and FeatureFlags issued the same GET and decoded the same way. Share the request, status check and decoding in get[T]. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…ents ReplaceExtendsFile and ReplaceEnvFile started with the same parsing and lookup of the service node. Move it to a helper. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The four menu shortcuts that open a Docker Desktop view repeated the same background span, open and error reporting. Only the link and the error wording differ. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The volume, network and relay link network removals of down each spelled out the same acquire/release of the shared limiter. Wrap them with a helper built on internal/concurrency. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
create and createAndStart prepared, announced and executed their plan identically, differing only by scope. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The four throttle device lists of the blkio configuration were converted by four identical loops. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The service depends_on was written to a container label in create.go and read back in compose.go, each side knowing the other's format only by convention. Put the encoder and decoder side by side, with a round-trip test; the label content is unchanged. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
create and up each carried the same normalization function mapping the mistaken --y spelling to --yes. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…place Eight config subcommands created a Compose service and loaded the project with the same four lines. Move them to a helper of configOptions. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…one helper DescriptorForComposeFile and DescriptorForEnvFile only differed by their media type and annotation key. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
dupl reports blocks of syntax that are the same up to a renaming of identifiers and literals, which is the kind of copy this series removed; it does not see semantic equivalents such as reordered operands, which stay a matter for review. The threshold is 80 tokens; tests and the e2e DSL are excluded, and the few remaining pairs (declarative cobra commands, mirrored event and lookup functions) carry a targeted nolint with the reason. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
dock-tor
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #14396
What this PR does, in one sentence
Removes the copies of the same helper that the #14396 extractions and older code left in several places, one commit per case, without changing any behavior.
Context
Moving code out of
pkg/composeintointernal/*packages recopied a number of small helpers (progress events, container names, label filters, engine adapters, event processors that do nothing...) instead of lettingpkg/composeuse the extracted ones, and a few older copies were never merged. A duplication analysis, which also finds equivalent blocks written differently, listed them and the places that should share one implementation.What the PR brings
One commit per case, behavior unchanged, tests kept with the same assertions (new helpers get a small test of their own).
Shared core, now used by
pkg/composeand theinternal/*packages alike:internal/progress, including aNoopevent processor);label=key=valuefilters (internal/naming);internal/projectloader);internal/inspectandinternal/containeropsboth declared, now ininternal/enginewith a single adapter inpkg/compose;internal/concurrency).Local clean-ups: the pull/push stream decoding, sorted map keys through
slices.Sorted(maps.Keys(m)), pause/unpause, the project fallback of down/kill/stop/restart, the Desktop clientget[T], the yaml replacements, the Desktop shortcuts, the limiter gating ofdown, create/createAndStart, the blkio throttle devices, thedepends_onlabel codec (encoder and decoder side by side, with a round-trip test), the--yflag, theconfigsubcommands and the OCI layer descriptors.Where two copies differ in behavior (an edge case handled in one and not in the other), they are deliberately left alone rather than unified, so each commit stays a pure de-duplication.
The last commit enables the
dupllinter so that new copies show up in review: it reports blocks of syntax that are equivalent up to a renaming of identifiers and literals, and does not detect semantic equivalents such as reordered operands, which remain a matter for review. The threshold is 80 tokens, tests and the e2e DSL are excluded, and the few remaining pairs (declarative cobra commands, mirrored event and lookup functions) carry a targeted//nolint:duplwith the reason.Why this is the right next brick
It keeps the #14396 series from leaving two implementations of every helper behind: the extracted packages become the single source for the shared core, and the linter keeps it that way. It only touches helpers and their call sites, so it is independent of the other extractions in flight.
🤖 Generated with Claude Code