Skip to content

Commit

Permalink
get all chassis once (#3103)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobz965 committed Aug 3, 2023
1 parent 42e0574 commit 914bf61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
35 changes: 16 additions & 19 deletions pkg/controller/init.go
Expand Up @@ -855,31 +855,28 @@ func (c *Controller) initNodeChassis() error {
klog.Errorf("failed to list nodes: %v", err)
return err
}

chssisNodes, err := c.ovnLegacyClient.GetAllChassisMap()
if err != nil {
klog.Errorf("failed to get chassis nodes: %v", err)
return err
}
for _, node := range nodes {
chassisName := node.Annotations[util.ChassisAnnotation]
if chassisName != "" {
existChasisId, err := c.ovnLegacyClient.GetChassis(node.Name)
if err != nil {
klog.Errorf("failed to get chassis id: %v", err)
return err
}
if existChasisId == chassisName {
continue
}
exist, err := c.ovnLegacyClient.ChassisExist(chassisName)
if err != nil {
klog.Errorf("failed to check chassis exist: %v", err)
return err
}
if exist {
err = c.ovnLegacyClient.InitChassisNodeTag(chassisName, node.Name)
if err != nil {
klog.Errorf("failed to set chassis nodeTag: %v", err)
return err
if hostname, exist := chssisNodes[chassisName]; exist {
if hostname == node.Name {
continue
} else {
klog.Infof("node %s sbdb chassis %s host name %s", node.Name, chassisName, hostname)
err = c.ovnLegacyClient.InitChassisNodeTag(chassisName, node.Name)
if err != nil {
klog.Errorf("failed to set chassis nodeTag: %v", err)
return err
}
}
}
}
}

return nil
}
20 changes: 20 additions & 0 deletions pkg/ovs/ovn-sbctl.go
Expand Up @@ -151,3 +151,23 @@ func (c LegacyClient) GetAllChassis() ([]string, error) {
}
return result, nil
}

// GetAllChassisMap return a map of chassis uuid : node name
func (c LegacyClient) GetAllChassisMap() (map[string]string, error) {
output, err := c.ovnSbCommand("--format=csv", "--no-heading", "--data=bare", "--columns=name,hostname", "find", "chassis", fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName))
if err != nil {
return nil, fmt.Errorf("failed to find node chassis, %v", err)
}
lines := strings.Split(output, "\n")
result := make(map[string]string, len(lines))
for _, l := range lines {
if len(strings.TrimSpace(l)) == 0 {
continue
}
res := strings.Split(l, ",")
if len(res) == 2 {
result[res[0]] = res[1]
}
}
return result, nil
}

0 comments on commit 914bf61

Please sign in to comment.