diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 81bcf70f3..1cffca17c 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -10,6 +10,8 @@ import ( "strconv" "strings" "time" + + "github.com/k8snetworkplumbingwg/sriov-cni/pkg/logging" ) var ( @@ -310,21 +312,23 @@ func SetVFEffectiveMAC(netLinkManager NetlinkManager, netDeviceName string, macA return err } - return Retry(20, 100*time.Millisecond, func() error { - if err := netLinkManager.LinkSetHardwareAddr(orgLinkObj, hwaddr); err != nil { - return err - } + return Retry(20, 100*time.Millisecond, warnOnError( + "SetVFEffectiveMAC", + func() error { + if err := netLinkManager.LinkSetHardwareAddr(orgLinkObj, hwaddr); err != nil { + return err + } - linkObj, err := netLinkManager.LinkByName(netDeviceName) - if err != nil { - return fmt.Errorf("failed to get netlink device with name %s: %q", orgLinkObj.Attrs().Name, err) - } - if linkObj.Attrs().HardwareAddr.String() != macAddress { - return fmt.Errorf("effective mac address is different from requested one") - } + linkObj, err := netLinkManager.LinkByName(netDeviceName) + if err != nil { + return fmt.Errorf("failed to get netlink device with name %s: %q", orgLinkObj.Attrs().Name, err) + } + if linkObj.Attrs().HardwareAddr.String() != macAddress { + return fmt.Errorf("effective mac address is different from requested one") + } - return nil - }) + return nil + })) } // SetVFHardwareMAC will try to set the hardware mac address on a specific VF ID under a requested PF @@ -344,21 +348,22 @@ func SetVFHardwareMAC(netLinkManager NetlinkManager, pfDevice string, vfID int, return err } - return Retry(20, 100*time.Millisecond, func() error { - if err := netLinkManager.LinkSetVfHardwareAddr(orgLinkObj, vfID, hwaddr); err != nil { - return err - } + return Retry(20, 100*time.Millisecond, warnOnError("SetVFHardwareMAC", + func() error { + if err := netLinkManager.LinkSetVfHardwareAddr(orgLinkObj, vfID, hwaddr); err != nil { + return err + } - linkObj, err := netLinkManager.LinkByName(pfDevice) - if err != nil { - return fmt.Errorf("failed to get netlink device with name %s: %q", orgLinkObj.Attrs().Name, err) - } - if linkObj.Attrs().Vfs[vfID].Mac.String() != macAddress { - return fmt.Errorf("hardware mac address is different from requested one") - } + linkObj, err := netLinkManager.LinkByName(pfDevice) + if err != nil { + return fmt.Errorf("failed to get netlink device with name %s: %q", orgLinkObj.Attrs().Name, err) + } + if linkObj.Attrs().Vfs[vfID].Mac.String() != macAddress { + return fmt.Errorf("hardware mac address is different from requested one") + } - return nil - }) + return nil + })) } // IsValidMACAddress checks if net.HardwareAddr is a valid MAC address. @@ -402,3 +407,15 @@ func Retry(retries int, sleep time.Duration, f func() error) error { } return err } + +func warnOnError(callerFn string, f func() error) func() error { + return func() error { + err := f() + if err != nil { + logging.Warning("Delegated function error", + "func", callerFn, + "error", err) + } + return err + } +}