@@ -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
10151func (k * K8sSWIFTv2Middleware ) assignSubnetPrefixLengthFields (_ * cns.PodIpInfo , _ v1alpha1.InterfaceInfo , _ string ) error {
10252 return nil
0 commit comments