Skip to content

Commit

Permalink
ensure address label is correct before deleting it (#2487)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Mar 16, 2023
1 parent df493a8 commit d70bf21
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/daemon/ovs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,15 @@ func configProviderNic(nicName, brName string) (int, error) {
continue
}

if !strings.HasPrefix(addr.Label, nicName) {
if strings.HasPrefix(addr.Label, brName) {
addr.Label = nicName + addr.Label[len(brName):]
} else {
addr.Label = nicName
}
}
if err = netlink.AddrDel(nic, &addr); err != nil {
errMsg := fmt.Errorf("failed to delete address %s on nic %s: %v", addr.String(), nicName, err)
errMsg := fmt.Errorf("failed to delete address %q on nic %s: %v", addr.String(), nicName, err)
if errors.Is(err, syscall.EADDRNOTAVAIL) {
// the IP address does not exist now
klog.Warning(errMsg)
Expand All @@ -605,10 +612,10 @@ func configProviderNic(nicName, brName string) (int, error) {
}

if addr.Label != "" {
addr.Label = brName + strings.TrimPrefix(addr.Label, nicName)
addr.Label = brName + addr.Label[len(nicName):]
}
if err = netlink.AddrReplace(bridge, &addr); err != nil {
return 0, fmt.Errorf("failed to replace address %s on OVS bridge %s: %v", addr.String(), brName, err)
return 0, fmt.Errorf("failed to replace address %q on OVS bridge %s: %v", addr.String(), brName, err)
}
}

Expand Down

0 comments on commit d70bf21

Please sign in to comment.