Skip to content

Commit

Permalink
optimize ecmp policy route (#3421)
Browse files Browse the repository at this point in the history
Signed-off-by: 马洪贞 <hzma@alauda.io>
  • Loading branch information
hongzhen-ma authored Nov 16, 2023
1 parent 81e0ec3 commit aac2ae2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
19 changes: 3 additions & 16 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ func (c *Controller) checkGatewayReady() error {
continue
}

exist, err := c.checkPolicyRouteExistForNode(node.Name, cidrBlock, ip, util.GatewayRouterPolicyPriority)
exist, err := c.checkPolicyRouteConsistent(cidrBlock, ip, util.GatewayRouterPolicyPriority)
if err != nil {
klog.Errorf("check ecmp policy route exist for subnet %v, error %v", subnet.Name, err)
break
Expand Down Expand Up @@ -1104,20 +1104,7 @@ func (c *Controller) getPolicyRouteParas(cidr string, priority int32) ([]string,
return nextHops, nameIpMap, nil
}

func (c *Controller) checkPolicyRouteExistForNode(nodeName, cidr, nexthop string, priority int32) (bool, error) {
nextHops, _, err := c.getPolicyRouteParas(cidr, priority)
if err != nil {
klog.Errorf("failed to get policy route paras, %v", err)
return false, err
}

if util.ContainsString(nextHops, nexthop) {
return true, nil
}
return false, nil
}

func (c *Controller) checkPolicyRouteConsistent(nodeName, cidr, nexthop string, priority int32) (bool, error) {
func (c *Controller) checkPolicyRouteConsistent(cidr, nexthop string, priority int32) (bool, error) {
nextHops, _, err := c.getPolicyRouteParas(cidr, priority)
if err != nil {
klog.Errorf("failed to get policy route paras, %v", err)
Expand Down Expand Up @@ -1229,7 +1216,7 @@ func (c *Controller) addPolicyRouteForCentralizedSubnetOnNode(nodeName, nodeIP s
if util.CheckProtocol(cidrBlock) != util.CheckProtocol(nextHop) {
continue
}
exist, err := c.checkPolicyRouteExistForNode(nodeName, cidrBlock, nextHop, util.GatewayRouterPolicyPriority)
exist, err := c.checkPolicyRouteConsistent(cidrBlock, nextHop, util.GatewayRouterPolicyPriority)
if err != nil {
klog.Errorf("check ecmp policy route exist for subnet %v, error %v", subnet.Name, err)
continue
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ func (c *Controller) updatePolicyRouteForCentralizedSubnet(subnetName, cidr stri
for node, ip := range nameIpMap {
externalIDs[node] = ip
}
klog.Infof("add ecmp policy route for router: %s, match %s, action %s, nexthop %s, extrenalID %s", c.config.ClusterRouter, match, "allow", "", externalIDs)
klog.Infof("add ecmp policy route for router: %s, match %s, action %s, nexthop %s, extrenalID %s", c.config.ClusterRouter, match, "reroute", nextHopIp, externalIDs)
if err := c.ovnLegacyClient.AddPolicyRoute(c.config.ClusterRouter, util.GatewayRouterPolicyPriority, match, "reroute", nextHopIp, externalIDs); err != nil {
klog.Errorf("failed to add policy route for centralized subnet %s: %v", subnetName, err)
return err
Expand All @@ -1989,7 +1989,7 @@ func (c *Controller) addPolicyRouteForCentralizedSubnet(subnet *kubeovnv1.Subnet
if util.CheckProtocol(cidrBlock) != util.CheckProtocol(nodeIP) {
continue
}
consistent, err := c.checkPolicyRouteConsistent(nodeName, cidrBlock, nodeIP, util.GatewayRouterPolicyPriority)
consistent, err := c.checkPolicyRouteConsistent(cidrBlock, nodeIP, util.GatewayRouterPolicyPriority)
if err != nil {
klog.Errorf("failed to check policy route for subnet %v, error %v", subnet.Name, err)
continue
Expand Down
13 changes: 9 additions & 4 deletions pkg/ovs/ovn-nbctl-legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"os"
"os/exec"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -2686,10 +2688,13 @@ func (c LegacyClient) CheckPolicyRouteNexthopConsistent(router, match, nexthop s
klog.Errorf("failed to get policy route paras, %v", err)
return false, err
}
for _, next := range nextHops {
if next == nexthop {
return true, nil
}
sort.Strings(nextHops)

inNextHops := strings.Split(nexthop, ",")
sort.Strings(inNextHops)

if reflect.DeepEqual(inNextHops, nextHops) {
return true, nil
}
return false, nil
}
Expand Down

0 comments on commit aac2ae2

Please sign in to comment.