-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: route issues on Swiftv2 Windows #3205
base: master
Are you sure you want to change the base?
Changes from 24 commits
6b60041
909e842
e2ec36a
4f283bd
6632c76
7d3b8c1
12facb8
298d5fc
535bcb6
ea4f9a1
49dc1dc
eec67b8
6cbd918
7a1cf77
f931460
fe6a5e9
9437123
e37e7b5
38b82a6
6e6e683
c1c6da3
d609b14
34c6061
4f8ef4f
e3982fb
b32f48f
fb7b987
45cf623
7ddf286
d1c2ae3
500698f
11604e6
a4d484f
f15292a
35a33ae
8e94fc6
91847f5
a3053a8
6389118
0c67be2
e6f4d86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,7 @@ import ( | |
"net/netip" | ||
|
||
"github.com/Azure/azure-container-networking/cns" | ||
"github.com/Azure/azure-container-networking/cns/configuration" | ||
"github.com/Azure/azure-container-networking/cns/logger" | ||
"github.com/Azure/azure-container-networking/cns/middlewares/utils" | ||
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1" | ||
"github.com/pkg/errors" | ||
) | ||
|
@@ -30,50 +28,12 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error { | |
routes = append(routes, virtualGWRoute, route) | ||
|
||
case cns.InfraNIC: | ||
// Get and parse infraVNETCIDRs from env | ||
infraVNETCIDRs, err := configuration.InfraVNETCIDRs() | ||
// Linux uses 169.254.1.1 as the default ipv4 gateway and fe80::1234:5678:9abc as the default ipv6 gateway | ||
infraRoutes, err := k.setInfraRoutes(podIPInfo) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to get infraVNETCIDRs from env") | ||
} | ||
infraVNETCIDRsv4, infraVNETCIDRsv6, err := utils.ParseCIDRs(infraVNETCIDRs) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to parse infraVNETCIDRs") | ||
} | ||
|
||
// Get and parse podCIDRs from env | ||
podCIDRs, err := configuration.PodCIDRs() | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to get podCIDRs from env") | ||
} | ||
podCIDRsV4, podCIDRv6, err := utils.ParseCIDRs(podCIDRs) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to parse podCIDRs") | ||
} | ||
|
||
// Get and parse serviceCIDRs from env | ||
serviceCIDRs, err := configuration.ServiceCIDRs() | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to get serviceCIDRs from env") | ||
} | ||
serviceCIDRsV4, serviceCIDRsV6, err := utils.ParseCIDRs(serviceCIDRs) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to parse serviceCIDRs") | ||
} | ||
|
||
ip, err := netip.ParseAddr(podIPInfo.PodIPConfig.IPAddress) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to parse podIPConfig IP address %s", podIPInfo.PodIPConfig.IPAddress) | ||
} | ||
|
||
if ip.Is4() { | ||
routes = append(routes, addRoutes(podCIDRsV4, overlayGatewayv4)...) | ||
routes = append(routes, addRoutes(serviceCIDRsV4, overlayGatewayv4)...) | ||
routes = append(routes, addRoutes(infraVNETCIDRsv4, overlayGatewayv4)...) | ||
} else { | ||
routes = append(routes, addRoutes(podCIDRv6, overlayGatewayV6)...) | ||
routes = append(routes, addRoutes(serviceCIDRsV6, overlayGatewayV6)...) | ||
routes = append(routes, addRoutes(infraVNETCIDRsv6, overlayGatewayV6)...) | ||
return errors.Wrap(err, "failed to set routes for infraNIC interface") | ||
} | ||
routes = infraRoutes | ||
podIPInfo.SkipDefaultRoutes = true | ||
|
||
case cns.NodeNetworkInterfaceBackendNIC: //nolint:exhaustive // ignore exhaustive types check | ||
|
@@ -86,7 +46,14 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error { | |
return nil | ||
} | ||
|
||
func addRoutes(cidrs []string, gatewayIP string) []cns.Route { | ||
// assignSubnetPrefixLengthFields is a no-op for linux swiftv2 as the default prefix-length is sufficient | ||
func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(_ *cns.PodIpInfo, _ v1alpha1.InterfaceInfo, _ string) error { | ||
return nil | ||
} | ||
|
||
paulyufan2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (k *K8sSWIFTv2Middleware) addDefaultRoute(*cns.PodIpInfo, string) {} | ||
|
||
func (k *K8sSWIFTv2Middleware) addRoutes(cidrs []string, gatewayIP string) []cns.Route { | ||
routes := make([]cns.Route, len(cidrs)) | ||
for i, cidr := range cidrs { | ||
routes[i] = cns.Route{ | ||
|
@@ -97,9 +64,24 @@ func addRoutes(cidrs []string, gatewayIP string) []cns.Route { | |
return routes | ||
} | ||
|
||
// assignSubnetPrefixLengthFields is a no-op for linux swiftv2 as the default prefix-length is sufficient | ||
func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(_ *cns.PodIpInfo, _ v1alpha1.InterfaceInfo, _ string) error { | ||
return nil | ||
} | ||
func (k *K8sSWIFTv2Middleware) setInfraRoutes(podIPInfo *cns.PodIpInfo) ([]cns.Route, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we change this to |
||
var routes []cns.Route | ||
|
||
func (k *K8sSWIFTv2Middleware) addDefaultRoute(*cns.PodIpInfo, string) {} | ||
ip, err := netip.ParseAddr(podIPInfo.PodIPConfig.IPAddress) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to parse podIPConfig IP address %s", podIPInfo.PodIPConfig.IPAddress) | ||
} | ||
|
||
v4IPs, v6IPs, err := k.GetCidrs() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get CIDRs") | ||
} | ||
|
||
if ip.Is4() { | ||
routes = append(routes, k.addRoutes(v4IPs, overlayGatewayv4)...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm comparing the getInfraRoutes code in the _linux.go file and the getInfraRoutes code in the _windows.go file and noticed that overlayGatewayv4 / v6 is added in linux-- could you provide background on this (does it make an appearance in windows, and what is it used for?). Also the casing is inconsistent for v4 and V6 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I think I added comments somewhere; Windows: always use 0.0.0.0 as the default gateway IP for containerd to program the routing table and ipv6 is not supported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for clarifying, could we also add that note (regarding the gateway ip) above this function if it is still present after the refactor? |
||
} else { | ||
routes = append(routes, k.addRoutes(v6IPs, overlayGatewayV6)...) | ||
} | ||
|
||
return routes, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package middlewares | |
import ( | ||
"context" | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/Azure/azure-container-networking/cns" | ||
|
@@ -342,10 +343,10 @@ func TestSetRoutesSuccess(t *testing.T) { | |
} else { | ||
assert.Equal(t, ipInfo.SkipDefaultRoutes, false) | ||
} | ||
|
||
} | ||
|
||
for i := range podIPInfo { | ||
assert.DeepEqual(t, podIPInfo[i].Routes, desiredPodIPInfo[i].Routes) | ||
reflect.DeepEqual(podIPInfo[i].Routes, desiredPodIPInfo[i].Routes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preference towards |
||
} | ||
} | ||
|
||
|
@@ -378,9 +379,10 @@ func TestSetRoutesFailure(t *testing.T) { | |
} | ||
|
||
func TestAddRoutes(t *testing.T) { | ||
middleware := K8sSWIFTv2Middleware{Cli: mock.NewClient()} | ||
cidrs := []string{"10.0.0.0/24", "20.0.0.0/24"} | ||
gatewayIP := "192.168.1.1" | ||
routes := addRoutes(cidrs, gatewayIP) | ||
routes := middleware.addRoutes(cidrs, gatewayIP) | ||
expectedRoutes := []cns.Route{ | ||
{ | ||
IPAddress: "10.0.0.0/24", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use named returns please, they have surprising semantics. For example, these two lines are unnecessary since they are auto-initialized.