Skip to content

Commit 4eec043

Browse files
committed
fix comments
1 parent 9b1925a commit 4eec043

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

cns/middlewares/k8sSwiftV2.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ func (k *K8sSWIFTv2Middleware) getIPConfig(ctx context.Context, podInfo cns.PodI
237237
return nil, errors.Wrap(err, "failed to parse mtpnc subnetAddressSpace prefix")
238238
}
239239
podIPInfos = append(podIPInfos, podIPInfo)
240+
// for windows scenario, it is required to add default route with gatewayIP from CNS
241+
k.addDefaultRoute(&podIPInfo, interfaceInfo.GatewayIP)
240242
}
241243
}
242244
}

cns/middlewares/k8sSwiftV2_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@ func addRoutes(cidrs []string, gatewayIP string) []cns.Route {
101101
func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(_ *cns.PodIpInfo, _ v1alpha1.InterfaceInfo, _ string) error {
102102
return nil
103103
}
104+
105+
func (k *K8sSWIFTv2Middleware) addDefaultRoute(_ *cns.PodIpInfo, _ string) {}

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(podIPInfo *cns.Pod
4646
},
4747
GatewayIPAddress: interfaceInfo.GatewayIP,
4848
}
49-
// assign the default route with gateway IP
49+
50+
return nil
51+
}
52+
53+
// add default route with gateway IP to podIPInfo
54+
func (k *K8sSWIFTv2Middleware) addDefaultRoute(podIPInfo *cns.PodIpInfo, gwIP string) {
5055
route := cns.Route{
5156
IPAddress: "0.0.0.0/0",
52-
GatewayIPAddress: interfaceInfo.GatewayIP,
57+
GatewayIPAddress: gwIP,
5358
}
5459
podIPInfo.Routes = append(podIPInfo.Routes, route)
55-
56-
return nil
5760
}

cns/middlewares/k8sSwiftV2_windows_test.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,44 @@ func TestAssignSubnetPrefixSuccess(t *testing.T) {
6060
SubnetAddressSpace: "20.240.1.0/16",
6161
}
6262

63-
routes := []cns.Route{
64-
{
65-
IPAddress: "0.0.0.0/0",
66-
GatewayIPAddress: gatewayIP,
67-
},
68-
}
69-
7063
ipInfo := podIPInfo
7164
err := middleware.assignSubnetPrefixLengthFields(&ipInfo, intInfo, ipInfo.PodIPConfig.IPAddress)
7265
assert.Equal(t, err, nil)
7366
// assert that the function for windows modifies all the expected fields with prefix-length
7467
assert.Equal(t, ipInfo.PodIPConfig.PrefixLength, uint8(16))
7568
assert.Equal(t, ipInfo.HostPrimaryIPInfo.Gateway, intInfo.GatewayIP)
7669
assert.Equal(t, ipInfo.HostPrimaryIPInfo.Subnet, intInfo.SubnetAddressSpace)
70+
}
71+
72+
func TestAddDefaultRoute(t *testing.T) {
73+
middleware := K8sSWIFTv2Middleware{Cli: mock.NewClient()}
74+
75+
podIPInfo := cns.PodIpInfo{
76+
PodIPConfig: cns.IPSubnet{
77+
IPAddress: "20.240.1.242",
78+
PrefixLength: 32,
79+
},
80+
NICType: cns.DelegatedVMNIC,
81+
MacAddress: "12:34:56:78:9a:bc",
82+
}
83+
84+
gatewayIP := "20.240.1.1"
85+
intInfo := v1alpha1.InterfaceInfo{
86+
GatewayIP: gatewayIP,
87+
SubnetAddressSpace: "20.240.1.0/16",
88+
}
89+
90+
ipInfo := podIPInfo
91+
middleware.addDefaultRoute(&ipInfo, intInfo.GatewayIP)
92+
93+
expectedRoutes := []cns.Route{
94+
{
95+
IPAddress: "0.0.0.0/0",
96+
GatewayIPAddress: gatewayIP,
97+
},
98+
}
7799

78-
// compare two slices of routes
79-
if !reflect.DeepEqual(ipInfo.Routes, routes) {
80-
t.Errorf("got '%+v', expected '%+v'", ipInfo.Routes, routes)
100+
if !reflect.DeepEqual(ipInfo.Routes, expectedRoutes) {
101+
t.Errorf("got '%+v', expected '%+v'", ipInfo.Routes, expectedRoutes)
81102
}
82103
}

0 commit comments

Comments
 (0)