@@ -310,35 +310,16 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
310310 internalCIDRv4 , internalCIDRv6 := util .SplitStringIP (intSubnet .Spec .CIDRBlock )
311311
312312 // collect egress policies
313- ipv4Src , ipv6Src := set .New [string ](), set .New [string ]()
314313 ipv4ForwardSrc , ipv6ForwardSrc := set .New [string ](), set .New [string ]()
315314 ipv4SNATSrc , ipv6SNATSrc := set .New [string ](), set .New [string ]()
316- fnFilter := func (internalCIDR string , ipBlocks []string ) set.Set [string ] {
317- if internalCIDR == "" {
318- return nil
319- }
320-
321- ret := set .New [string ]()
322- for _ , cidr := range ipBlocks {
323- if ok , _ := util .CIDRContainsCIDR (internalCIDR , cidr ); ! ok {
324- ret .Insert (cidr )
325- }
326- }
327- return ret
328- }
329-
330315 for _ , policy := range gw .Spec .Policies {
331316 ipv4 , ipv6 := util .SplitIpsByProtocol (policy .IPBlocks )
332- ipv4Src = ipv4Src .Insert (ipv4 ... )
333- ipv6Src = ipv6Src .Insert (ipv6 ... )
334- filteredV4 := fnFilter (internalCIDRv4 , ipv4 )
335- filteredV6 := fnFilter (internalCIDRv6 , ipv6 )
336317 if policy .SNAT {
337- ipv4SNATSrc = ipv4SNATSrc .Union ( filteredV4 )
338- ipv6SNATSrc = ipv6SNATSrc .Union ( filteredV6 )
318+ ipv4SNATSrc = ipv4SNATSrc .Insert ( ipv4 ... )
319+ ipv6SNATSrc = ipv6SNATSrc .Insert ( ipv6 ... )
339320 } else {
340- ipv4ForwardSrc = ipv4ForwardSrc .Union ( filteredV4 )
341- ipv6ForwardSrc = ipv6ForwardSrc .Union ( filteredV6 )
321+ ipv4ForwardSrc = ipv4ForwardSrc .Insert ( ipv4 ... )
322+ ipv6ForwardSrc = ipv6ForwardSrc .Insert ( ipv6 ... )
342323 }
343324 for _ , subnetName := range policy .Subnets {
344325 subnet , err := c .subnetsLister .Get (subnetName )
@@ -353,8 +334,6 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
353334 }
354335 // TODO: check subnet's vpc and vlan
355336 ipv4 , ipv6 := util .SplitStringIP (subnet .Spec .CIDRBlock )
356- ipv4Src = ipv4Src .Insert (ipv4 )
357- ipv6Src = ipv6Src .Insert (ipv6 )
358337 if policy .SNAT {
359338 ipv4SNATSrc .Insert (ipv4 )
360339 ipv6SNATSrc .Insert (ipv6 )
@@ -366,13 +345,29 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
366345 }
367346
368347 // calculate internal route destinations and forward source CIDR blocks
369- ipv4Src .Delete ("" )
370- ipv6Src .Delete ("" )
371348 ipv4ForwardSrc .Delete ("" )
372349 ipv6ForwardSrc .Delete ("" )
373350 ipv4SNATSrc .Delete ("" )
374351 ipv6SNATSrc .Delete ("" )
375- intRouteDstIPv4 , intRouteDstIPv6 := ipv4ForwardSrc .Union (ipv4SNATSrc ), ipv6ForwardSrc .Union (ipv6SNATSrc )
352+ ipv4Src := ipv4ForwardSrc .Union (ipv4SNATSrc )
353+ ipv6Src := ipv6ForwardSrc .Union (ipv6SNATSrc )
354+
355+ // filter out ip blocks within the internal subnet CIDR(s) to avoid route(s) configuration failure
356+ fnFilter := func (internalCIDR string , ipBlocks set.Set [string ]) set.Set [string ] {
357+ if internalCIDR == "" {
358+ return nil
359+ }
360+
361+ ret := set .New [string ]()
362+ for cidr := range ipBlocks {
363+ if ok , _ := util .CIDRContainsCIDR (internalCIDR , cidr ); ! ok {
364+ ret .Insert (cidr )
365+ }
366+ }
367+ return ret
368+ }
369+ intRouteDstIPv4 := fnFilter (internalCIDRv4 , ipv4Src )
370+ intRouteDstIPv6 := fnFilter (internalCIDRv6 , ipv6Src )
376371
377372 // generate route annotations used to configure routes in the pod
378373 routes := util .NewPodRoutes ()
0 commit comments