Skip to content

Commit b14386f

Browse files
committed
add an ut
1 parent c1755b0 commit b14386f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

cni/network/network.go

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

858858
setEndpointOptions(opt.cnsNetworkConfig, &endpointInfo, vethName)
859+
859860
logger.Info("Generated endpoint info from fields", zap.String("epInfo", endpointInfo.PrettyString()))
860861

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

cns/middlewares/k8sSwiftV2_windows.go

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

33
import (
4-
"fmt"
5-
64
"github.com/Azure/azure-container-networking/cns"
75
"github.com/Azure/azure-container-networking/cns/logger"
86
"github.com/Azure/azure-container-networking/cns/middlewares/utils"
@@ -17,7 +15,6 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
1715
logger.Printf("[SWIFTv2Middleware] skip setting default route on InfraNIC interface")
1816
podIPInfo.SkipDefaultRoutes = true
1917
}
20-
2118
return nil
2219
}
2320

@@ -44,14 +41,11 @@ func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(podIPInfo *cns.Pod
4441
GatewayIPAddress: interfaceInfo.GatewayIP,
4542
}
4643
// assign default route
47-
defaultRoute := cns.Route{
48-
IPAddress: fmt.Sprintf("%s/%d", interfaceInfo.GatewayIP, prefixLength),
49-
}
5044
route := cns.Route{
5145
IPAddress: "0.0.0.0/0",
5246
GatewayIPAddress: interfaceInfo.GatewayIP,
5347
}
54-
podIPInfo.Routes = append(podIPInfo.Routes, defaultRoute, route)
48+
podIPInfo.Routes = append(podIPInfo.Routes, route)
5549

5650
return nil
5751
}

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)