Skip to content

Commit 0527b9b

Browse files
committed
controller: fix vpc egress gateway not working for targets within the internal subnet's cidr (#6218)
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
1 parent 9c0e272 commit 0527b9b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/controller/vpc_egress_gateway.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ 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]()
314315
ipv4ForwardSrc, ipv6ForwardSrc := set.New[string](), set.New[string]()
315316
ipv4SNATSrc, ipv6SNATSrc := set.New[string](), set.New[string]()
316317
fnFilter := func(internalCIDR string, ipBlocks []string) set.Set[string] {
@@ -329,6 +330,8 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
329330

330331
for _, policy := range gw.Spec.Policies {
331332
ipv4, ipv6 := util.SplitIpsByProtocol(policy.IPBlocks)
333+
ipv4Src = ipv4Src.Insert(ipv4...)
334+
ipv6Src = ipv6Src.Insert(ipv6...)
332335
filteredV4 := fnFilter(internalCIDRv4, ipv4)
333336
filteredV6 := fnFilter(internalCIDRv6, ipv6)
334337
if policy.SNAT {
@@ -339,11 +342,6 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
339342
ipv6ForwardSrc = ipv6ForwardSrc.Union(filteredV6)
340343
}
341344
for _, subnetName := range policy.Subnets {
342-
if subnetName == internalSubnet {
343-
// skip the internal subnet
344-
continue
345-
}
346-
347345
subnet, err := c.subnetsLister.Get(subnetName)
348346
if err != nil {
349347
klog.Error(err)
@@ -356,6 +354,8 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
356354
}
357355
// TODO: check subnet's vpc and vlan
358356
ipv4, ipv6 := util.SplitStringIP(subnet.Spec.CIDRBlock)
357+
ipv4Src = ipv4Src.Insert(ipv4)
358+
ipv6Src = ipv6Src.Insert(ipv6)
359359
if policy.SNAT {
360360
ipv4SNATSrc.Insert(ipv4)
361361
ipv6SNATSrc.Insert(ipv6)
@@ -367,6 +367,8 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
367367
}
368368

369369
// calculate internal route destinations and forward source CIDR blocks
370+
ipv4Src.Delete("")
371+
ipv6Src.Delete("")
370372
ipv4ForwardSrc.Delete("")
371373
ipv6ForwardSrc.Delete("")
372374
ipv4SNATSrc.Delete("")
@@ -565,7 +567,7 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
565567

566568
// return the source CIDR blocks for later OVN resources reconciliation
567569
deploy.APIVersion, deploy.Kind = deploymentGroupVersion, deploymentKind
568-
return attachmentNetworkName, intRouteDstIPv4, intRouteDstIPv6, deploy, nil
570+
return attachmentNetworkName, ipv4Src, ipv6Src, deploy, nil
569571
}
570572

571573
func (c *Controller) reconcileVpcEgressGatewayOVNRoutes(gw *kubeovnv1.VpcEgressGateway, af int, lrName, lrpName, bfdIP string, nextHops map[string]string, sources set.Set[string]) error {

0 commit comments

Comments
 (0)