Skip to content

Commit a82289a

Browse files
zhangzujianzbb88888
authored andcommitted
controller: fix vpc egress gateway not working for targets within the internal subnet's cidr (kubeovn#6218)
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
1 parent 437dcb2 commit a82289a

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
@@ -310,6 +310,7 @@ 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]()
313314
ipv4ForwardSrc, ipv6ForwardSrc := set.New[string](), set.New[string]()
314315
ipv4SNATSrc, ipv6SNATSrc := set.New[string](), set.New[string]()
315316
fnFilter := func(internalCIDR string, ipBlocks []string) set.Set[string] {
@@ -328,6 +329,8 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
328329

329330
for _, policy := range gw.Spec.Policies {
330331
ipv4, ipv6 := util.SplitIpsByProtocol(policy.IPBlocks)
332+
ipv4Src = ipv4Src.Insert(ipv4...)
333+
ipv6Src = ipv6Src.Insert(ipv6...)
331334
filteredV4 := fnFilter(internalCIDRv4, ipv4)
332335
filteredV6 := fnFilter(internalCIDRv6, ipv6)
333336
if policy.SNAT {
@@ -338,11 +341,6 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
338341
ipv6ForwardSrc = ipv6ForwardSrc.Union(filteredV6)
339342
}
340343
for _, subnetName := range policy.Subnets {
341-
if subnetName == internalSubnet {
342-
// skip the internal subnet
343-
continue
344-
}
345-
346344
subnet, err := c.subnetsLister.Get(subnetName)
347345
if err != nil {
348346
klog.Error(err)
@@ -355,6 +353,8 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
355353
}
356354
// TODO: check subnet's vpc and vlan
357355
ipv4, ipv6 := util.SplitStringIP(subnet.Spec.CIDRBlock)
356+
ipv4Src = ipv4Src.Insert(ipv4)
357+
ipv6Src = ipv6Src.Insert(ipv6)
358358
if policy.SNAT {
359359
ipv4SNATSrc.Insert(ipv4)
360360
ipv6SNATSrc.Insert(ipv6)
@@ -366,6 +366,8 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
366366
}
367367

368368
// calculate internal route destinations and forward source CIDR blocks
369+
ipv4Src.Delete("")
370+
ipv6Src.Delete("")
369371
ipv4ForwardSrc.Delete("")
370372
ipv6ForwardSrc.Delete("")
371373
ipv4SNATSrc.Delete("")
@@ -564,7 +566,7 @@ func (c *Controller) reconcileVpcEgressGatewayWorkload(gw *kubeovnv1.VpcEgressGa
564566

565567
// return the source CIDR blocks for later OVN resources reconciliation
566568
deploy.APIVersion, deploy.Kind = appsv1.SchemeGroupVersion.String(), util.KindDeployment
567-
return attachmentNetworkName, intRouteDstIPv4, intRouteDstIPv6, deploy, nil
569+
return attachmentNetworkName, ipv4Src, ipv6Src, deploy, nil
568570
}
569571

570572
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)