From c92f7ac6f540473d4d6063904e5101773a9818b3 Mon Sep 17 00:00:00 2001 From: amaslennikov Date: Thu, 13 Apr 2023 11:48:07 +0300 Subject: [PATCH] Derive link type from PF if the interface name is not available In case a workload is already consuming a VF and sriov-device-plugin is restarted, when this selector is specified, the device plugin will fail to get the VF link type since getting this information requires the VF netdev. The netdev does not exist in the host namespace as its assigned to pod. this causes sriov-network-device-plugin to fail adding this VF to resource pool, causing it to report the wrong number of resources. To fix this, derive the link type of the device from its PF, if the netdev itself is not available. Signed-off-by: amaslennikov --- pkg/devices/gen_net.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/devices/gen_net.go b/pkg/devices/gen_net.go index cc4df0782..e92b94d61 100644 --- a/pkg/devices/gen_net.go +++ b/pkg/devices/gen_net.go @@ -45,7 +45,7 @@ func NewGenNetDevice(deviceID string, dt types.DeviceType, isRdma bool) (*GenNet var funcID int var err error - //nolint: exhaustive + // nolint: exhaustive switch dt { case types.NetDeviceType: if pfName, err = utils.GetPfName(deviceID); err != nil { @@ -82,8 +82,13 @@ func NewGenNetDevice(deviceID string, dt types.DeviceType, isRdma bool) (*GenNet } linkType := "" - if len(ifName) > 0 { - la, err := utils.GetNetlinkProvider().GetLinkAttrs(ifName) + linkTypeProviderDevice := ifName + // If interface name is not available, derive link type from PF + if linkTypeProviderDevice == "" { + linkTypeProviderDevice = pfName + } + if linkTypeProviderDevice != "" { + la, err := utils.GetNetlinkProvider().GetLinkAttrs(linkTypeProviderDevice) if err != nil { return nil, err }