Skip to content

Commit cd629a4

Browse files
committed
fix comments
1 parent ed4c09c commit cd629a4

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

cns/middlewares/k8sSwiftV2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ func (k *K8sSWIFTv2Middleware) AddRoutes(cidrs []string, gatewayIP string) []cns
238238
return routes
239239
}
240240

241-
// CNS gets node and service CIDRs from configuration env and parse them to get the v4 and v6 IPs
242-
func (k *K8sSWIFTv2Middleware) GetCidrs() (v4IPs, v6IPs []string, err error) {
241+
// Both Linux and Windows CNS gets infravnet and service CIDRs from configuration env
242+
func (k *K8sSWIFTv2Middleware) GetCidrs() ([]string, []string, error) {
243243
v4Cidrs := []string{}
244244
v6Cidrs := []string{}
245245

cns/middlewares/k8sSwiftV2_linux.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
3232
routes = append(routes, virtualGWRoute, route)
3333

3434
case cns.InfraNIC:
35-
// get service and infravnet routes
35+
// Linux CNS middleware sets the infra routes(infravnet/pod/service cidrs) to infraNIC interface for the podIPInfo used in SWIFT V2 Linux scenario
3636
infraRoutes, err := k.getInfraRoutes(podIPInfo)
3737
if err != nil {
3838
return errors.Wrap(err, "failed to get infra routes for infraNIC interface")
@@ -50,9 +50,10 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
5050
return nil
5151
}
5252

53-
// CNS gets pod CIDRs from configuration env and parse them to get the v4 and v6 IPs
54-
// Containerd reassigns the IP to the adapter and kernel configures the pod cidr route by default, so windows swiftv2 does not require pod cidr
55-
func (k *K8sSWIFTv2Middleware) GetPodCidrs() (v4IPs, v6IPs []string, err error) {
53+
// Linux CNS gets pod CIDRs from configuration env
54+
// Containerd reassigns the IP to the adapter and kernel configures the pod cidr route by default on Windows VM
55+
// Hence the windows swiftv2 scenario does not require pod cidr
56+
func (k *K8sSWIFTv2Middleware) GetPodCidrs() ([]string, []string, error) {
5657
v4PodCidrs := []string{}
5758
v6PodCidrs := []string{}
5859

@@ -72,6 +73,8 @@ func (k *K8sSWIFTv2Middleware) GetPodCidrs() (v4IPs, v6IPs []string, err error)
7273
return v4PodCidrs, v6PodCidrs, nil
7374
}
7475

76+
// getInfraRoutes() returns the infra routes including infravnet/pod/service cidrs for the podIPInfo used in SWIFT V2 Linux scenario
77+
// Linux uses 169.254.1.1 as the default ipv4 gateway and fe80::1234:5678:9abc as the default ipv6 gateway
7578
func (k *K8sSWIFTv2Middleware) getInfraRoutes(podIPInfo *cns.PodIpInfo) ([]cns.Route, error) {
7679
var routes []cns.Route
7780

@@ -93,7 +96,6 @@ func (k *K8sSWIFTv2Middleware) getInfraRoutes(podIPInfo *cns.PodIpInfo) ([]cns.R
9396
v4IPs = append(v4IPs, v4PodIPs...)
9497
v6IPs = append(v6IPs, v6PodIPs...)
9598

96-
// Linux uses 169.254.1.1 as the default ipv4 gateway and fe80::1234:5678:9abc as the default ipv6 gateway
9799
if ip.Is4() {
98100
routes = append(routes, k.AddRoutes(v4IPs, overlayGatewayv4)...)
99101
} else {

cns/middlewares/k8sSwiftV2_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package middlewares
33
import (
44
"context"
55
"fmt"
6-
"reflect"
76
"testing"
87

98
"github.com/Azure/azure-container-networking/cns"
@@ -12,6 +11,7 @@ import (
1211
"github.com/Azure/azure-container-networking/cns/middlewares/mock"
1312
"github.com/Azure/azure-container-networking/cns/types"
1413
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
14+
"github.com/google/go-cmp/cmp"
1515
"gotest.tools/v3/assert"
1616
)
1717

@@ -346,7 +346,7 @@ func TestSetRoutesSuccess(t *testing.T) {
346346
}
347347

348348
for i := range podIPInfo {
349-
reflect.DeepEqual(podIPInfo[i].Routes, desiredPodIPInfo[i].Routes)
349+
cmp.Equal(podIPInfo[i].Routes, desiredPodIPInfo[i].Routes)
350350
}
351351
}
352352

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
3636
}
3737
podIPInfo.Routes = append(podIPInfo.Routes, route)
3838

39-
// set routes(infravnet and service cidrs) for infraNIC interface
39+
// // Linux CNS middleware sets the infra routes(infravnet and service cidrs) to infraNIC interface for the podIPInfo used in SWIFT V2 Windows scenario
4040
infraRoutes, err := k.getInfraRoutes(podIPInfo)
4141
if err != nil {
4242
return errors.Wrap(err, "failed to set routes for infraNIC interface")
@@ -220,6 +220,9 @@ func GetDefaultDenyBool(mtpnc v1alpha1.MultitenantPodNetworkConfig) bool {
220220
return mtpnc.Status.DefaultDenyACL
221221
}
222222

223+
// getInfraRoutes() returns the infra routes including infravnet/ and service cidrs for the podIPInfo used in SWIFT V2 Windows scenario
224+
// Windows uses default route 0.0.0.0 as the gateway IP for containerd to configure;
225+
// For example, containerd would set route like: ip route 10.0.0.0/16 via 0.0.0.0 dev eth0
223226
func (k *K8sSWIFTv2Middleware) getInfraRoutes(podIPInfo *cns.PodIpInfo) ([]cns.Route, error) {
224227
var routes []cns.Route
225228

@@ -228,16 +231,13 @@ func (k *K8sSWIFTv2Middleware) getInfraRoutes(podIPInfo *cns.PodIpInfo) ([]cns.R
228231
return nil, errors.Wrapf(err, "failed to parse podIPConfig IP address %s", podIPInfo.PodIPConfig.IPAddress)
229232
}
230233

231-
// swiftv2 windows does not support ipv6
234+
// TODO: add ipv6 when supported
232235
v4IPs, _, err := k.GetCidrs()
233236
if err != nil {
234237
return nil, errors.Wrap(err, "failed to get CIDRs")
235238
}
236239

237240
if ip.Is4() {
238-
// add routes to podIPInfo for the given CIDRs and gateway IP
239-
// always use default gateway IP for containerd to configure routes;
240-
// containerd will set route with default gateway ip like 10.0.0.0/16 via 0.0.0.0 dev eth0
241241
routes = append(routes, k.AddRoutes(v4IPs, defaultGateway)...)
242242
}
243243

cns/middlewares/k8sSwiftV2_windows_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestSetRoutesSuccess(t *testing.T) {
2020
middleware := K8sSWIFTv2Middleware{Cli: mock.NewClient()}
2121
t.Setenv(configuration.EnvServiceCIDRs, "10.0.0.0/16")
2222
t.Setenv(configuration.EnvInfraVNETCIDRs, "10.240.0.10/16")
23+
t.Setenv(configuration.EnvPodCIDRs, "10.1.0.10/24") // make sure windows swiftv2 does not set pod cidr route
2324

2425
podIPInfo := []cns.PodIpInfo{
2526
{

0 commit comments

Comments
 (0)