Skip to content

Commit ff47ed7

Browse files
committed
fix addRoutes
1 parent 70d7777 commit ff47ed7

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

cns/middlewares/k8sSwiftV2.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,14 @@ func (k *K8sSWIFTv2Middleware) getIPConfig(ctx context.Context, podInfo cns.PodI
247247
func (k *K8sSWIFTv2Middleware) Type() cns.SWIFTV2Mode {
248248
return cns.K8sSWIFTV2
249249
}
250+
251+
func (k *K8sSWIFTv2Middleware) AddRoutes(cidrs []string, gatewayIP string) []cns.Route {
252+
routes := make([]cns.Route, len(cidrs))
253+
for i, cidr := range cidrs {
254+
routes[i] = cns.Route{
255+
IPAddress: cidr,
256+
GatewayIPAddress: gatewayIP,
257+
}
258+
}
259+
return routes
260+
}

cns/middlewares/k8sSwiftV2_linux.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
6666
}
6767

6868
if ip.Is4() {
69-
routes = append(routes, addRoutes(podCIDRsV4, overlayGatewayv4)...)
70-
routes = append(routes, addRoutes(serviceCIDRsV4, overlayGatewayv4)...)
71-
routes = append(routes, addRoutes(infraVNETCIDRsv4, overlayGatewayv4)...)
69+
routes = append(routes, k.AddRoutes(podCIDRsV4, overlayGatewayv4)...)
70+
routes = append(routes, k.AddRoutes(serviceCIDRsV4, overlayGatewayv4)...)
71+
routes = append(routes, k.AddRoutes(infraVNETCIDRsv4, overlayGatewayv4)...)
7272
} else {
73-
routes = append(routes, addRoutes(podCIDRv6, overlayGatewayV6)...)
74-
routes = append(routes, addRoutes(serviceCIDRsV6, overlayGatewayV6)...)
75-
routes = append(routes, addRoutes(infraVNETCIDRsv6, overlayGatewayV6)...)
73+
routes = append(routes, k.AddRoutes(podCIDRv6, overlayGatewayV6)...)
74+
routes = append(routes, k.AddRoutes(serviceCIDRsV6, overlayGatewayV6)...)
75+
routes = append(routes, k.AddRoutes(infraVNETCIDRsv6, overlayGatewayV6)...)
7676
}
7777
podIPInfo.SkipDefaultRoutes = true
7878

@@ -86,17 +86,6 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
8686
return nil
8787
}
8888

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-
10089
// assignSubnetPrefixLengthFields is a no-op for linux swiftv2 as the default prefix-length is sufficient
10190
func (k *K8sSWIFTv2Middleware) assignSubnetPrefixLengthFields(_ *cns.PodIpInfo, _ v1alpha1.InterfaceInfo, _ string) error {
10291
return nil

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
6161
}
6262

6363
if ip.Is4() {
64-
podIPInfo.Routes = append(podIPInfo.Routes, addRoutes(podCIDRsV4, overlayGatewayv4)...)
65-
podIPInfo.Routes = append(podIPInfo.Routes, addRoutes(serviceCIDRsV4, overlayGatewayv4)...)
66-
podIPInfo.Routes = append(podIPInfo.Routes, addRoutes(infraVNETCIDRsv4, overlayGatewayv4)...)
64+
podIPInfo.Routes = append(podIPInfo.Routes, k.AddRoutes(podCIDRsV4, overlayGatewayv4)...)
65+
podIPInfo.Routes = append(podIPInfo.Routes, k.AddRoutes(serviceCIDRsV4, overlayGatewayv4)...)
66+
podIPInfo.Routes = append(podIPInfo.Routes, k.AddRoutes(infraVNETCIDRsv4, overlayGatewayv4)...)
6767
} else {
68-
podIPInfo.Routes = append(podIPInfo.Routes, addRoutes(podCIDRv6, overlayGatewayV6)...)
69-
podIPInfo.Routes = append(podIPInfo.Routes, addRoutes(serviceCIDRsV6, overlayGatewayV6)...)
70-
podIPInfo.Routes = append(podIPInfo.Routes, addRoutes(infraVNETCIDRsv6, overlayGatewayV6)...)
68+
podIPInfo.Routes = append(podIPInfo.Routes, k.AddRoutes(podCIDRv6, overlayGatewayV6)...)
69+
podIPInfo.Routes = append(podIPInfo.Routes, k.AddRoutes(serviceCIDRsV6, overlayGatewayV6)...)
70+
podIPInfo.Routes = append(podIPInfo.Routes, k.AddRoutes(infraVNETCIDRsv6, overlayGatewayV6)...)
7171
}
7272

7373
podIPInfo.SkipDefaultRoutes = true

0 commit comments

Comments
 (0)