Skip to content

Commit

Permalink
fix near err
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed Apr 20, 2024
1 parent 708f9c5 commit cf5f324
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,26 @@ func configureGlobalMirror(portName string, mtu int) error {
}

if !nicExist {
klog.Infof("nic %s not exist, create it", portName)
raw, err := ovs.Exec(ovs.MayExist, "add-port", "br-int", portName, "--",
"set", "interface", portName, "type=internal", "--",
"clear", "bridge", "br-int", "mirrors", "--",
"--id=@mirror0", "get", "port", portName, "--",
"--id=@m", "create", "mirror", fmt.Sprintf("name=%s", util.MirrorDefaultName), "select_all=true", "output_port=@mirror0", "--",
"add", "bridge", "br-int", "mirrors", "@m")
if err != nil {
klog.Errorf("failed to configure mirror nic %s %q", portName, raw)
klog.Errorf("failed to configure mirror nic %s, %q, %v", portName, raw, err)
return fmt.Errorf(raw)
}
} else {
klog.Infof("nic %s exist, configure it", portName)
raw, err := ovs.Exec(ovs.MayExist, "add-port", "br-int", portName, "--",
"clear", "bridge", "br-int", "mirrors", "--",
"--id=@mirror0", "get", "port", portName, "--",
"--id=@m", "create", "mirror", fmt.Sprintf("name=%s", util.MirrorDefaultName), "select_all=true", "output_port=@mirror0", "--",
"add", "bridge", "br-int", "mirrors", "@m")
if err != nil {
klog.Errorf("failed to configure mirror nic %s %q", portName, raw)
klog.Errorf("failed to configure mirror nic %s, %q, %v", portName, raw, err)
return fmt.Errorf(raw)
}
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/daemon/ovs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,11 +917,13 @@ func (c *Controller) patchNodeExternalGwLabel(key string, enabled bool) error {
func configureMirrorLink(portName string, _ int) error {
mirrorLink, err := netlink.LinkByName(portName)
if err != nil {
klog.Error(err)
return fmt.Errorf("can not find mirror nic %s: %v", portName, err)
}

if mirrorLink.Attrs().OperState != netlink.OperUp {
if err = netlink.LinkSetUp(mirrorLink); err != nil {
klog.Error(err)
return fmt.Errorf("can not set mirror nic %s up: %v", portName, err)
}
}
Expand All @@ -932,10 +934,12 @@ func configureMirrorLink(portName string, _ int) error {
func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPConflict bool) error {
nodeLink, err := netlink.LinkByName(link)
if err != nil {
klog.Error(err)
return fmt.Errorf("can not find nic %s: %v", link, err)
}

if err = netlink.LinkSetHardwareAddr(nodeLink, macAddr); err != nil {
klog.Error(err)
return fmt.Errorf("can not set mac address to nic %s: %v", link, err)
}

Expand All @@ -952,6 +956,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo

if nodeLink.Attrs().OperState != netlink.OperUp {
if err = netlink.LinkSetUp(nodeLink); err != nil {
klog.Error(err)
return fmt.Errorf("can not set node nic %s up: %v", link, err)
}
}
Expand All @@ -960,6 +965,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
ipAddMap := make(map[string]netlink.Addr)
ipAddrs, err := netlink.AddrList(nodeLink, unix.AF_UNSPEC)
if err != nil {
klog.Error(err)
return fmt.Errorf("can not get addr %s: %v", nodeLink, err)
}
for _, ipAddr := range ipAddrs {
Expand Down Expand Up @@ -987,6 +993,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
for ip, addr := range ipDelMap {
klog.Infof("delete ip address %s on %s", ip, link)
if err = netlink.AddrDel(nodeLink, &addr); err != nil {
klog.Error(err)
return fmt.Errorf("delete address %s: %v", addr, err)
}
}
Expand All @@ -1012,6 +1019,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo

klog.Infof("add ip address %s to %s", ip, link)
if err = netlink.AddrAdd(nodeLink, &addr); err != nil {
klog.Error(err)
return fmt.Errorf("can not add address %v to nic %s: %v", addr, link, err)
}
}
Expand Down

0 comments on commit cf5f324

Please sign in to comment.