From 21c36b76ae96fb929ac2d93b9856cf19f1f3adaa Mon Sep 17 00:00:00 2001 From: amaslennikov Date: Wed, 7 Feb 2024 11:25:03 +0300 Subject: [PATCH] Expose RDMA device name in the devicespec if available Signed-off-by: amaslennikov --- pkg/netdevice/netResourcePool.go | 10 ++++++++++ pkg/netdevice/netResourcePool_test.go | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/netdevice/netResourcePool.go b/pkg/netdevice/netResourcePool.go index 7375b5ec9..f46297fd8 100644 --- a/pkg/netdevice/netResourcePool.go +++ b/pkg/netdevice/netResourcePool.go @@ -24,6 +24,7 @@ import ( "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/resources" "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types" + "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils" ) type netResourcePool struct { @@ -113,6 +114,15 @@ func (rp *netResourcePool) StoreDeviceInfoFile(resourceNamePrefix string) error PciAddress: netDev.GetPciAddr(), }, } + + if netDev.IsRdma() { + rdmaDevices := utils.GetRdmaProvider().GetRdmaDevicesForPcidev(devInfo.Pci.PciAddress) + if len(rdmaDevices) == 0 { + glog.Errorf("No RDMA devices available for RDMA capable device: %s", devInfo.Pci.PciAddress) + } else { + devInfo.Pci.RdmaDevice = strings.Join(rdmaDevices, ",") + } + } } resource := fmt.Sprintf("%s/%s", resourceNamePrefix, rp.GetConfig().ResourceName) if err := rp.nadutils.SaveDeviceInfoFile(resource, id, &devInfo); err != nil { diff --git a/pkg/netdevice/netResourcePool_test.go b/pkg/netdevice/netResourcePool_test.go index f9cce0a6f..5c0c0ce6e 100644 --- a/pkg/netdevice/netResourcePool_test.go +++ b/pkg/netdevice/netResourcePool_test.go @@ -24,6 +24,8 @@ import ( "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/netdevice" "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types" "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types/mocks" + "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils" + utilsmocks "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils/mocks" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -113,12 +115,18 @@ var _ = Describe("NetResourcePool", func() { fake1 := &mocks.PciNetDevice{} fake1.On("GetPciAddr").Return("0000:01:00.1"). - On("GetVdpaDevice").Return(nil) + On("GetVdpaDevice").Return(nil). + On("IsRdma").Return(true) fake2 := &mocks.PciNetDevice{} fake2.On("GetPciAddr").Return("0000:01:00.2"). - On("GetVdpaDevice").Return(nil) + On("GetVdpaDevice").Return(nil). + On("IsRdma").Return(false) pcis := map[string]types.HostDevice{"fake1": fake1, "fake2": fake2} + fakeRdmaProvider := utilsmocks.RdmaProvider{} + fakeRdmaProvider.On("GetRdmaDevicesForPcidev", "0000:01:00.1").Return([]string{"rdmadevice1"}) + utils.SetRdmaProviderInst(&fakeRdmaProvider) + It("should call nadutils to create a well formatted DeviceInfo object", func() { nadutils := &mocks.NadUtils{} nadutils.On("SaveDeviceInfoFile", "fakeOrg.io/fakeResource", "fake1", Anything). @@ -126,6 +134,9 @@ var _ = Describe("NetResourcePool", func() { if devInfo.Type != nettypes.DeviceInfoTypePCI || devInfo.Pci == nil || devInfo.Pci.PciAddress != "0000:01:00.1" { return fmt.Errorf("wrong device info") } + if devInfo.Pci.RdmaDevice != "rdmadevice1" { + return fmt.Errorf("wrong rdma device") + } return nil }) nadutils.On("SaveDeviceInfoFile", "fakeOrg.io/fakeResource", "fake2", Anything). @@ -133,6 +144,9 @@ var _ = Describe("NetResourcePool", func() { if devInfo.Type != nettypes.DeviceInfoTypePCI || devInfo.Pci == nil || devInfo.Pci.PciAddress != "0000:01:00.2" { return fmt.Errorf("wrong device info") } + if devInfo.Pci.RdmaDevice != "" { + return fmt.Errorf("wrong rdma device") + } return nil }) rp := netdevice.NewNetResourcePool(nadutils, rc, pcis)