Skip to content

Commit

Permalink
update policy route when change from ecmp to active-standby (#2717)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed May 3, 2023
1 parent ba63982 commit a55db01
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
24 changes: 22 additions & 2 deletions pkg/controller/node.go
Expand Up @@ -1112,17 +1112,37 @@ func (c *Controller) getPolicyRouteParas(cidr string, priority int32) ([]string,
}

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

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

func (c *Controller) checkPolicyRouteConsistent(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 c.config.EnableEcmp {
if util.ContainsString(nextHops, nexthop) {
return true, nil
}
} else {
if len(nextHops) == 1 && nextHops[0] == nexthop {
return true, nil
}
}
return false, nil
}

func (c *Controller) deletePolicyRouteForNode(nodeName string) error {
subnets, err := c.subnetsLister.List(labels.Everything())
if err != nil {
Expand Down
17 changes: 14 additions & 3 deletions pkg/controller/subnet.go
Expand Up @@ -1365,6 +1365,17 @@ func (c *Controller) reconcileOvnRoute(subnet *kubeovnv1.Subnet) error {
node, err := c.nodesLister.Get(subnet.Status.ActivateGateway)
if err == nil && nodeReady(node) {
klog.Infof("subnet %s uses the old activate gw %s", subnet.Name, node.Name)

nodeTunlIPAddr, err := getNodeTunlIP(node)
if err != nil {
klog.Errorf("failed to get gatewayNode tunnel ip for subnet %s", subnet.Name)
return err
}
nextHop := getNextHopByTunnelIP(nodeTunlIPAddr)
if err = c.addPolicyRouteForCentralizedSubnet(subnet, subnet.Status.ActivateGateway, nil, strings.Split(nextHop, ",")); err != nil {
klog.Errorf("failed to add active-backup policy route for centralized subnet %s: %v", subnet.Name, err)
return err
}
return nil
}
}
Expand Down Expand Up @@ -1898,12 +1909,12 @@ func (c *Controller) addPolicyRouteForCentralizedSubnet(subnet *kubeovnv1.Subnet
if util.CheckProtocol(cidrBlock) != util.CheckProtocol(nodeIP) {
continue
}
exist, err := c.checkPolicyRouteExistForNode(nodeName, cidrBlock, nodeIP, util.GatewayRouterPolicyPriority)
consistent, err := c.checkPolicyRouteConsistent(nodeName, cidrBlock, nodeIP, util.GatewayRouterPolicyPriority)
if err != nil {
klog.Errorf("check ecmp policy route exist for subnet %v, error %v", subnet.Name, err)
klog.Errorf("failed to check policy route for subnet %v, error %v", subnet.Name, err)
continue
}
if exist {
if consistent {
continue
}
var nextHops []string
Expand Down

0 comments on commit a55db01

Please sign in to comment.