@@ -205,8 +205,7 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
205205 }
206206 }
207207
208- overlayMode := (invoker .ipamMode == util .V4Overlay ) || (invoker .ipamMode == util .DualStackOverlay ) || (invoker .ipamMode == util .Overlay )
209- if err := configureDefaultAddResult (& info , & addConfig , & addResult , overlayMode , key ); err != nil {
208+ if err := configureDefaultAddResult (& info , & addConfig , & addResult , key ); err != nil {
210209 return IPAMAddResult {}, err
211210 }
212211 default :
@@ -379,32 +378,48 @@ func getRoutes(cnsRoutes []cns.Route, skipDefaultRoutes bool) ([]network.RouteIn
379378 return routes , nil
380379}
381380
382- func configureDefaultAddResult (info * IPResultInfo , addConfig * IPAMAddConfig , addResult * IPAMAddResult , overlayMode bool , key string ) error {
381+ func configureDefaultAddResult (info * IPResultInfo , addConfig * IPAMAddConfig , addResult * IPAMAddResult , key string ) error {
382+ ipamMode := util .IpamMode (addConfig .nwCfg .IPAM .Mode )
383383 // set the NC Primary IP in options
384384 // SNATIPKey is not set for ipv6
385- if net .ParseIP (info .ncPrimaryIP ).To4 () != nil {
385+ if ipamMode != util . Nodesubnet && net .ParseIP (info .ncPrimaryIP ).To4 () != nil {
386386 addConfig .options [network .SNATIPKey ] = info .ncPrimaryIP
387387 }
388388
389+ if ipamMode == util .Nodesubnet {
390+ info .ncGatewayIPAddress = info .hostGateway
391+ info .ncPrimaryIP = info .hostPrimaryIP
392+ _ , ncIPNet , err := net .ParseCIDR (info .hostSubnet )
393+ if err != nil {
394+ return errors .Wrap (err , "Unable to parse hostSubnet from response: " + info .hostSubnet + " with err %w" )
395+ }
396+
397+ maskLen , _ := ncIPNet .Mask .Size ()
398+ info .ncSubnetPrefix = uint8 (maskLen )
399+ }
400+
389401 ip , ncIPNet , err := net .ParseCIDR (info .podIPAddress + "/" + fmt .Sprint (info .ncSubnetPrefix ))
402+
390403 if ip == nil || err != nil {
391404 return errors .Wrap (err , "Unable to parse IP from response: " + info .podIPAddress + " with err %w" )
392405 }
393406
394- ncgw := net .ParseIP (info .ncGatewayIPAddress )
395- if ncgw == nil {
396- // TODO: Remove v4overlay and dualstackoverlay options, after 'overlay' rolls out in AKS-RP
397- if ! overlayMode {
407+ podGateway := net .ParseIP (info .ncGatewayIPAddress )
408+ // TODO: Remove v4overlay and dualstackoverlay options, after 'overlay' rolls out in AKS-RP
409+ isPodSubnetMode := (ipamMode != util .V4Overlay ) && (ipamMode != util .DualStackOverlay ) && (ipamMode != util .Overlay ) && (ipamMode != util .Nodesubnet )
410+
411+ if podGateway == nil {
412+ if isPodSubnetMode {
398413 return errors .Wrap (errInvalidArgs , "%w: Gateway address " + info .ncGatewayIPAddress + " from response is invalid" )
399414 }
400415
401416 if net .ParseIP (info .podIPAddress ).To4 () != nil { //nolint:gocritic
402- ncgw , err = getOverlayGateway (ncIPNet )
417+ podGateway , err = getOverlayGateway (ncIPNet )
403418 if err != nil {
404419 return err
405420 }
406421 } else if net .ParseIP (info .podIPAddress ).To16 () != nil {
407- ncgw = net .ParseIP (overlayGatewayV6IP )
422+ podGateway = net .ParseIP (overlayGatewayV6IP )
408423 } else {
409424 return errors .Wrap (err , "No podIPAddress is found: %w" )
410425 }
@@ -430,7 +445,7 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
430445 IP : ip ,
431446 Mask : ncIPNet .Mask ,
432447 },
433- Gateway : ncgw ,
448+ Gateway : podGateway ,
434449 })
435450
436451 routes , getRoutesErr := getRoutes (info .routes , info .skipDefaultRoutes )
@@ -444,7 +459,7 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
444459 } else { // add default routes if none are provided
445460 resRoute = append (resRoute , network.RouteInfo {
446461 Dst : defaultRouteDstPrefix ,
447- Gw : ncgw ,
462+ Gw : podGateway ,
448463 })
449464 }
450465
@@ -461,9 +476,8 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
461476 }
462477
463478 // set subnet prefix for host vm
464- // setHostOptions will execute if IPAM mode is not v4 overlay and not dualStackOverlay mode
465- // TODO: Remove v4overlay and dualstackoverlay options, after 'overlay' rolls out in AKS-RP
466- if ! overlayMode {
479+ // setHostOptions will execute if IPAM mode is podsubnet
480+ if isPodSubnetMode {
467481 if err := setHostOptions (ncIPNet , addConfig .options , info ); err != nil {
468482 return err
469483 }
0 commit comments