Skip to content

Commit

Permalink
deleting all chassises which are not nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lut777 committed Dec 8, 2021
1 parent dbcb1a8 commit 4fb302f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ func (c *Controller) handleAddNode(key string) error {
return err
}

if err := c.RemoveRedundantChassis(node); err != nil {
return err
}

if err := c.retryDelDupChassis(util.ChasRetryTime, util.ChasRetryIntev+2, c.checkChassisDupl, node); err != nil {
return err
}
Expand Down Expand Up @@ -851,3 +855,38 @@ func (c *Controller) checkAndUpdateNodePortGroup() error {

return nil
}

func (c *Controller) RemoveRedundantChassis(node *v1.Node) error {
chassisAdd, err := c.ovnClient.GetChassis(node.Name)
if err != nil {
klog.Errorf("failed to get node %s chassisID, %v", node.Name, err)
return err
}
if chassisAdd == "" {
chassises, err := c.ovnClient.GetALlChassisHostname()
if err != nil {
klog.Errorf("failed to get all chassis, %v", err)
}
nodes, err := c.nodesLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list nodes, %v", err)
return err
}
for _, chassis := range chassises {
matched := true
for _, node := range nodes {
if chassis == node.Name {
matched = false
}
}
if matched {
if err := c.ovnClient.DeleteChassis(chassis); err != nil {
klog.Errorf("failed to delete chassis for node %s %v", chassis, err)
return err
}
}
}
return errors.New("chassis reset, reboot ovs-ovn on this node: " + node.Name)
}
return nil
}
16 changes: 16 additions & 0 deletions pkg/ovs/ovn-sbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,19 @@ func (c Client) GetChassis(node string) (string, error) {
}
return strings.TrimSpace(output), nil
}

func (c Client) GetALlChassisHostname() ([]string, error) {
output, err := c.ovnSbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=hostname", "find", "chassis")
if err != nil {
return nil, fmt.Errorf("failed to find node chassis, %v", err)
}
lines := strings.Split(output, "\n")
result := make([]string, 0, len(lines))
for _, l := range lines {
if len(strings.TrimSpace(l)) == 0 {
continue
}
result = append(result, strings.TrimSpace(l))
}
return result, nil
}

0 comments on commit 4fb302f

Please sign in to comment.