Skip to content

Commit

Permalink
fix deleting old sb chassis for a re-added node (#2989)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian authored Jun 28, 2023
1 parent 30cd09e commit d5d196e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
7 changes: 2 additions & 5 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,8 @@ func (c *Controller) handleUpdateNode(key string) error {
return err
}

if node.Annotations[util.ChassisAnnotation] != "" {
if err = c.ovnLegacyClient.InitChassisNodeTag(node.Annotations[util.ChassisAnnotation], node.Name); err != nil {
klog.Errorf("failed to set chassis nodeTag for node '%s', %v", node.Name, err)
return err
}
if err := c.validateChassis(node); err != nil {
return err
}
if err := c.retryDelDupChassis(util.ChasRetryTime, util.ChasRetryIntev+2, c.checkChassisDupl, node); err != nil {
return err
Expand Down
18 changes: 7 additions & 11 deletions pkg/ovs/ovn-sbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ func (c LegacyClient) ovnSbCommand(cmdArgs ...string) (string, error) {
}

func (c LegacyClient) DeleteChassisByNode(node string) error {
output, err := c.ovnSbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=name", "find", "chassis", fmt.Sprintf("external_ids:node=%s", node))
chassis, err := c.GetChassis(node)
if err != nil {
return fmt.Errorf("failed to get node chassis %s, %v", node, err)
}
for _, chassis := range strings.Split(output, "\n") {
chassis = strings.TrimSpace(chassis)
if len(chassis) > 0 {
if err := c.DeleteChassisByName(chassis); err != nil {
return err
}
}
if chassis == "" {
return nil
}
return nil

return c.DeleteChassisByName(chassis)
}

func (c LegacyClient) DeleteChassisByName(chassisName string) error {
Expand All @@ -84,12 +80,12 @@ func (c LegacyClient) DeleteChassisByName(chassisName string) error {
}

func (c LegacyClient) GetChassis(node string) (string, error) {
output, err := c.ovnSbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=name", "find", "chassis", fmt.Sprintf("hostname=%s", node))
output, err := c.ovnSbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=name", "find", "chassis", fmt.Sprintf("external_ids:node=%s", node))
if err != nil {
return "", fmt.Errorf("failed to find node chassis %s, %v", node, err)
}
if len(output) == 0 {
output, err = c.ovnSbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=name", "find", "chassis", fmt.Sprintf("external_ids:node=%s", node))
output, err = c.ovnSbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=name", "find", "chassis", fmt.Sprintf("hostname=%s", node))
if err != nil {
return "", fmt.Errorf("failed to find node chassis %s, %v", node, err)
}
Expand Down

0 comments on commit d5d196e

Please sign in to comment.