Skip to content

[shimV2] added network controller implementation#2633

Merged
rawahars merged 4 commits intomicrosoft:mainfrom
rawahars:network-controller
Apr 6, 2026
Merged

[shimV2] added network controller implementation#2633
rawahars merged 4 commits intomicrosoft:mainfrom
rawahars:network-controller

Conversation

@rawahars
Copy link
Copy Markdown
Contributor

Summary

This change adds the network controller implementation for V2 shims which manages the network lifecycle for a single pod running inside a UVM. The implementation provides a clear lifecycle state machine, separates platform-specific logic for LCOW and WCOW. This controller will be initialized from VMController which can inject the low-level managers to perform VM host + guest network operations.

The main changes are grouped below.

Network controller implementation:

  • Implemented the Controller interface and its concrete Manager type, providing Setup and Teardown methods to manage HCN namespaces and endpoints for a pod (internal/controller/network/interface.go, internal/controller/network/network.go).

Platform-specific guest operations:

  • Added platform-specific files for LCOW and WCOW, implementing guest-side network namespace and endpoint management with proper separation via build tags (internal/controller/network/network_lcow.go, internal/controller/network/network_wcow.go).

Lifecycle state management:

  • Defined a State type to track the network lifecycle, including transitions for setup, teardown, and error handling (internal/controller/network/state.go).

@rawahars rawahars requested a review from a team as a code owner March 17, 2026 21:57
This change adds the network controller implementation for V2 shims which manages the network lifecycle for a single pod running inside a UVM.

Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
@rawahars rawahars force-pushed the network-controller branch from 0336432 to e901ab7 Compare March 20, 2026 19:11
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Copy link
Copy Markdown
Contributor

@helsaawy helsaawy left a comment

Choose a reason for hiding this comment

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

if we are going to gate the Controller functionality by build tags, can we fully extend it to the GuestNetworkManager types?
that way we don't have to deal with unused fields in either case:

//
// internal/controller/network/network.go 
//

type Controller struct {
	// ...

	// guestMgr manages the guest-side NIC operations.
	guestMgr guestNetworkManager

	// ...
}

// New creates a ready-to-use Controller in [StateNotConfigured].
func New(
	vmNetManager vmNetworkManager,Expand commentComment on line R51Resolved
	guestMgr guestNetworkManager,
) *Controller {

//
// internal/controller/network/network_lcow.go 
//

// guestNetworkManager exposes linux guest network operations.
// Implemented by [guestmanager.Guest].
type guestNetworkManager interface {
	// AddLCOWNetworkInterface adds a network interface to the LCOW guest.
	AddLCOWNetworkInterface(ctx context.Context, settings *guestresource.LCOWNetworkAdapter) error
	// RemoveLCOWNetworkInterface removes a network interface from the LCOW guest.
	RemoveLCOWNetworkInterface(ctx context.Context, settings *guestresource.LCOWNetworkAdapter) error
}

//
// internal/controller/network/network_wcow.go 
//

// guestNetworkManager exposes windows guest network operations.
// Implemented by guestmanager.Guest.
type guestNetworkManager interface {
	// AddNetworkNamespace adds a network namespace to the WCOW guest.
	AddNetworkNamespace(ctx context.Context, settings *hcn.HostComputeNamespace) error
	// RemoveNetworkNamespace removes a network namespace from the WCOW guest.
	RemoveNetworkNamespace(ctx context.Context, settings *hcn.HostComputeNamespace) error
	// AddNetworkInterface adds a network interface to the WCOW guest.
	AddNetworkInterface(ctx context.Context, adapterID string, requestType guestrequest.RequestType, settings *hcn.HostComputeEndpoint) error
	// RemoveNetworkInterface removes a network interface from the WCOW guest.
	RemoveNetworkInterface(ctx context.Context, adapterID string, requestType guestrequest.RequestType, settings *hcn.HostComputeEndpoint) error
}

@helsaawy
Copy link
Copy Markdown
Contributor

helsaawy commented Apr 2, 2026

also, more of a nit, but can WCOW be the default and therefore have LCOW require the lcow build tag?

Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
@rawahars rawahars force-pushed the network-controller branch from c2d5a77 to 01a48e5 Compare April 4, 2026 23:49
@rawahars
Copy link
Copy Markdown
Contributor Author

rawahars commented Apr 4, 2026

@helsaawy Made the suggested changes. These changes are inline with other places now.
Please take a look.

//
// Guest-side operations differ between LCOW and WCOW and are implemented in
// platform-specific source files selected via build tags
// ("lcow" tag for LCOW shim, "wcow" tag for WCOW shim).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why did we go with not go with WCOW being the default?
it will likely cause more problems that the default build fails during runtime rather than assuming WCOW

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right that was the intention based on discussion with Justin.
LCOW shim needs to be specifically compiled using lcow tag and WCOW with wcow. There's no default otherwise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so just building a shim will always give us something entirely non-functional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes that's true! It's purely intent driven with new shim.

@rawahars rawahars merged commit 89f99da into microsoft:main Apr 6, 2026
17 checks passed
@rawahars rawahars deleted the network-controller branch April 6, 2026 17:00
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.

4 participants