Skip to content

Commit

Permalink
optimize log for node port-group
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Feb 16, 2022
1 parent 0869e62 commit 136aedf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ func (c *Controller) checkPodsChangedOnNode(pgName string, ports []string) (bool
return false, err
}

nameIdMap, err := c.ovnClient.ListLspForNodePortgroup()
nameIdMap, idNameMap, err := c.ovnClient.ListLspForNodePortgroup()
if err != nil {
klog.Errorf("failed to list lsp info, %v", err)
return false, err
Expand All @@ -828,14 +828,14 @@ func (c *Controller) checkPodsChangedOnNode(pgName string, ports []string) (bool

for _, portId := range portIds {
if !util.IsStringIn(portId, pgPorts) {
klog.Infof("new added pod %v should add to node port group %v", portId, pgName)
klog.Infof("pod on node changed, new added port %v should add to node port group %v", idNameMap[portId], pgName)
return true, nil
}
}

for _, pgPort := range pgPorts {
if !util.IsStringIn(pgPort, portIds) {
klog.Infof("can not find match pod for port %v in node port group %v", pgPort, pgName)
klog.Infof("pod on node changed, can not find match pod for port %v in node port group %v", pgPort, pgName)
return true, nil
}
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,14 +1300,15 @@ func (c Client) ListPgPorts(pgName string) ([]string, error) {
return result, nil
}

func (c Client) ListLspForNodePortgroup() (map[string]string, error) {
func (c Client) ListLspForNodePortgroup() (map[string]string, map[string]string, error) {
output, err := c.ovnNbCommand("--data=bare", "--format=csv", "--no-heading", "--columns=name,_uuid", "list", "logical_switch_port")
if err != nil {
klog.Errorf("failed to list logical-switch-port, %v", err)
return nil, err
return nil, nil, err
}
lines := strings.Split(output, "\n")
result := make(map[string]string, len(lines))
nameIdMap := make(map[string]string, len(lines))
idNameMap := make(map[string]string, len(lines))
for _, l := range lines {
if len(strings.TrimSpace(l)) == 0 {
continue
Expand All @@ -1318,9 +1319,10 @@ func (c Client) ListLspForNodePortgroup() (map[string]string, error) {
}
name := strings.TrimSpace(parts[0])
uuid := strings.TrimSpace(parts[1])
result[name] = uuid
nameIdMap[name] = uuid
idNameMap[uuid] = name
}
return result, nil
return nameIdMap, idNameMap, nil
}

func (c Client) SetPortsToPortGroup(portGroup string, portNames []string) error {
Expand Down

0 comments on commit 136aedf

Please sign in to comment.