Skip to content

Commit

Permalink
fix: the vx-bridge-6 created in the online environment does not have …
Browse files Browse the repository at this point in the history
…an IP address

Signed-off-by: OrangeBao <[email protected]>
  • Loading branch information
OrangeBao committed Dec 27, 2023
1 parent ed1b248 commit 9dab29f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pkg/clusterlink/network/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"strings"
"syscall"
"time"

"github.com/pkg/errors"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -59,9 +60,9 @@ func createNewVxlanIface(name string, addrIPWithMask *netlink.Addr, vxlanId int,
klog.Infof("name %v ------------------------- %v", name, deviceIP)
iface := &netlink.Vxlan{
LinkAttrs: netlink.LinkAttrs{
Name: name,
MTU: rIface.MTU - vxlanOverhead,
Flags: net.FlagUp,
Name: name,
MTU: rIface.MTU - vxlanOverhead,
// Flags: net.FlagUp,
HardwareAddr: hardwareAddr,
},
SrcAddr: net.ParseIP(deviceIP),
Expand Down Expand Up @@ -94,12 +95,25 @@ func createNewVxlanIface(name string, addrIPWithMask *netlink.Addr, vxlanId int,

klog.Infof("name %v ------------------------- addrIPWithMask %v", name, addrIPWithMask)

err = netlink.AddrAdd(iface, addrIPWithMask)
link, err := netlink.LinkByName(name)
if err != nil {
fmt.Printf("get link by name err: %v\n", err)
panic(err)
}

err = netlink.AddrAdd(link, addrIPWithMask)
if err != nil {
klog.Errorf("Add address %v to vxlan interface,get error : %v", addrIPWithMask, err)
return err
}

time.Sleep(1 * time.Second)
err = netlink.LinkSetUp(link)
if err != nil {
klog.Errorf("set up device err: %v\n", err)
return err
}

return nil
}

Expand Down

0 comments on commit 9dab29f

Please sign in to comment.