Skip to content

Commit 98518ea

Browse files
committed
Minor improvement to route add for remote zone nodes
Just execute the 2 route adds in the same txn Signed-off-by: Tim Rozet <[email protected]>
1 parent edc159d commit 98518ea

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

go-controller/pkg/ovn/zone_interconnect/zone_ic_handler.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
utilnet "k8s.io/utils/net"
1414

1515
libovsdbclient "github.com/ovn-org/libovsdb/client"
16+
"github.com/ovn-org/libovsdb/ovsdb"
1617

1718
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/factory"
1819
libovsdbops "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/libovsdb/ops"
@@ -568,6 +569,7 @@ func (zic *ZoneInterconnectHandler) cleanupNodeTransitSwitchPort(nodeName string
568569
// ip4.dst == 10.244.0.0/24 , nexthop = 100.88.0.2
569570
// ip4.dst == 100.64.0.2/16 , nexthop = 100.88.0.2 (only for default primary network)
570571
func (zic *ZoneInterconnectHandler) addRemoteNodeStaticRoutes(node *corev1.Node, nodeTransitSwitchPortIPs, nodeSubnets, nodeGRPIPs []*net.IPNet) error {
572+
ops := make([]ovsdb.Operation, 0, 2)
571573
addRoute := func(prefix, nexthop string) error {
572574
logicalRouterStaticRoute := nbdb.LogicalRouterStaticRoute{
573575
ExternalIDs: map[string]string{
@@ -581,37 +583,32 @@ func (zic *ZoneInterconnectHandler) addRemoteNodeStaticRoutes(node *corev1.Node,
581583
lrsr.Nexthop == nexthop &&
582584
lrsr.ExternalIDs["ic-node"] == node.Name
583585
}
584-
if err := libovsdbops.CreateOrReplaceLogicalRouterStaticRouteWithPredicate(zic.nbClient, zic.networkClusterRouterName, &logicalRouterStaticRoute, p); err != nil {
585-
return fmt.Errorf("failed to create static route: %w", err)
586+
var err error
587+
ops, err = libovsdbops.CreateOrReplaceLogicalRouterStaticRouteWithPredicateOps(zic.nbClient, ops, zic.networkClusterRouterName, &logicalRouterStaticRoute, p)
588+
if err != nil {
589+
return fmt.Errorf("failed to create static route ops: %w", err)
586590
}
587591
return nil
588592
}
589593

590594
nodeSubnetStaticRoutes := zic.getStaticRoutes(nodeSubnets, nodeTransitSwitchPortIPs, false)
591595
for _, staticRoute := range nodeSubnetStaticRoutes {
592-
// Possible optimization: Add all the routes in one transaction
593596
if err := addRoute(staticRoute.prefix, staticRoute.nexthop); err != nil {
594597
return fmt.Errorf("error adding static route %s - %s to the router %s : %w", staticRoute.prefix, staticRoute.nexthop, zic.networkClusterRouterName, err)
595598
}
596599
}
597600

598-
if zic.IsSecondary() && !(util.IsNetworkSegmentationSupportEnabled() && zic.IsPrimaryNetwork()) {
599-
// Secondary network cluster router doesn't connect to a join switch
600-
// or to a Gateway router.
601-
//
602-
// Except for UDN primary L3 networks.
603-
return nil
604-
}
605-
606-
nodeGRPIPStaticRoutes := zic.getStaticRoutes(nodeGRPIPs, nodeTransitSwitchPortIPs, true)
607-
for _, staticRoute := range nodeGRPIPStaticRoutes {
608-
// Possible optimization: Add all the routes in one transaction
609-
if err := addRoute(staticRoute.prefix, staticRoute.nexthop); err != nil {
610-
return fmt.Errorf("error adding static route %s - %s to the router %s : %w", staticRoute.prefix, staticRoute.nexthop, zic.networkClusterRouterName, err)
601+
if len(nodeGRPIPs) > 0 {
602+
nodeGRPIPStaticRoutes := zic.getStaticRoutes(nodeGRPIPs, nodeTransitSwitchPortIPs, true)
603+
for _, staticRoute := range nodeGRPIPStaticRoutes {
604+
if err := addRoute(staticRoute.prefix, staticRoute.nexthop); err != nil {
605+
return fmt.Errorf("error adding static route %s - %s to the router %s : %w", staticRoute.prefix, staticRoute.nexthop, zic.networkClusterRouterName, err)
606+
}
611607
}
612608
}
613609

614-
return nil
610+
_, err := libovsdbops.TransactAndCheck(zic.nbClient, ops)
611+
return err
615612
}
616613

617614
// deleteLocalNodeStaticRoutes deletes the static routes added by the function addRemoteNodeStaticRoutes

0 commit comments

Comments
 (0)