Skip to content

Commit

Permalink
delete ecmp route when node is not ready
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Jul 15, 2021
1 parent 72a73fb commit d26850d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ func (c *Controller) checkGatewayReady() error {
if util.GatewayContains(subnet.Spec.GatewayNode, node.Name) {
ipStr := node.Annotations[util.IpAddressAnnotation]
for _, ip := range strings.Split(ipStr, ",") {
var cidrBlock string
for _, cidrBlock = range strings.Split(subnet.Spec.CIDRBlock, ",") {
if util.CheckProtocol(cidrBlock) != util.CheckProtocol(ip) {
continue
}
}

pinger, err := goping.NewPinger(ip)
if err != nil {
return fmt.Errorf("failed to init pinger, %v", err)
Expand All @@ -524,15 +531,19 @@ func (c *Controller) checkGatewayReady() error {
}
pinger.Run()

exist, err := c.checkNodeEcmpRouteExist(ip, subnet.Spec.CIDRBlock)
exist, err := c.checkNodeEcmpRouteExist(ip, cidrBlock)
if err != nil {
klog.Errorf("get ecmp static route for subnet %v, error %v", subnet.Name, err)
break
}
if !nodeReady(node) {
success = false
}

if !success {
klog.Warningf("failed to ping gw %s", ip)
klog.Warningf("failed to ping ovn0 %s or node %v is not ready", ip, node.Name)
if exist {
if err := c.deleteStaticRoute(ip, c.config.ClusterRouter, subnet); err != nil {
if err := c.ovnClient.DeleteMatchedStaticRoute(cidrBlock, ip, c.config.ClusterRouter); err != nil {
klog.Errorf("failed to delete static route %s for node %s, %v", ip, node.Name, err)
return err
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,14 @@ func (c Client) DeleteNatRule(logicalIP, router string) error {
return err
}

func (c Client) DeleteMatchedStaticRoute(cidr, nexthop, router string) error {
if cidr == "" || nexthop == "" {
return nil
}
_, err := c.ovnNbCommand(IfExists, "lr-route-del", router, cidr, nexthop)
return err
}

// DeleteStaticRoute delete a static route rule in ovn
func (c Client) DeleteStaticRoute(cidr, router string) error {
if cidr == "" {
Expand Down

0 comments on commit d26850d

Please sign in to comment.