@@ -116,6 +116,7 @@ type NetworkManager interface {
116116 UpdateEndpoint (networkID string , existingEpInfo * EndpointInfo , targetEpInfo * EndpointInfo ) error
117117 GetNumberOfEndpoints (ifName string , networkID string ) int
118118 GetEndpointID (containerID , ifName string ) string
119+ GetEndpointIDByNicType (containerID , ifName string , nicType cns.NICType ) string
119120 IsStatelessCNIMode () bool
120121 SaveState (eps []* endpoint ) error
121122 DeleteState (epInfos []* EndpointInfo ) error
@@ -514,7 +515,7 @@ func (nm *networkManager) DeleteEndpointState(networkID string, epInfo *Endpoint
514515 nw := & network {
515516 Id : networkID , // currently unused in stateless cni
516517 HnsId : epInfo .HNSNetworkID ,
517- Mode : opModeTransparentVlan ,
518+ Mode : opModeTransparent ,
518519 SnatBridgeIP : "" ,
519520 NetNs : dummyGUID , // to trigger hns v2, windows
520521 extIf : & externalInterface {
@@ -529,6 +530,7 @@ func (nm *networkManager) DeleteEndpointState(networkID string, epInfo *Endpoint
529530 HNSNetworkID : epInfo .HNSNetworkID , // unused (we use nw.HnsId for deleting the network)
530531 HostIfName : epInfo .HostIfName ,
531532 LocalIP : "" ,
533+ IPAddresses : epInfo .IPAddresses ,
532534 VlanID : 0 ,
533535 AllowInboundFromHostToNC : false , // stateless currently does not support apipa
534536 AllowInboundFromNCToHost : false ,
@@ -537,11 +539,12 @@ func (nm *networkManager) DeleteEndpointState(networkID string, epInfo *Endpoint
537539 NetworkContainerID : epInfo .NetworkContainerID , // we don't use this as long as AllowInboundFromHostToNC and AllowInboundFromNCToHost are false
538540 NetNs : dummyGUID , // to trigger hnsv2, windows
539541 NICType : epInfo .NICType ,
542+ NetworkNameSpace : epInfo .NetNsPath ,
540543 IfName : epInfo .IfName , // TODO: For stateless cni linux populate IfName here to use in deletion in secondary endpoint client
541544 }
542545 logger .Info ("Deleting endpoint with" , zap .String ("Endpoint Info: " , epInfo .PrettyString ()), zap .String ("HNISID : " , ep .HnsId ))
543546
544- err := nw .deleteEndpointImpl (netlink . NewNetlink (), platform . NewExecClient ( logger ) , nil , nil , nil , nil , nil , ep )
547+ err := nw .deleteEndpointImpl (nm . netlink , nm . plClient , nil , nm . netio , nm . nsClient , nm . iptablesClient , nm . dhcpClient , ep )
545548 if err != nil {
546549 return err
547550 }
@@ -745,6 +748,16 @@ func (nm *networkManager) GetEndpointID(containerID, ifName string) string {
745748 return containerID + "-" + ifName
746749}
747750
751+ // GetEndpointIDByNicType returns a unique endpoint ID based on the CNI mode and NIC type.
752+ func (nm * networkManager ) GetEndpointIDByNicType (containerID , ifName string , nicType cns.NICType ) string {
753+ // For stateless CNI, secondary NICs use containerID-ifName as endpointID.
754+ if nm .IsStatelessCNIMode () && nicType != cns .InfraNIC {
755+ return containerID + "-" + ifName
756+ }
757+ // For InfraNIC, use GetEndpointID() logic.
758+ return nm .GetEndpointID (containerID , ifName )
759+ }
760+
748761// saves the map of network ids to endpoints to the state file
749762func (nm * networkManager ) SaveState (eps []* endpoint ) error {
750763 nm .Lock ()
@@ -809,6 +822,7 @@ func cnsEndpointInfotoCNIEpInfos(endpointInfo restserver.EndpointInfo, endpointI
809822 epInfo .NICType = ipInfo .NICType
810823 epInfo .HNSNetworkID = ipInfo .HnsNetworkID
811824 epInfo .MacAddress = net .HardwareAddr (ipInfo .MacAddress )
825+ epInfo .NetNsPath = ipInfo .NetworkNameSpace
812826 ret = append (ret , epInfo )
813827 }
814828 return ret
@@ -837,11 +851,12 @@ func generateCNSIPInfoMap(eps []*endpoint) map[string]*restserver.IPInfo {
837851
838852 for _ , ep := range eps {
839853 ifNametoIPInfoMap [ep .IfName ] = & restserver.IPInfo { // in windows, the nicname is args ifname, in linux, it's ethX
840- NICType : ep .NICType ,
841- HnsEndpointID : ep .HnsId ,
842- HnsNetworkID : ep .HNSNetworkID ,
843- HostVethName : ep .HostIfName ,
844- MacAddress : ep .MacAddress .String (),
854+ NICType : ep .NICType ,
855+ HnsEndpointID : ep .HnsId ,
856+ HnsNetworkID : ep .HNSNetworkID ,
857+ HostVethName : ep .HostIfName ,
858+ MacAddress : ep .MacAddress .String (),
859+ NetworkNameSpace : ep .NetworkNameSpace ,
845860 }
846861 }
847862
0 commit comments