Skip to content

Commit 3631e4e

Browse files
committed
ensure address label is correct before deleting it (#2487)
1 parent 5ffc237 commit 3631e4e

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
@@ -576,8 +576,15 @@ func configProviderNic(nicName, brName string) (int, error) {
576576
continue
577577
}
578578

579+
if !strings.HasPrefix(addr.Label, nicName) {
580+
if strings.HasPrefix(addr.Label, brName) {
581+
addr.Label = nicName + addr.Label[len(brName):]
582+
} else {
583+
addr.Label = nicName
584+
}
585+
}
579586
if err = netlink.AddrDel(nic, &addr); err != nil {
580-
errMsg := fmt.Errorf("failed to delete address %s on nic %s: %v", addr.String(), nicName, err)
587+
errMsg := fmt.Errorf("failed to delete address %q on nic %s: %v", addr.String(), nicName, err)
581588
if errors.Is(err, syscall.EADDRNOTAVAIL) {
582589
// the IP address does not exist now
583590
klog.Warning(errMsg)
@@ -587,10 +594,10 @@ func configProviderNic(nicName, brName string) (int, error) {
587594
}
588595

589596
if addr.Label != "" {
590-
addr.Label = brName + strings.TrimPrefix(addr.Label, nicName)
597+
addr.Label = brName + addr.Label[len(nicName):]
591598
}
592599
if err = netlink.AddrReplace(bridge, &addr); err != nil {
593-
return 0, fmt.Errorf("failed to replace address %s on OVS bridge %s: %v", addr.String(), brName, err)
600+
return 0, fmt.Errorf("failed to replace address %q on OVS bridge %s: %v", addr.String(), brName, err)
594601
}
595602
}
596603

0 commit comments

Comments
 (0)