Support connecting and disconnecting containers to networks after creation#40549
Support connecting and disconnecting containers to networks after creation#40549beena352 wants to merge 9 commits into
Conversation
…eenachauhan/wslc-attach-detach-network # Conflicts: # test/windows/WSLCTests.cpp
There was a problem hiding this comment.
Pull request overview
This PR adds WSLC APIs intended to attach and detach already-created containers from WSLC-managed Docker networks, plus tests for the new attach/detach behavior.
Changes:
- Adds session-level
AttachContainerToNetworkandDetachContainerFromNetworkdeclarations and implementations. - Adds Docker HTTP client helpers and request schema types for network connect/disconnect endpoints.
- Adds WSLC tests covering round-trip attach/detach and several validation paths.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/windows/service/inc/wslc.idl |
Adds new network attach/detach methods to IWSLCSession. |
src/windows/wslcsession/WSLCSession.h |
Declares the new session methods. |
src/windows/wslcsession/WSLCSession.cpp |
Implements validation, lookup, Docker connect/disconnect calls, and logging. |
src/windows/wslcsession/WSLCContainer.h |
Exposes container network mode to session logic. |
src/windows/wslcsession/DockerHTTPClient.h |
Declares Docker network connect/disconnect helpers. |
src/windows/wslcsession/DockerHTTPClient.cpp |
Implements Docker network connect/disconnect endpoint calls. |
src/windows/inc/docker_schema.h |
Adds request payload schemas for Docker network connect/disconnect. |
test/windows/WSLCTests.cpp |
Adds tests for attach/detach network behavior and validation. |
Comments suppressed due to low confidence (4)
test/windows/WSLCTests.cpp:6293
- This call targets
IWSLCContainer::AttachToNetwork, but that method is not declared onIWSLCContainer; the added API isIWSLCSession::AttachContainerToNetwork. Update the test to call through the session with the launched container's ID.
VERIFY_ARE_EQUAL(E_INVALIDARG, container.Get().AttachToNetwork(&attachment));
test/windows/WSLCTests.cpp:6321
- This call will not compile because
AttachToNetworkis not part ofIWSLCContainer; the new attach method is onIWSLCSession. Use the session-level API with this container's ID.
VERIFY_ARE_EQUAL(E_INVALIDARG, container.Get().AttachToNetwork(&attachment));
test/windows/WSLCTests.cpp:6332
- This call will not compile because
AttachToNetworkis not declared onIWSLCContainer; call the session-level attach API with the container ID instead.
VERIFY_ARE_EQUAL(E_INVALIDARG, container.Get().AttachToNetwork(&attachment));
test/windows/WSLCTests.cpp:6347
- This call targets a non-existent
IWSLCContainer::AttachToNetworkmethod. The attach API added in this PR is session-level, so the test should useAttachContainerToNetworkon the session with the container ID.
VERIFY_ARE_EQUAL(E_NOTIMPL, container.Get().AttachToNetwork(&attachment));
dkbennett
left a comment
There was a problem hiding this comment.
LGTM, the copilot comments on the ABI can be ignored since we haven't shipped it yet, but soon we can't ignore that. The comments about sending to docker without checking may have some merit, though I believe the model is send it to docker and then we report the docker error if there's a problem, so that's probably OK, and something easy to fix later if not.
kvega005
left a comment
There was a problem hiding this comment.
I think this stuff uint the PR description got copied from another PR:
- Uses existing lock pattern: m_lock.lock_shared() then scoped_lock(m_containersLock, m_networksLock)
- Cleans up deleted containers via erase_if before lookup
- Error handling follows DeleteNetwork pattern: local validation with exact errors, Docker errors surfaced via catch-all
Those were from the original design, I moved the methods from IWSLCSession to IWSLCContainer after review feedback but didn't update the description. Fixed now. |
Summary of the Pull Request
Implements ConnectToNetwork and DisconnectFromNetwork methods on IWSLCContainer, enabling containers to join/leave networks after they are created and running.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
ConnectDisconnectContainerNetworkRoundTripTest: Create bridged container → create network → connect → verify via inspect (network appears with IP) → disconnect → verify gone
ConnectDisconnectContainerValidationTest:
Empty NetworkName → E_INVALIDARG (both connect and disconnect)
Nonexistent network → WSLC_E_NETWORK_NOT_FOUND (both connect and disconnect)
Host and None mode containers → E_INVALIDARG (both connect and disconnect)
ContainerIpAddress set → E_NOTIMPL