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