Skip to content

Commit d70bf21

Browse files
committed
ensure address label is correct before deleting it (#2487)
1 parent df493a8 commit d70bf21

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/daemon/ovs_linux.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,15 @@ func configProviderNic(nicName, brName string) (int, error) {
594594
continue
595595
}
596596

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

607614
if addr.Label != "" {
608-
addr.Label = brName + strings.TrimPrefix(addr.Label, nicName)
615+
addr.Label = brName + addr.Label[len(nicName):]
609616
}
610617
if err = netlink.AddrReplace(bridge, &addr); err != nil {
611-
return 0, fmt.Errorf("failed to replace address %s on OVS bridge %s: %v", addr.String(), brName, err)
618+
return 0, fmt.Errorf("failed to replace address %q on OVS bridge %s: %v", addr.String(), brName, err)
612619
}
613620
}
614621

0 commit comments

Comments
 (0)