Skip to content

Commit

Permalink
fix network break on kube-ovn-cni startup (#2272)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Jan 29, 2023
1 parent 4a8997b commit 63dc62a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/containernetworking/plugins/pkg/utils/sysctl"
goping "github.com/oilbeater/go-ping"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
"k8s.io/klog/v2"

kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
Expand Down Expand Up @@ -491,7 +492,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo

ipDelMap := make(map[string]netlink.Addr)
ipAddMap := make(map[string]netlink.Addr)
ipAddrs, err := netlink.AddrList(nodeLink, 0x0)
ipAddrs, err := netlink.AddrList(nodeLink, unix.AF_UNSPEC)
if err != nil {
return fmt.Errorf("can not get addr %s: %v", nodeLink, err)
}
Expand All @@ -500,7 +501,7 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
// skip 169.254.0.0/16 and fe80::/10
continue
}
ipDelMap[ipAddr.IP.String()+"/"+ipAddr.Mask.String()] = ipAddr
ipDelMap[ipAddr.IPNet.String()] = ipAddr
}

for _, ipStr := range strings.Split(ip, ",") {
Expand All @@ -517,12 +518,13 @@ func configureNic(link, ip string, macAddr net.HardwareAddr, mtu int, detectIPCo
ipAddMap[ipStr] = *ipAddr
}

for _, addr := range ipDelMap {
for ip, addr := range ipDelMap {
klog.Infof("delete ip address %s on %s", ip, link)
if err = netlink.AddrDel(nodeLink, &addr); err != nil {
return fmt.Errorf("delete address %s: %v", addr, err)
}
}
for _, addr := range ipAddMap {
for ip, addr := range ipAddMap {
if detectIPConflict && addr.IP.To4() != nil {
ip := addr.IP.String()
mac, err := util.ArpDetectIPConflict(link, ip, macAddr)
Expand All @@ -536,6 +538,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 {
return fmt.Errorf("can not add address %v to nic %s: %v", addr, link, err)
}
Expand Down Expand Up @@ -1018,7 +1021,7 @@ func configureAdditionalNic(link, ip string) error {
// skip 169.254.0.0/16 and fe80::/10
continue
}
ipDelMap[ipAddr.IP.String()+"/"+ipAddr.Mask.String()] = ipAddr
ipDelMap[ipAddr.IPNet.String()] = ipAddr
}

for _, ipStr := range strings.Split(ip, ",") {
Expand Down

0 comments on commit 63dc62a

Please sign in to comment.