Support arbitrary network driver options in wslc network create#40859
Support arbitrary network driver options in wslc network create#40859beena352 wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends WSLC network management to support arbitrary Docker network driver options end-to-end (create → inspect JSON output → session recovery), while still treating a small set of reserved keys (Internal, Subnet, Gateway) as typed inputs with strict casing to avoid silent misinterpretation.
Changes:
- Allow non-reserved
DriverOptsto pass through to Docker’sCreateNetwork.Options, while rejecting case-mismatches for reserved keys. - Persist and surface network
Optionsin WSLC’s in-memory metadata and JSON schema (wslc_schema::Network), including after session recovery. - Add/adjust Windows tests to validate arbitrary options round-trip and recovery behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Updates invalid-option expectations (case-mismatch only for reserved keys) and adds coverage for arbitrary driver options + recovery persistence. |
| src/windows/wslcsession/WSLCSession.cpp | Implements reserved-key case-mismatch validation, forwards non-reserved options to Docker, and stores/returns Options on inspect and recovery. |
| src/windows/wslcsession/WSLCNetworkMetadata.h | Extends the cached network entry to include Options. |
| src/windows/inc/wslc_schema.h | Adds optional Options to WSLC inspect-network JSON schema. |
| src/windows/inc/docker_schema.h | Adds optional Options to Docker network create/inspect schema used by the client. |
| <data name="MessageWslcInvalidNetworkDriverOption" xml:space="preserve"> | ||
| <value>Unsupported network driver option: '{}'</value> | ||
| <comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment> | ||
| <value>Network driver option '{}' is case-sensitive. Use the exact casing: Internal, Subnet, or Gateway.</value> |
There was a problem hiding this comment.
How does docker the docker API react if it's passed these options with the wrong casing ? Does it just ignore them ?
There was a problem hiding this comment.
Yeah, Docker just silently accepts them. I disabled our validation temporarily and tested with --opt internal=true --opt subnet=172.55.0.0/16 --opt gateway=172.55.0.1 - all lowercase. Our InspectNetwork is a direct HTTP GET to Docker's /networks/{id} endpoint (deserialized 1:1), and it shows:
Internal: false (typed field never got set)
Subnet: 172.18.0.0/16, Gateway: 172.18.0.1 (Docker picked its own defaults)
Options: {"internal": "true", "subnet": "172.55.0.0/16", "gateway": "172.55.0.1"} (stored but doing nothing)
So from Docker's side, the lowercase keys just end up as inert entries in the Options map - the network gets created but is silently broken. That's why we reject the case mismatch up front.

There was a problem hiding this comment.
Ok in that case I think we should match their behavior. From a UX perspective I think the best way to this would be to implement the CLI options for these values that docker has (--internal, gateway , ...) and not to any specific casing check in the service
…eenachauhan/feat/wslc-network-arbitrary-driver-opts
Summary of the Pull Request
Adds support for passing arbitrary driver options through to Docker when creating networks with wslc network create. Previously, only Internal, Subnet, and Gateway were recognized - any other option was silently dropped. Now unknown keys are forwarded to Docker and round-tripped through wslc network inspect. Case-mismatches of the three reserved keys (e.g., internal instead of Internal) are still rejected with a clear error.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Problem: wslc network create --opt my.abc.key=mygod silently dropped the option, it never reached Docker and network inspect showed no trace of it. Docker itself supports arbitrary driver options on networks; wslc should too.
Changes:
docker_schema.h- Added Options field to CreateNetwork and Network structs (same pattern already used by Volume).
wslc_schema.h- Added Options field to the output Network struct so inspect can surface them.
WSLCNetworkMetadata.h- Added Options to NetworkEntry cache.
WSLCSession.cpp: Changed validation from "reject all unknown keys" to "reject only case-mismatches of reserved keys" (Internal, Subnet, Gateway).
Forwards non-reserved driver opts into request.Options for Docker.
Copies Options from Docker's inspect response into the session cache.
Surfaces Options in InspectNetwork output.
Added Options copy in RecoverExistingNetworks so custom opts survive session restart.
WSLCTests.cpp:
Updated NetworkCreateInvalidDriverAndOptionTest- removed "foo" from rejection list (it's now a valid pass-through key).
New NetworkCreateWithArbitraryDriverOptsTest- creates with two custom opts, inspects and verifies they round-trip.
Extended NetworkSessionRecoveryTest- verifies custom opts survive session recovery.
Validation Steps Performed