Skip to content

Commit

Permalink
delete ecmp route when node is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Jul 20, 2021
1 parent e7e1ac9 commit 41b6429
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,22 @@ func (c *Controller) checkGatewayReady() error {
}

for _, node := range nodes {
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
}
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
}
}

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 util.GatewayContains(subnet.Spec.GatewayNode, node.Name) {
pinger, err := goping.NewPinger(ip)
if err != nil {
return fmt.Errorf("failed to init pinger, %v", err)
Expand All @@ -546,11 +552,6 @@ func (c *Controller) checkGatewayReady() error {
}
pinger.Run()

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
}
Expand All @@ -572,6 +573,14 @@ func (c *Controller) checkGatewayReady() error {
}
}
}
} else {
if exist {
klog.Infof("subnet %v gatewayNode does not contains node %v, should delete ecmp route for node ip %s", subnet.Name, node.Name, ip)
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

0 comments on commit 41b6429

Please sign in to comment.