@@ -141,8 +141,9 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
141141 }
142142 }
143143
144- addResult := IPAMAddResult {interfaceInfo : make ( map [ string ]network. InterfaceInfo ) }
144+ addResult := IPAMAddResult {}
145145 numInterfacesWithDefaultRoutes := 0
146+
146147 for i := 0 ; i < len (response .PodIPInfo ); i ++ {
147148 info := IPResultInfo {
148149 podIPAddress : response .PodIPInfo [i ].PodIPConfig .IPAddress ,
@@ -163,42 +164,29 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
163164 zap .Any ("podInfo" , podInfo ))
164165
165166 //nolint:exhaustive // ignore exhaustive types check
166- // Do we want to leverage this lint skip in other places of our code?
167- key := invoker .getInterfaceInfoKey (info .nicType , info .macAddress )
168167 switch info .nicType {
169168 case cns .DelegatedVMNIC :
170169 // only handling single v4 PodIPInfo for Frontend NICs at the moment, will have to update once v6 gets added
171170 if ! info .skipDefaultRoutes {
172171 numInterfacesWithDefaultRoutes ++
173172 }
174173
175- // Add secondary interface info from podIPInfo to ipamAddResult
176- info .hostSubnet = response .PodIPInfo [i ].HostPrimaryIPInfo .Subnet
177- info .hostPrimaryIP = response .PodIPInfo [i ].HostPrimaryIPInfo .PrimaryIP
178- info .hostGateway = response .PodIPInfo [i ].HostPrimaryIPInfo .Gateway
179-
180- if err := configureSecondaryAddResult (& info , & addResult , & response .PodIPInfo [i ].PodIPConfig , key ); err != nil {
174+ if err := configureSecondaryAddResult (& info , & addResult , & response .PodIPInfo [i ].PodIPConfig ); err != nil {
181175 return IPAMAddResult {}, err
182176 }
183- case cns .InfraNIC , "" :
184- // if we change from legacy cns, the nicType will be empty, so we assume it is infra nic
185- info .nicType = cns .InfraNIC
186-
177+ default :
187178 // only count dualstack interface once
188- _ , exist := addResult .interfaceInfo [key ]
189- if ! exist {
190- addResult .interfaceInfo [key ] = network.InterfaceInfo {}
179+ if addResult .defaultInterfaceInfo .IPConfigs == nil {
180+ addResult .defaultInterfaceInfo .IPConfigs = make ([]* network.IPConfig , 0 )
191181 if ! info .skipDefaultRoutes {
192182 numInterfacesWithDefaultRoutes ++
193183 }
194184 }
195185
196186 overlayMode := (invoker .ipamMode == util .V4Overlay ) || (invoker .ipamMode == util .DualStackOverlay ) || (invoker .ipamMode == util .Overlay )
197- if err := configureDefaultAddResult (& info , & addConfig , & addResult , overlayMode , key ); err != nil {
187+ if err := configureDefaultAddResult (& info , & addConfig , & addResult , overlayMode ); err != nil {
198188 return IPAMAddResult {}, err
199189 }
200- default :
201- logger .Warn ("Unknown NIC type received from cns pod ip info" , zap .String ("nicType" , string (info .nicType )))
202190 }
203191 }
204192
@@ -365,15 +353,15 @@ func getRoutes(cnsRoutes []cns.Route, skipDefaultRoutes bool) ([]network.RouteIn
365353 return routes , nil
366354}
367355
368- func configureDefaultAddResult (info * IPResultInfo , addConfig * IPAMAddConfig , addResult * IPAMAddResult , overlayMode bool , key string ) error {
356+ func configureDefaultAddResult (info * IPResultInfo , addConfig * IPAMAddConfig , addResult * IPAMAddResult , overlayMode bool ) error {
369357 // set the NC Primary IP in options
370358 // SNATIPKey is not set for ipv6
371359 if net .ParseIP (info .ncPrimaryIP ).To4 () != nil {
372360 addConfig .options [network .SNATIPKey ] = info .ncPrimaryIP
373361 }
374362
375363 ip , ncIPNet , err := net .ParseCIDR (info .podIPAddress + "/" + fmt .Sprint (info .ncSubnetPrefix ))
376- if ip == nil || err != nil {
364+ if ip == nil {
377365 return errors .Wrap (err , "Unable to parse IP from response: " + info .podIPAddress + " with err %w" )
378366 }
379367
@@ -396,21 +384,15 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
396384 }
397385 }
398386
399- // get the name of the primary IP address
400- _ , hostIPNet , err := net .ParseCIDR (info .hostSubnet )
401- if err != nil {
402- return errors .Wrap (err , "unable to parse hostSubnet" )
403- }
404-
405387 if ip := net .ParseIP (info .podIPAddress ); ip != nil {
388+ defaultInterfaceInfo := & addResult .defaultInterfaceInfo
406389 defaultRouteDstPrefix := network .Ipv4DefaultRouteDstPrefix
407390 if ip .To4 () == nil {
408391 defaultRouteDstPrefix = network .Ipv6DefaultRouteDstPrefix
409392 addResult .ipv6Enabled = true
410393 }
411394
412- ipConfigs := addResult .interfaceInfo [key ].IPConfigs
413- ipConfigs = append (ipConfigs ,
395+ defaultInterfaceInfo .IPConfigs = append (defaultInterfaceInfo .IPConfigs ,
414396 & network.IPConfig {
415397 Address : net.IPNet {
416398 IP : ip ,
@@ -424,26 +406,27 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
424406 return getRoutesErr
425407 }
426408
427- resRoute := addResult .interfaceInfo [key ].Routes
428409 if len (routes ) > 0 {
429- resRoute = append (resRoute , routes ... )
410+ defaultInterfaceInfo . Routes = append (defaultInterfaceInfo . Routes , routes ... )
430411 } else { // add default routes if none are provided
431- resRoute = append (resRoute , network.RouteInfo {
412+ defaultInterfaceInfo . Routes = append (defaultInterfaceInfo . Routes , network.RouteInfo {
432413 Dst : defaultRouteDstPrefix ,
433414 Gw : ncgw ,
434415 })
435416 }
436- // if we have multiple infra ip result infos, we effectively append routes and ip configs to that same interface info each time
437- // the host subnet prefix (in ipv4 or ipv6) will always refer to the same interface regardless of which ip result info we look at
438- addResult .interfaceInfo [key ] = network.InterfaceInfo {
439- NICType : cns .InfraNIC ,
440- SkipDefaultRoutes : info .skipDefaultRoutes ,
441- IPConfigs : ipConfigs ,
442- Routes : resRoute ,
443- HostSubnetPrefix : * hostIPNet ,
444- }
417+
418+ addResult .defaultInterfaceInfo .SkipDefaultRoutes = info .skipDefaultRoutes
419+ }
420+
421+ // get the name of the primary IP address
422+ _ , hostIPNet , err := net .ParseCIDR (info .hostSubnet )
423+ if err != nil {
424+ return fmt .Errorf ("unable to parse hostSubnet: %w" , err )
445425 }
446426
427+ addResult .hostSubnetPrefix = * hostIPNet
428+ addResult .defaultInterfaceInfo .NICType = cns .InfraNIC
429+
447430 // set subnet prefix for host vm
448431 // setHostOptions will execute if IPAM mode is not v4 overlay and not dualStackOverlay mode
449432 // TODO: Remove v4overlay and dualstackoverlay options, after 'overlay' rolls out in AKS-RP
@@ -456,7 +439,7 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
456439 return nil
457440}
458441
459- func configureSecondaryAddResult (info * IPResultInfo , addResult * IPAMAddResult , podIPConfig * cns.IPSubnet , key string ) error {
442+ func configureSecondaryAddResult (info * IPResultInfo , addResult * IPAMAddResult , podIPConfig * cns.IPSubnet ) error {
460443 ip , ipnet , err := podIPConfig .GetIPNet ()
461444 if ip == nil {
462445 return errors .Wrap (err , "Unable to parse IP from response: " + info .podIPAddress + " with err %w" )
@@ -472,14 +455,13 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
472455 return err
473456 }
474457
475- addResult . interfaceInfo [ key ] = network.InterfaceInfo {
458+ result : = network.InterfaceInfo {
476459 IPConfigs : []* network.IPConfig {
477460 {
478461 Address : net.IPNet {
479462 IP : ip ,
480463 Mask : ipnet .Mask ,
481464 },
482- Gateway : net .ParseIP (info .ncGatewayIPAddress ),
483465 },
484466 },
485467 Routes : routes ,
@@ -488,12 +470,7 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
488470 SkipDefaultRoutes : info .skipDefaultRoutes ,
489471 }
490472
491- return nil
492- }
473+ addResult .secondaryInterfacesInfo = append (addResult .secondaryInterfacesInfo , result )
493474
494- func (invoker * CNSIPAMInvoker ) getInterfaceInfoKey (nicType cns.NICType , macAddress string ) string {
495- if nicType == cns .DelegatedVMNIC {
496- return macAddress
497- }
498- return string (nicType )
475+ return nil
499476}
0 commit comments