Skip to content

Commit cac583c

Browse files
committed
long-term solution for route issues windows
1 parent 5ac0e8c commit cac583c

File tree

3 files changed

+72
-53
lines changed

3 files changed

+72
-53
lines changed

cns/middlewares/k8sSwiftV2.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,65 @@ func (k *K8sSWIFTv2Middleware) getIPConfig(ctx context.Context, podInfo cns.PodI
249249
func (k *K8sSWIFTv2Middleware) Type() cns.SWIFTV2Mode {
250250
return cns.K8sSWIFTV2
251251
}
252+
253+
func (k *K8sSWIFTv2Middleware) addRoutes(cidrs []string, gatewayIP string) []cns.Route {
254+
routes := make([]cns.Route, len(cidrs))
255+
for i, cidr := range cidrs {
256+
routes[i] = cns.Route{
257+
IPAddress: cidr,
258+
GatewayIPAddress: gatewayIP,
259+
}
260+
}
261+
return routes
262+
}
263+
264+
func (k *K8sSWIFTv2Middleware) SetInfraRoutes(podIPInfo *cns.PodIpInfo) ([]cns.Route, error) {
265+
var routes []cns.Route
266+
267+
// Get and parse infraVNETCIDRs from env
268+
infraVNETCIDRs, err := configuration.InfraVNETCIDRs()
269+
if err != nil {
270+
return nil, errors.Wrapf(err, "failed to get infraVNETCIDRs from env")
271+
}
272+
infraVNETCIDRsv4, infraVNETCIDRsv6, err := utils.ParseCIDRs(infraVNETCIDRs)
273+
if err != nil {
274+
return nil, errors.Wrapf(err, "failed to parse infraVNETCIDRs")
275+
}
276+
277+
// Get and parse podCIDRs from env
278+
podCIDRs, err := configuration.PodCIDRs()
279+
if err != nil {
280+
return nil, errors.Wrapf(err, "failed to get podCIDRs from env")
281+
}
282+
podCIDRsV4, podCIDRv6, err := utils.ParseCIDRs(podCIDRs)
283+
if err != nil {
284+
return nil, errors.Wrapf(err, "failed to parse podCIDRs")
285+
}
286+
287+
// Get and parse serviceCIDRs from env
288+
serviceCIDRs, err := configuration.ServiceCIDRs()
289+
if err != nil {
290+
return nil, errors.Wrapf(err, "failed to get serviceCIDRs from env")
291+
}
292+
serviceCIDRsV4, serviceCIDRsV6, err := utils.ParseCIDRs(serviceCIDRs)
293+
if err != nil {
294+
return nil, errors.Wrapf(err, "failed to parse serviceCIDRs")
295+
}
296+
297+
ip, err := netip.ParseAddr(podIPInfo.PodIPConfig.IPAddress)
298+
if err != nil {
299+
return nil, errors.Wrapf(err, "failed to parse podIPConfig IP address %s", podIPInfo.PodIPConfig.IPAddress)
300+
}
301+
302+
if ip.Is4() {
303+
routes = append(routes, k.addRoutes(podCIDRsV4, overlayGatewayv4)...)
304+
routes = append(routes, k.addRoutes(serviceCIDRsV4, overlayGatewayv4)...)
305+
routes = append(routes, k.addRoutes(infraVNETCIDRsv4, overlayGatewayv4)...)
306+
} else {
307+
routes = append(routes, k.addRoutes(podCIDRv6, overlayGatewayV6)...)
308+
routes = append(routes, k.addRoutes(serviceCIDRsV6, overlayGatewayV6)...)
309+
routes = append(routes, k.addRoutes(infraVNETCIDRsv6, overlayGatewayV6)...)
310+
}
311+
312+
return routes, nil
313+
}

cns/middlewares/k8sSwiftV2_linux.go

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,11 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
3030
routes = append(routes, virtualGWRoute, route)
3131

3232
case cns.InfraNIC:
33-
// Get and parse infraVNETCIDRs from env
34-
infraVNETCIDRs, err := configuration.InfraVNETCIDRs()
33+
infraRoutes, err := k.SetInfraRoutes(podIPInfo)
3534
if err != nil {
36-
return errors.Wrapf(err, "failed to get infraVNETCIDRs from env")
37-
}
38-
infraVNETCIDRsv4, infraVNETCIDRsv6, err := utils.ParseCIDRs(infraVNETCIDRs)
39-
if err != nil {
40-
return errors.Wrapf(err, "failed to parse infraVNETCIDRs")
41-
}
42-
43-
// Get and parse podCIDRs from env
44-
podCIDRs, err := configuration.PodCIDRs()
45-
if err != nil {
46-
return errors.Wrapf(err, "failed to get podCIDRs from env")
47-
}
48-
podCIDRsV4, podCIDRv6, err := utils.ParseCIDRs(podCIDRs)
49-
if err != nil {
50-
return errors.Wrapf(err, "failed to parse podCIDRs")
51-
}
52-
53-
// Get and parse serviceCIDRs from env
54-
serviceCIDRs, err := configuration.ServiceCIDRs()
55-
if err != nil {
56-
return errors.Wrapf(err, "failed to get serviceCIDRs from env")
57-
}
58-
serviceCIDRsV4, serviceCIDRsV6, err := utils.ParseCIDRs(serviceCIDRs)
59-
if err != nil {
60-
return errors.Wrapf(err, "failed to parse serviceCIDRs")
61-
}
62-
63-
ip, err := netip.ParseAddr(podIPInfo.PodIPConfig.IPAddress)
64-
if err != nil {
65-
return errors.Wrapf(err, "failed to parse podIPConfig IP address %s", podIPInfo.PodIPConfig.IPAddress)
66-
}
67-
68-
if ip.Is4() {
69-
routes = append(routes, addRoutes(podCIDRsV4, overlayGatewayv4)...)
70-
routes = append(routes, addRoutes(serviceCIDRsV4, overlayGatewayv4)...)
71-
routes = append(routes, addRoutes(infraVNETCIDRsv4, overlayGatewayv4)...)
72-
} else {
73-
routes = append(routes, addRoutes(podCIDRv6, overlayGatewayV6)...)
74-
routes = append(routes, addRoutes(serviceCIDRsV6, overlayGatewayV6)...)
75-
routes = append(routes, addRoutes(infraVNETCIDRsv6, overlayGatewayV6)...)
35+
return errors.Wrap(err, "failed to set routes for infraNIC interface")
7636
}
37+
routes = infraRoutes
7738
podIPInfo.SkipDefaultRoutes = true
7839

7940
case cns.NodeNetworkInterfaceBackendNIC: //nolint:exhaustive // ignore exhaustive types check
@@ -86,17 +47,6 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
8647
return nil
8748
}
8849

89-
func addRoutes(cidrs []string, gatewayIP string) []cns.Route {
90-
routes := make([]cns.Route, len(cidrs))
91-
for i, cidr := range cidrs {
92-
routes[i] = cns.Route{
93-
IPAddress: cidr,
94-
GatewayIPAddress: gatewayIP,
95-
}
96-
}
97-
return routes
98-
}
99-
10050
// assignSubnetPrefixLengthFields is a no-op for linux swiftv2 as the default prefix-length is sufficient
10151
func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(_ *cns.PodIpInfo, _ v1alpha1.InterfaceInfo, _ string) error {
10252
return nil

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
2020
}
2121
podIPInfo.Routes = append(podIPInfo.Routes, route)
2222

23+
// add routes for infraNIC
24+
routes, err := k.SetInfraRoutes(podIPInfo)
25+
fmt.Printf("routes are %v", routes)
26+
if err != nil {
27+
return errors.Wrap(err, "failed to set routes for infraNIC interface")
28+
}
29+
podIPInfo.Routes = routes
2330
podIPInfo.SkipDefaultRoutes = true
2431
}
2532
return nil

0 commit comments

Comments
 (0)