Skip to content

Commit b3546e5

Browse files
committed
CNS should send default routes to CNI windows
1 parent 80b3a50 commit b3546e5

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

cni/network/invoker_cns.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -487,16 +487,7 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
487487
if err != nil {
488488
return err
489489
}
490-
491-
resRoute := addResult.interfaceInfo[key].Routes
492-
if len(routes) > 0 {
493-
resRoute = append(resRoute, routes...)
494-
} else { // add default route to customer vnet on swiftv2 windows
495-
resRoute = append(resRoute, network.RouteInfo{
496-
Dst: network.Ipv4DefaultRouteDstPrefix,
497-
Gw: net.ParseIP(info.ncGatewayIPAddress),
498-
})
499-
}
490+
logger.Info("routes are now", zap.Any("routes are now", routes))
500491

501492
addResult.interfaceInfo[key] = network.InterfaceInfo{
502493
IPConfigs: []*network.IPConfig{
@@ -508,7 +499,7 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
508499
Gateway: net.ParseIP(info.ncGatewayIPAddress),
509500
},
510501
},
511-
Routes: resRoute,
502+
Routes: routes,
512503
NICType: info.nicType,
513504
MacAddress: macAddress,
514505
SkipDefaultRoutes: info.skipDefaultRoutes,

cni/network/network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ func (plugin *NetPlugin) createEpInfo(opt *createEpInfoOpt) (*network.EndpointIn
856856
}
857857

858858
setEndpointOptions(opt.cnsNetworkConfig, &endpointInfo, vethName)
859-
859+
logger.Info("endpointInfo routes are", zap.Any("endpointInfo routes", endpointInfo.Routes))
860860
logger.Info("Generated endpoint info from fields", zap.String("epInfo", endpointInfo.PrettyString()))
861861

862862
// now our ep info should have the full combined information from both the network and endpoint structs

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package middlewares
22

33
import (
4+
"fmt"
5+
46
"github.com/Azure/azure-container-networking/cns"
57
"github.com/Azure/azure-container-networking/cns/logger"
68
"github.com/Azure/azure-container-networking/cns/middlewares/utils"
@@ -15,6 +17,7 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
1517
logger.Printf("[SWIFTv2Middleware] skip setting default route on InfraNIC interface")
1618
podIPInfo.SkipDefaultRoutes = true
1719
}
20+
1821
return nil
1922
}
2023

@@ -40,5 +43,15 @@ func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(podIPInfo *cns.Pod
4043
},
4144
GatewayIPAddress: interfaceInfo.GatewayIP,
4245
}
46+
// assign routes
47+
virtualGWRoute := cns.Route{
48+
IPAddress: fmt.Sprintf("%s/%d", interfaceInfo.GatewayIP, prefixLength),
49+
}
50+
route := cns.Route{
51+
IPAddress: "0.0.0.0/0",
52+
GatewayIPAddress: virtualGW,
53+
}
54+
podIPInfo.Routes = append(podIPInfo.Routes, virtualGWRoute, route)
55+
4356
return nil
4457
}

network/transparent_endpointclient_linux.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (client *TransparentEndpointClient) ConfigureContainerInterfacesAndRoutes(e
233233

234234
// add route for virtualgwip
235235
// ip route add 169.254.1.1/32 dev eth0
236-
_, virtualGwNet, _ := net.ParseCIDR(virtualGwIPString)
236+
virtualGwIP, virtualGwNet, _ := net.ParseCIDR(virtualGwIPString)
237237
routeInfo := RouteInfo{
238238
Dst: *virtualGwNet,
239239
Scope: netlink.RT_SCOPE_LINK,
@@ -242,7 +242,18 @@ func (client *TransparentEndpointClient) ConfigureContainerInterfacesAndRoutes(e
242242
return newErrorTransparentEndpointClient(err)
243243
}
244244

245-
if err := addRoutes(client.netlink, client.netioshim, client.containerVethName, epInfo.Routes); err != nil {
245+
if !epInfo.SkipDefaultRoutes {
246+
// ip route add default via 169.254.1.1 dev eth0
247+
_, defaultIPNet, _ := net.ParseCIDR(defaultGwCidr)
248+
dstIP := net.IPNet{IP: net.ParseIP(defaultGw), Mask: defaultIPNet.Mask}
249+
routeInfo = RouteInfo{
250+
Dst: dstIP,
251+
Gw: virtualGwIP,
252+
}
253+
if err := addRoutes(client.netlink, client.netioshim, client.containerVethName, []RouteInfo{routeInfo}); err != nil {
254+
return err
255+
}
256+
} else if err := addRoutes(client.netlink, client.netioshim, client.containerVethName, epInfo.Routes); err != nil {
246257
return newErrorTransparentEndpointClient(err)
247258
}
248259

0 commit comments

Comments
 (0)