diff --git a/pkg/factory/factory.go b/pkg/factory/factory.go index fbe94de41..13e2463b9 100644 --- a/pkg/factory/factory.go +++ b/pkg/factory/factory.go @@ -118,7 +118,8 @@ func (rf *resourceFactory) GetResourcePool(rc *types.ResourceConfig, filteredDev case types.NetDeviceType: if len(filteredDevice) > 0 { if _, ok := filteredDevice[0].(types.PciNetDevice); ok { - rPool = netdevice.NewNetResourcePool(rc, apiDevices, devicePool) + nadUtils := rf.GetNadUtils() + rPool = netdevice.NewNetResourcePool(nadUtils, rc, apiDevices, devicePool) } else { err = fmt.Errorf("invalid device list for NetDeviceType") } diff --git a/pkg/netdevice/netResourcePool.go b/pkg/netdevice/netResourcePool.go index 778850a27..6b05484c9 100644 --- a/pkg/netdevice/netResourcePool.go +++ b/pkg/netdevice/netResourcePool.go @@ -20,7 +20,6 @@ import ( "strings" nettypes "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" - nadutils "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/utils" pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1" "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/resources" @@ -30,17 +29,19 @@ import ( type netResourcePool struct { *resources.ResourcePoolImpl selectors *types.NetDeviceSelectors + nadutils types.NadUtils } var _ types.ResourcePool = &netResourcePool{} // NewNetResourcePool returns an instance of resourcePool -func NewNetResourcePool(rc *types.ResourceConfig, apiDevices map[string]*pluginapi.Device, devicePool map[string]types.PciDevice) types.ResourcePool { +func NewNetResourcePool(nadutils types.NadUtils, rc *types.ResourceConfig, apiDevices map[string]*pluginapi.Device, devicePool map[string]types.PciDevice) types.ResourcePool { rp := resources.NewResourcePool(rc, apiDevices, devicePool) s, _ := rc.SelectorObj.(*types.NetDeviceSelectors) return &netResourcePool{ ResourcePoolImpl: rp, selectors: s, + nadutils: nadutils, } } @@ -101,7 +102,7 @@ func (rp *netResourcePool) StoreDeviceInfoFile(resourceNamePrefix string) error }, } resource := fmt.Sprintf("%s/%s", resourceNamePrefix, rp.GetConfig().ResourceName) - if err := nadutils.SaveDeviceInfoForDP(resource, id, &devInfo); err != nil { + if err := rp.nadutils.SaveDeviceInfoFile(resource, id, &devInfo); err != nil { return err } } @@ -113,7 +114,7 @@ func (rp *netResourcePool) CleanDeviceInfoFile(resourceNamePrefix string) error errors := make([]string, 0) for id := range rp.GetDevicePool() { resource := fmt.Sprintf("%s/%s", resourceNamePrefix, rp.GetConfig().ResourceName) - if err := nadutils.CleanDeviceInfoForDP(resource, id); err != nil { + if err := rp.nadutils.CleanDeviceInfoFile(resource, id); err != nil { // Continue trying to clean. errors = append(errors, err.Error()) } diff --git a/pkg/netdevice/netResourcePool_test.go b/pkg/netdevice/netResourcePool_test.go index 1e64d3c0b..fbbd72fa5 100644 --- a/pkg/netdevice/netResourcePool_test.go +++ b/pkg/netdevice/netResourcePool_test.go @@ -15,6 +15,7 @@ package netdevice_test import ( + "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/factory" "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" @@ -27,6 +28,8 @@ import ( var _ = Describe("NetResourcePool", func() { Context("getting a new instance of the pool", func() { + rf := factory.NewResourceFactory("fake", "fake", true) + nadutils := rf.GetNadUtils() rc := &types.ResourceConfig{ ResourceName: "fake", ResourcePrefix: "fake", @@ -35,7 +38,7 @@ var _ = Describe("NetResourcePool", func() { devs := map[string]*v1beta1.Device{} pcis := map[string]types.PciDevice{} - rp := netdevice.NewNetResourcePool(rc, devs, pcis) + rp := netdevice.NewNetResourcePool(nadutils, rc, devs, pcis) It("should return a valid instance of the pool", func() { Expect(rp).ToNot(BeNil()) @@ -43,6 +46,8 @@ var _ = Describe("NetResourcePool", func() { }) Describe("getting DeviceSpecs", func() { Context("for non-RDMA devices", func() { + rf := factory.NewResourceFactory("fake", "fake", true) + nadutils := rf.GetNadUtils() rc := &types.ResourceConfig{ ResourceName: "fake", ResourcePrefix: "fake", @@ -78,7 +83,7 @@ var _ = Describe("NetResourcePool", func() { pcis := map[string]types.PciDevice{"fake1": fake1, "fake2": fake2, "fake3": fake3} - rp := netdevice.NewNetResourcePool(rc, devs, pcis) + rp := netdevice.NewNetResourcePool(nadutils, rc, devs, pcis) devIDs := []string{"fake1", "fake2"} @@ -93,6 +98,8 @@ var _ = Describe("NetResourcePool", func() { }) }) Context("for RDMA devices", func() { + rf := factory.NewResourceFactory("fake", "fake", true) + nadutils := rf.GetNadUtils() rc := &types.ResourceConfig{ ResourceName: "fake", ResourcePrefix: "fake", @@ -123,7 +130,7 @@ var _ = Describe("NetResourcePool", func() { pcis := map[string]types.PciDevice{"fake1": fake1, "fake2": fake2} - rp := netdevice.NewNetResourcePool(rc, devs, pcis) + rp := netdevice.NewNetResourcePool(nadutils, rc, devs, pcis) devIDs := []string{"fake1", "fake2"}