feat: clean up stale HNS resources on NC create for delegated NICs in SwiftV2#4290
Open
jackieluc wants to merge 2 commits intoAzure:masterfrom
Open
feat: clean up stale HNS resources on NC create for delegated NICs in SwiftV2#4290jackieluc wants to merge 2 commits intoAzure:masterfrom
jackieluc wants to merge 2 commits intoAzure:masterfrom
Conversation
b0f802a to
3a934e6
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in mechanism in CNS to proactively clean up stale Windows HNS endpoint/network resources (and corresponding CNS endpoint-state entries) during CreateNetworkContainer for SwiftV2 delegated NIC scenarios, helping unblock NC creation when a delegated NIC/MAC is reused.
Changes:
- Introduces
EnableStaleHNSCleanupOnNCCreateconfig/option and wires it into CNS service options. - Adds stale-resource detection/cleanup helpers (
normalizeMAC,findEndpointStateByMAC,cleanupStaleHNSResources) invoked on ACI NC create when delegated NIC info is present and endpoint-state management is enabled. - Adds an
HNSClientabstraction for deletions (with tests) and emits a cleanup metric.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| common/config.go | Adds new option key for enabling stale HNS cleanup on NC create. |
| cns/configuration/configuration.go | Adds config field to toggle stale HNS cleanup behavior. |
| cns/service/main.go | Wires new config flag into CNS service options. |
| cns/restserver/restserver.go | Injects an hnsClient into HTTPRestService for runtime + testability. |
| cns/restserver/api.go | Triggers stale HNS cleanup during ACI CreateNetworkContainer under gating conditions. |
| cns/restserver/ipam.go | Implements MAC normalization, endpoint-state lookup by MAC, cleanup logic, and metric emission. |
| cns/restserver/ipam_test.go | Adds unit tests for MAC lookup and stale HNS cleanup (with a mock HNS client). |
| cns/logger/constants.go | Adds metric name constant for stale HNS cleanup telemetry. |
| cns/hnsclient/hnsclient.go | Introduces HNSClient interface + default implementation. |
| cns/hnsclient/hnsclient_windows.go | Exposes DeleteNetworkByIDHnsV2 wrapper used by the client interface. |
| cns/hnsclient/hnsclient_linux.go | Adds non-Windows stubs for the new delete-by-ID functions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
/azp run Azure Container Networking PR |
|
Azure Pipelines successfully started running 1 pipeline(s). |
a7fde2f to
f137028
Compare
Member
Author
|
/azp run Azure Container Networking PR |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
This pull request is stale because it has been open for 2 weeks with no activity. Remove stale label or comment or this will be closed in 7 days |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for Change:
EnableStaleHNSCleanupOnNCCreateconfig flag (also gated behind several conditions:NetworkingContainerType== ACI,ManageEndpointState, and NC has delegated NIC type)CreateNetworkContainerwhen a delegated NIC MAC is reused by a new NC. This handles cases where a previous NC was not properly cleaned up (e.g., CNI DEL was never called because of containerd issues), which kept stale HNS resources and blocked new SwiftV2 NC creations due to control plane thinking the NIC was available when in reality it was not.HNSClientfor CNS and for testingTesting:
cleanupStaleHNSResourcesandfindEndpointStateByMACIssue Fixed:
Requirements:
Notes: