Skip to content

Conversation

@tamilmani1989
Copy link
Member

@tamilmani1989 tamilmani1989 commented Sep 5, 2025

This PR updates both CNS and CNI code to support apipa nic creation in swiftv2. The code has been refactored to construct apipa nic as separate entry in podIpInfo if either of allowhostonc or allownctohost set. CNI when it does RequestIPs call to CNS and CNS return apipa nic as separate entry in PodIPInfo. This allows CNI to treat this as separate endpoint and align with current cni design/model of 1 nic per endpoint info. CNI then iterates through endpoint info and creates one nic at a time. NetworkContainerID is included in PodIPInfo as apipa endpoint creation gets details based on that. This is also required during delete as HNS endpoint for apipa is constructed based on networkcontainerid. Added DeleteEndpointState API in CNS to remove state when CNI delete call is invoked. DeleteEndpointState removes state from CNS statefile.

Previously, in non-multitenancy scenarios ipamInvoker.Delete would automatically clean up state (cns finds infra container id)
and
Now, swiftv2 multitenancy does not call plugin.ipamInvoker.Delete and so state does not automatically clean up and requires explicit DeleteEndpointState API call in cns

CNS State looks like this:


{
        "Endpoints": {
                "230ebd0bcea0220dd0bcb82fbc1a84c7d91f8cad53ff503e3e6b816d55aa35d9": {
                        "PodName": "",
                        "PodNamespace": "",
                        "IfnameToIPMap": {
                                "Ethernet 3": {
                                        "IPv4": null,
                                        "HnsEndpointID": "8d07a074-796c-4cbf-921e-14bf29d78cae",
                                        "HnsNetworkID": "89e5843c-68b6-4f6c-a3c7-c602380d8909",
                                        "MacAddress": "00:22:48:0a:7a:c3",
                                        "NICType": "FrontendNIC"
                                },
                                "HostNCApipaEndpoint-Swift_1fe8a29c-c61c-480c-8732-ff369f97a5cd": {
                                        "IPv4": null,
                                        "HnsEndpointID": "92e64863-c91a-4123-b417-0a8bf6ed7c80",
                                        "NetworkContainerID": "Swift_1fe8a29c-c61c-480c-8732-ff369f97a5cd",
                                        "NICType": "ApipaNIC"
                                }
                        }
                },

Reason for Change:

Issue Fixed:

Requirements:

Notes:

This PR updates both CNS and CNI code to construct apipa nic as separate entry
in podIpInfo if either of allowhostonc or allownctohost set. This allows CNI to
treat this as separate endpoint and align with current cni design/model of
1 nic per endpoint info. CNI then iterates through endpoint info and creates one
nic at a time.

Signed-off-by: Tamilmani <[email protected]>
Copilot AI review requested due to automatic review settings September 5, 2025 21:27
@tamilmani1989 tamilmani1989 requested review from a team as code owners September 5, 2025 21:27
@tamilmani1989 tamilmani1989 marked this pull request as draft September 5, 2025 21:27
Copy link
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 refactors the handling of APIPA (Automatic Private IP Addressing) NICs by creating them as separate entries in the podIpInfo structure when either allowhostonc or allownctohost flags are set. This aligns with the CNI design model of having one NIC per endpoint.

  • Introduces a new ApipaNIC type constant for APIPA network interface classification
  • Adds logic to create separate APIPA NIC entries in CNS when communication flags are enabled
  • Updates CNI to handle APIPA NICs with specialized configuration including skipped default routes

Reviewed Changes

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

File Description
cns/NetworkContainerContract.go Adds ApipaNIC constant and communication flags to PodIpInfo struct
cns/restserver/ipam.go Implements logic to create separate APIPA NIC entries when communication flags are set
cni/network/invoker_cns.go Adds APIPA NIC handling in CNI with specialized configuration function
network/network_windows.go Updates network creation logic to skip network creation for APIPA NICs

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions
Copy link

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

@github-actions github-actions bot added the stale Stale due to inactivity. label Sep 20, 2025
@github-actions
Copy link

Pull request closed due to inactivity.

@github-actions github-actions bot closed this Sep 27, 2025
@github-actions github-actions bot deleted the tm/apipa_refactor_swiftv2 branch September 27, 2025 00:01
@tamilmani1989 tamilmani1989 restored the tm/apipa_refactor_swiftv2 branch October 8, 2025 17:48
@tamilmani1989
Copy link
Member Author

reopen

@tamilmani1989 tamilmani1989 reopened this Oct 8, 2025
@github-actions github-actions bot removed the stale Stale due to inactivity. label Oct 9, 2025
… podipinfo to support apipa endpoint create request.

persist networkcontainer id in cns state to support delete apipa endpoint when called as endpoint name based on networkcontainerid.

Signed-off-by: Tamilmani <[email protected]>
@tamilmani1989 tamilmani1989 force-pushed the tm/apipa_refactor_swiftv2 branch from ddfbaa5 to f052db3 Compare October 24, 2025 20:22
@tamilmani1989 tamilmani1989 changed the title refactor: Update apipa nic as separate entry in podIPInfo feature: Adding apipa nic support for swiftv2 Oct 24, 2025
@tamilmani1989 tamilmani1989 changed the title feature: Adding apipa nic support for swiftv2 feature: Adding apipa nic support for swiftv2 windows Oct 24, 2025
@tamilmani1989 tamilmani1989 marked this pull request as ready for review October 24, 2025 20:36
@tamilmani1989 tamilmani1989 force-pushed the tm/apipa_refactor_swiftv2 branch from b5bf968 to 8c79a66 Compare October 31, 2025 21:01
@tamilmani1989 tamilmani1989 force-pushed the tm/apipa_refactor_swiftv2 branch from 8c79a66 to ac7f244 Compare October 31, 2025 22:21
@tamilmani1989 tamilmani1989 added cns Related to CNS. cni Related to CNI. labels Nov 1, 2025
Copy link
Contributor

@QxBytes QxBytes left a comment

Choose a reason for hiding this comment

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

can we add ut coverage for apipa in network_test and invoker_cns_test ?

@tamilmani1989 tamilmani1989 force-pushed the tm/apipa_refactor_swiftv2 branch from 26a56ab to 7c13da8 Compare November 7, 2025 00:49
Signed-off-by: Tamilmani <[email protected]>
@tamilmani1989 tamilmani1989 force-pushed the tm/apipa_refactor_swiftv2 branch from 7c13da8 to bad2798 Compare November 7, 2025 01:06
Copy link
Contributor

@QxBytes QxBytes left a comment

Choose a reason for hiding this comment

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

Also just to confirm cns/restserver/ipam.go it's okay if we have multiple podIPInfos that set resp[i].AllowHostToNCCommunication || resp[i].AllowNCToHostCommunication to true, right? We would just take one of them (and it shouldn't matter which one we take) to create the apipa pod ip info.

require.True(apipaInterfaceFound, "ApipaNIC interface should be found in the result")

// Verify the ApipaNIC interface info
// Lines around 2586-2590 should be:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the line numbers might change so this comment probably isn't necessary

@tamilmani1989
Copy link
Member Author

Also just to confirm cns/restserver/ipam.go it's okay if we have multiple podIPInfos that set resp[i].AllowHostToNCCommunication || resp[i].AllowNCToHostCommunication to true, right? We would just take one of them (and it shouldn't matter which one we take) to create the apipa pod ip info.

ya should be fine. validation will be added in dnc side to prevent this

@behzad-mir behzad-mir enabled auto-merge November 7, 2025 17:32
Copy link
Contributor

@santhoshmprabhu santhoshmprabhu left a comment

Choose a reason for hiding this comment

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

I don't have much context on Swiftv2 and the need for this change. The code changes look good. A couple of nits, and also, it seems we don't have tests for the new CNS deletion API. Could we please add those as well?

case http.MethodDelete:
service.DeleteEndpointStateHandler(w, r)
default:
logger.Errorf("[EndpointHandlerAPI] EndpointHandler API expect http Get or Patch method")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: update this log to include delete method

HNSNetworkID: networkID,
}

// mock DeleteEndpointState() to make sure endpoint and network is deleted from cache
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Update the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cni Related to CNI. cns Related to CNS.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants