Skip to content

Commit 5852af3

Browse files
committed
add default route on customer vnets
1 parent 3a6959c commit 5852af3

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

cni/network/invoker_cns.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,15 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
438438
resRoute := addResult.interfaceInfo[key].Routes
439439
if len(routes) > 0 {
440440
resRoute = append(resRoute, routes...)
441-
} else { // add default routes if none are provided
442-
resRoute = append(resRoute, network.RouteInfo{
443-
Dst: defaultRouteDstPrefix,
444-
Gw: ncgw,
445-
})
441+
} else { // add default routes if none are provided and skipDefaultRoute is false
442+
if !info.skipDefaultRoutes {
443+
resRoute = append(resRoute, network.RouteInfo{
444+
Dst: defaultRouteDstPrefix,
445+
Gw: ncgw,
446+
})
447+
}
446448
}
449+
447450
// if we have multiple infra ip result infos, we effectively append routes and ip configs to that same interface info each time
448451
// the host subnet prefix (in ipv4 or ipv6) will always refer to the same interface regardless of which ip result info we look at
449452
addResult.interfaceInfo[key] = network.InterfaceInfo{
@@ -484,6 +487,19 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
484487
return err
485488
}
486489

490+
defaultRouteDstPrefix := network.Ipv4DefaultRouteDstPrefix
491+
ncgw := net.ParseIP(info.ncGatewayIPAddress)
492+
493+
resRoute := addResult.interfaceInfo[key].Routes
494+
if len(routes) > 0 {
495+
resRoute = append(resRoute, routes...)
496+
} else { // add default routes for secondary interfaces
497+
resRoute = append(resRoute, network.RouteInfo{
498+
Dst: defaultRouteDstPrefix,
499+
Gw: ncgw,
500+
})
501+
}
502+
487503
addResult.interfaceInfo[key] = network.InterfaceInfo{
488504
IPConfigs: []*network.IPConfig{
489505
{
@@ -494,7 +510,7 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
494510
Gateway: net.ParseIP(info.ncGatewayIPAddress),
495511
},
496512
},
497-
Routes: routes,
513+
Routes: resRoute,
498514
NICType: info.nicType,
499515
MacAddress: macAddress,
500516
SkipDefaultRoutes: info.skipDefaultRoutes,

0 commit comments

Comments
 (0)