Skip to content

Commit

Permalink
Merge pull request #530 from almaslennikov/expose-rdma-devices
Browse files Browse the repository at this point in the history
Expose RDMA device name in the devicespec if available
  • Loading branch information
SchSeba authored Mar 7, 2024
2 parents 15ceeb3 + 21c36b7 commit 4a91d9e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/netdevice/netResourcePool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 16 additions & 2 deletions pkg/netdevice/netResourcePool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -113,26 +115,38 @@ 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).
Return(func(rName, id string, devInfo *nettypes.DeviceInfo) error {
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).
Return(func(rName, id string, devInfo *nettypes.DeviceInfo) error {
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)
Expand Down

0 comments on commit 4a91d9e

Please sign in to comment.