Skip to content

fix!: make network inspect Docker-compatible#48

Open
jahirvidrio wants to merge 2 commits into
us:mainfrom
jahirvidrio:fix/network-inspect-docker-compat
Open

fix!: make network inspect Docker-compatible#48
jahirvidrio wants to merge 2 commits into
us:mainfrom
jahirvidrio:fix/network-inspect-docker-compat

Conversation

@jahirvidrio

Copy link
Copy Markdown
Contributor

What problem does this solve?

mocker network inspect <name> and mocker inspect --type=network <name> emit mocker's internal NetworkInfo shape — a single lowercase JSON object via TableFormatter.printJSON, not the Docker network.Inspect array of objects with PascalCase keys and nested IPAM. Scripts that pipe to jq and expect Docker fields (.IPAM.Config[0].Subnet, .Containers, top-level array) break.

mocker inspect --type=network <name> is also rejected at parse time today: the InspectObjectType enum only knows image | container, so the route is silently absent. Same for the auto-fallback path — mocker inspect <name> never tries network even when the target exists as a network.

This closes the last shipped command in the Docker-parity gap after #25 (image inspect) and #40 (container inspect).

What changed

  • New NetworkInspect DTO + pure mapToNetworkInspect mapper in Sources/MockerKit/Models/NetworkInspect.swift, mirroring the image- and container-inspect pattern. NetworkIPAM conforms to Encodable only with a custom encode(to:) that calls encodeNil(forKey: .Options) — Docker emits literal "Options": null for an unset IPAM driver-options map, not {}, and the default Swift Codable would have emitted {}.
  • New inspectNetworks collector in Sources/MockerKit/Models/InspectOperations.swift with accumulate-then-fail multi-arg semantics: unknown targets emit Error response from daemon: network <name> not found to stderr, processing continues, exit 1 at the end. This intentionally diverges from inspectContainers (which throws on first miss) — copying that pattern would break multi-arg parity with docker network inspect a b c.
  • Sources/Mocker/Commands/Network.swift: rewired NetworkInspect to variadic names: [String], removed the --verbose flag (was a no-op), and migrated output from TableFormatter.printJSON to InspectFormat.emitArray so the subcommand emits a Docker-shaped JSON array with unescaped slashes and honors --format / --format json the same way image and container inspect already do.
  • Sources/Mocker/Commands/Inspect.swift: extended InspectObjectType with .network, added the .network branch in run(), and added network as a third attempt in the auto-fallback loop after containers and images so mocker inspect <name> resolves to a network when neither matches.
  • Containers map ships as {} empty for v0.6.0. Apple-runtime enrichment (real EndpointID / MacAddress / IPv4Address from container network inspect <id>) is intentionally deferred to a non-breaking follow-up so the breaking-shape change lands within the review budget. Fabricating Name-only stub entries was considered and rejected: Docker never emits entries with empty runtime-field strings, so doing so would invent a shape Docker would never produce.

Breaking change

mocker network inspect no longer emits the lowercase NetworkInfo object. Scripts that read .subnet, .gateway, or .containers from a top-level object must migrate to .IPAM.Config[0].Subnet, .IPAM.Config[0].Gateway, and .Containers (a map, empty {} in v0.6.0 until the enrichment follow-up). The top-level is now a JSON array, so jq filters need .[0].Name instead of .name. mocker inspect --type=network <id> is a new route — it did not exist before — so nothing breaks there. Multi-arg network inspect a b c now returns one combined array (previously rejected: single-arg only).

'mocker network inspect' returned the internal NetworkInfo shape via
TableFormatter.printJSON (a single lowercase object). Add a NetworkInspect
DTO + pure mapToNetworkInspect mapper (mirroring the image- and
container-inspect pattern), add an inspectNetworks collector with
Docker-compatible accumulate-then-fail multi-arg semantics, and migrate
the subcommand to InspectFormat.emitArray so it emits a Docker-shaped
JSON array with unescaped slashes.

Containers map is always {} in v0.6.0 — Apple-runtime enrichment is
deferred to a non-breaking follow-up PR.

BREAKING CHANGE: 'mocker network inspect' now returns a Docker-compatible
JSON array with the moby v29.6.1 network.Inspect shape (PascalCase keys,
nested IPAM, Containers map) instead of the previous lowercase NetworkInfo
object. Scripts consuming '.subnet' / '.gateway' / '.containers' (string
array) must migrate to '.IPAM.Config[0].Subnet' / '.IPAM.Config[0].Gateway'
/ '.Containers' (map). Multi-arg invocation now returns one combined array
(previously single-arg only).
'mocker inspect --type=network' was rejected at parse time because the
InspectObjectType enum only knew image and container. Extend the enum
with .network, add the .network branch in Inspect.run() that routes
through the NetworkInspect DTO from the prior commit, and expand the
auto-fallback loop with a third attempt after containers and images so
'mocker inspect <name>' resolves to a network when neither matches.
Both invocation paths emit byte-identical Docker-shaped JSON arrays
because they share inspectNetworks + InspectFormat.emitArray.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant