Skip to content

Commit e66c1aa

Browse files
committed
fix UTs
1 parent a06840a commit e66c1aa

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

cns/middlewares/k8sSwiftV2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package middlewares
33
import (
44
"context"
55
"fmt"
6+
"net/netip"
67

78
"github.com/Azure/azure-container-networking/cns"
89
"github.com/Azure/azure-container-networking/cns/configuration"
@@ -259,7 +260,7 @@ func (k *K8sSWIFTv2Middleware) addRoutes(cidrs []string, gatewayIP string) []cns
259260
return routes
260261
}
261262

262-
func (k *K8sSWIFTv2Middleware) SetInfraRoutes() ([]cns.Route, error) {
263+
func (k *K8sSWIFTv2Middleware) SetInfraRoutes(podIPInfo *cns.PodIpInfo) ([]cns.Route, error) {
263264
var routes []cns.Route
264265

265266
// Get and parse infraVNETCIDRs from env

cns/middlewares/k8sSwiftV2_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
2727
routes = append(routes, virtualGWRoute, route)
2828

2929
case cns.InfraNIC:
30-
infraRoutes, err := k.SetInfraRoutes()
30+
infraRoutes, err := k.SetInfraRoutes(podIPInfo)
3131
if err != nil {
3232
return errors.Wrap(err, "failed to set routes for infraNIC interface")
3333
}
34-
routes = append(routes, infraRoutes)
34+
routes = infraRoutes
3535
podIPInfo.SkipDefaultRoutes = true
3636

3737
case cns.NodeNetworkInterfaceBackendNIC: //nolint:exhaustive // ignore exhaustive types check

cns/middlewares/k8sSwiftV2_windows.go

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

33
import (
4+
"fmt"
5+
46
"github.com/Azure/azure-container-networking/cns"
5-
"github.com/Azure/azure-container-networking/cns/logger"
67
"github.com/Azure/azure-container-networking/cns/middlewares/utils"
78
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
89
"github.com/pkg/errors"
@@ -12,8 +13,6 @@ import (
1213
// default route is set for secondary interface NIC(i.e,delegatedNIC)
1314
func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
1415
if podIPInfo.NICType == cns.InfraNIC {
15-
logger.Printf("[SWIFTv2Middleware] skip setting default route on InfraNIC interface")
16-
1716
// as a workaround, set a default route with gw 0.0.0.0 to avoid HNS setting default route to infraNIC interface
1817
// TODO: remove this once HNS supports custom routes adding to the pod
1918
route := cns.Route{
@@ -23,11 +22,12 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
2322
podIPInfo.Routes = append(podIPInfo.Routes, route)
2423

2524
// add routes for infraNIC
26-
routes, err := k.SetInfraRoutes()
25+
routes, err := k.SetInfraRoutes(podIPInfo)
26+
fmt.Printf("routes are %v", routes)
2727
if err != nil {
2828
return errors.Wrap(err, "failed to set routes for infraNIC interface")
2929
}
30-
podIPInfo.Routes = append(podIPInfo.Routes, routes)
30+
podIPInfo.Routes = routes
3131
podIPInfo.SkipDefaultRoutes = true
3232
}
3333
return nil

cns/middlewares/k8sSwiftV2_windows_test.go

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

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

78
"github.com/Azure/azure-container-networking/cns"
9+
"github.com/Azure/azure-container-networking/cns/configuration"
810
"github.com/Azure/azure-container-networking/cns/middlewares/mock"
911
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
1012
"gotest.tools/v3/assert"
1113
)
1214

1315
func TestSetRoutesSuccess(t *testing.T) {
1416
middleware := K8sSWIFTv2Middleware{Cli: mock.NewClient()}
17+
t.Setenv(configuration.EnvPodCIDRs, "10.0.1.10/24,16A0:0010:AB00:001E::2/32")
18+
t.Setenv(configuration.EnvServiceCIDRs, "10.0.0.0/16,16A0:0010:AB00:0000::/32")
19+
t.Setenv(configuration.EnvInfraVNETCIDRs, "10.240.0.1/16,16A0:0020:AB00:0000::/32")
1520

1621
podIPInfo := []cns.PodIpInfo{
1722
{
@@ -32,6 +37,7 @@ func TestSetRoutesSuccess(t *testing.T) {
3237
}
3338
for i := range podIPInfo {
3439
ipInfo := &podIPInfo[i]
40+
fmt.Printf("ipInfo is %v", ipInfo)
3541
err := middleware.setRoutes(ipInfo)
3642
assert.Equal(t, err, nil)
3743
if ipInfo.NICType == cns.InfraNIC {

0 commit comments

Comments
 (0)