Skip to content

Support connecting and disconnecting containers to networks after creation#40549

Open
beena352 wants to merge 9 commits into
microsoft:masterfrom
beena352:user/beenachauhan/wslc-attach-detach-network
Open

Support connecting and disconnecting containers to networks after creation#40549
beena352 wants to merge 9 commits into
microsoft:masterfrom
beena352:user/beenachauhan/wslc-attach-detach-network

Conversation

@beena352
Copy link
Copy Markdown
Contributor

@beena352 beena352 commented May 15, 2026

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

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [X ] Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

  • Acquires m_lock.lock_shared() for thread safety
  • Validates input before calling Docker: empty network name, unsupported IP address, Host/None network mode
  • Docker errors surfaced via THROW_DOCKER_USER_ERROR_MSG

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

@beena352 beena352 marked this pull request as ready for review May 15, 2026 16:10
@beena352 beena352 requested a review from a team as a code owner May 15, 2026 16:10
Comment thread src/windows/service/inc/wslc.idl Outdated
Comment thread src/windows/wslcsession/WSLCSession.cpp Outdated
…eenachauhan/wslc-attach-detach-network

# Conflicts:
#	test/windows/WSLCTests.cpp
Copilot AI review requested due to automatic review settings May 16, 2026 00:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AttachContainerToNetwork and DetachContainerFromNetwork declarations 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 on IWSLCContainer; the added API is IWSLCSession::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 AttachToNetwork is not part of IWSLCContainer; the new attach method is on IWSLCSession. 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 AttachToNetwork is not declared on IWSLCContainer; 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::AttachToNetwork method. The attach API added in this PR is session-level, so the test should use AttachContainerToNetwork on the session with the container ID.
        VERIFY_ARE_EQUAL(E_NOTIMPL, container.Get().AttachToNetwork(&attachment));

Comment thread test/windows/WSLCTests.cpp Outdated
Comment thread test/windows/WSLCTests.cpp Outdated
Comment thread src/windows/service/inc/wslc.idl
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread src/windows/service/inc/wslc.idl Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
@kvega005 kvega005 self-requested a review May 21, 2026 19:23
dkbennett
dkbennett previously approved these changes May 21, 2026
Copy link
Copy Markdown
Member

@dkbennett dkbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread test/windows/WSLCTests.cpp Outdated
Comment thread test/windows/WSLCTests.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Copy link
Copy Markdown
Contributor

@kvega005 kvega005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@beena352
Copy link
Copy Markdown
Contributor Author

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.

@beena352 beena352 changed the title Support attaching and detaching containers to networks after creation Support connecting and disconnecting containers to networks after creation May 26, 2026
Copilot AI review requested due to automatic review settings May 26, 2026 19:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread src/windows/service/inc/wslc.idl
Comment thread src/windows/wslcsession/WSLCContainer.h Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp
Comment thread test/windows/WSLCTests.cpp Outdated
Comment thread src/windows/service/inc/wslc.idl Outdated
Comment thread test/windows/WSLCTests.cpp Outdated
Copilot AI review requested due to automatic review settings May 27, 2026 17:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/windows/service/inc/wslc.idl
Comment thread src/windows/service/inc/wslc.idl
Comment thread src/windows/inc/docker_schema.h Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.h Outdated
Comment thread test/windows/WSLCTests.cpp Outdated
OneBlue
OneBlue previously approved these changes May 29, 2026
Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copilot AI review requested due to automatic review settings June 4, 2026 23:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/inc/wslc.idl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants