Skip to content

Commit 9a4b2b9

Browse files
committed
add default route on delegatedNIC interface
1 parent b7190c8 commit 9a4b2b9

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ import (
1212
// default route is set for secondary interface NIC(i.e,delegatedNIC)
1313
func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
1414
if podIPInfo.NICType == cns.InfraNIC {
15-
logger.Printf("[SWIFTv2Middleware] skip setting default route on InfraNIC interface")
15+
// as a workaround, set a default route with gw 0.0.0.0 to avoid HNS setting default route to infraNIC interface
16+
// TODO: Remove this once HNS supports custom routes adding to the pod
17+
route := cns.Route{
18+
IPAddress: "0.0.0.0/0",
19+
GatewayIPAddress: "0.0.0.0",
20+
}
21+
podIPInfo.Routes = append(podIPInfo.Routes, route)
22+
1623
podIPInfo.SkipDefaultRoutes = true
1724
}
1825
return nil
@@ -40,5 +47,12 @@ func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(podIPInfo *cns.Pod
4047
},
4148
GatewayIPAddress: interfaceInfo.GatewayIP,
4249
}
50+
// assign the default route with gateway IP
51+
route := cns.Route {
52+
IPAddress: "0.0.0.0/0",
53+
GatewayIPAddress: interfaceInfo.GatewayIP,
54+
}
55+
podIPInfo.Routes = append(podIPInfo.Routes, route)
56+
4357
return nil
4458
}

cns/middlewares/k8sSwiftV2_windows_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package middlewares
22

33
import (
4+
"reflect"
45
"testing"
56

67
"github.com/Azure/azure-container-networking/cns"
@@ -53,16 +54,29 @@ func TestAssignSubnetPrefixSuccess(t *testing.T) {
5354
MacAddress: "12:34:56:78:9a:bc",
5455
}
5556

57+
gatewayIP := "20.240.1.1"
5658
intInfo := v1alpha1.InterfaceInfo{
57-
GatewayIP: "20.240.1.1",
59+
GatewayIP: gatewayIP,
5860
SubnetAddressSpace: "20.240.1.0/16",
5961
}
6062

63+
routes := []cns.Route{
64+
{
65+
IPAddress: "0.0.0.0/0",
66+
GatewayIPAddress: gatewayIP,
67+
},
68+
}
69+
6170
ipInfo := podIPInfo
6271
err := middleware.assignSubnetPrefixLengthFields(&ipInfo, intInfo, ipInfo.PodIPConfig.IPAddress)
6372
assert.Equal(t, err, nil)
6473
// assert that the function for windows modifies all the expected fields with prefix-length
6574
assert.Equal(t, ipInfo.PodIPConfig.PrefixLength, uint8(16))
6675
assert.Equal(t, ipInfo.HostPrimaryIPInfo.Gateway, intInfo.GatewayIP)
6776
assert.Equal(t, ipInfo.HostPrimaryIPInfo.Subnet, intInfo.SubnetAddressSpace)
77+
78+
// compare two slices of routes
79+
if !reflect.DeepEqual(ipInfo.Routes, routes) {
80+
t.Errorf("got '%+v', expected '%+v'", ipInfo.Routes, routes)
81+
}
6882
}

0 commit comments

Comments
 (0)