Skip to content

Commit

Permalink
match chassis until timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
lut777 committed Jul 16, 2021
1 parent 187c594 commit 27c649a
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -225,7 +226,7 @@ func (c *Controller) handleAddNode(key string) error {
return err
}

if err := c.checkChassisDupl(node); err != nil {
if err := c.retryDelDupChassis(util.ChasRetryTime, util.ChasRetryIntev+2, c.checkChassisDupl, node); err != nil {
return err
}

Expand Down Expand Up @@ -413,7 +414,7 @@ func (c *Controller) handleUpdateNode(key string) error {
return err
}

if err := c.checkChassisDupl(node); err != nil {
if err := c.retryDelDupChassis(util.ChasRetryTime, util.ChasRetryIntev+2, c.checkChassisDupl, node); err != nil {
return err
}

Expand Down Expand Up @@ -604,17 +605,37 @@ func (c *Controller) checkChassisDupl(node *v1.Node) error {
klog.Errorf("failed to get node %s chassisID, %v", node.Name, err)
return err
}

chassisAnn := node.Annotations[util.ChassisAnnotation]
if chassisAnn != "" && chassisAnn != chassisAdd {
klog.Errorf("duplicate chassis for node %s and new chassis %s", node.Name, chassisAdd)
if err := c.ovnClient.DeleteChassis(node.Name); err != nil {
klog.Errorf("failed to delete chassis for node %s %v", node.Name, err)
return err
}
if chassisAnn == chassisAdd || chassisAnn == "" {
return nil
}

klog.V(3).Infof("finish check chassis, add %s and ann %s", chassisAdd, chassisAnn)
klog.Errorf("duplicate chassis for node %s and new chassis %s", node.Name, chassisAdd)
if err := c.ovnClient.DeleteChassis(node.Name); err != nil {
klog.Errorf("failed to delete chassis for node %s %v", node.Name, err)
return err
}
return errors.New("deleting dismatch chassis id")
}

func (c *Controller) retryDelDupChassis(attempts int, sleep int, f func(node *v1.Node) error, node *v1.Node) (err error) {
i := 0
for ; ; i++ {
err = f(node)
if err == nil {
return
}
if i >= (attempts - 1) {
break
}
time.Sleep(time.Duration(sleep) * time.Second)
}
if i >= (attempts - 1) {
errMsg := fmt.Errorf("exhausting all attempts")
klog.Error(errMsg)
return errMsg
}
klog.V(3).Infof("finish check chassis")
return nil
}

Expand Down

0 comments on commit 27c649a

Please sign in to comment.