Skip to content

Commit

Permalink
Merge pull request #611 from SchSeba/fix_device_spec_rdma
Browse files Browse the repository at this point in the history
Fix the device spec file creation in rdma exclusive mode
  • Loading branch information
zeeke authored Dec 9, 2024
2 parents a380ca5 + d7bd803 commit b3c1cda
Show file tree
Hide file tree
Showing 29 changed files with 98 additions and 84 deletions.
2 changes: 1 addition & 1 deletion pkg/cdi/mocks/CDI.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/infoprovider/rdmaInfoProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (ip *rdmaInfoProvider) GetDeviceSpecs() []*pluginapi.DeviceSpec {
}

devsSpec := ip.rdmaSpec.GetRdmaDeviceSpec()
glog.Infof("GetDeviceSpecs(): GetRdmaDeviceSpec returned %v", devsSpec)
return devsSpec
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/netdevice/netResourcePool.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ func (rp *netResourcePool) GetDeviceSpecs(deviceIDs []string) []*pluginapi.Devic

// StoreDeviceInfoFile stores the Device Info files according to the
// k8snetworkplumbingwg/device-info-spec
func (rp *netResourcePool) StoreDeviceInfoFile(resourceNamePrefix string) error {
// for the requested deviceIDs
func (rp *netResourcePool) StoreDeviceInfoFile(resourceNamePrefix string, deviceIDs []string) error {
var devInfo nettypes.DeviceInfo
for id, dev := range rp.GetDevicePool() {
devicePool := rp.GetDevicePool()

for _, id := range deviceIDs {
dev := devicePool[id]
netDev, ok := dev.(types.PciNetDevice)
if !ok {
return fmt.Errorf("storeDeviceInfoFile: Only pciNetDevices are supported")
Expand Down
4 changes: 2 additions & 2 deletions pkg/netdevice/netResourcePool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var _ = Describe("NetResourcePool", func() {
return nil
})
rp := netdevice.NewNetResourcePool(nadutils, rc, pcis)
err := rp.StoreDeviceInfoFile("fakeOrg.io")
err := rp.StoreDeviceInfoFile("fakeOrg.io", []string{"fake1", "fake2"})
nadutils.AssertExpectations(t)
Expect(err).ToNot(HaveOccurred())
})
Expand Down Expand Up @@ -217,7 +217,7 @@ var _ = Describe("NetResourcePool", func() {
return nil
})
rp := netdevice.NewNetResourcePool(nadutils, rc, pcis)
err := rp.StoreDeviceInfoFile("fakeOrg.io")
err := rp.StoreDeviceInfoFile("fakeOrg.io", []string{"fake1", "fake2"})
Expect(err).ToNot(HaveOccurred())
nadutils.AssertExpectations(t)
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/pool_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (rp *ResourcePoolImpl) GetDevicePool() map[string]types.HostDevice {

// StoreDeviceInfoFile does nothing. DeviceType-specific ResourcePools might
// store information according to the k8snetworkplumbingwg/device-info-spec
func (rp *ResourcePoolImpl) StoreDeviceInfoFile(resourceNamePrefix string) error {
func (rp *ResourcePoolImpl) StoreDeviceInfoFile(resourceNamePrefix string, deviceIDs []string) error {
return nil
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/resources/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ func (rs *resourceServer) Allocate(ctx context.Context, rqt *pluginapi.AllocateR
containerResp.Mounts = rs.resourcePool.GetMounts(container.DevicesIDs)
}

err = rs.resourcePool.StoreDeviceInfoFile(rs.resourceNamePrefix, container.DevicesIDs)
if err != nil {
glog.Errorf("failed to store device info file for device IDs %v: %v", container.DevicesIDs, err)
return nil, err
}

containerResp.Envs = envs
resp.ContainerResponses = append(resp.ContainerResponses, containerResp)
}
Expand Down Expand Up @@ -247,10 +253,6 @@ func (rs *resourceServer) Start() error {
resourceName := rs.resourcePool.GetResourceName()
_ = rs.cleanUp() // try tp clean up and continue

if err := rs.resourcePool.StoreDeviceInfoFile(rs.resourceNamePrefix); err != nil {
glog.Errorf("%s: error creating DeviceInfo File: %s", rs.resourcePool.GetResourceName(), err.Error())
}

glog.Infof("starting %s device plugin endpoint at: %s\n", resourceName, rs.endPoint)
lis, err := net.Listen(unix, rs.sockPath)
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions pkg/resources/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var _ = Describe("Server", func() {
rp := mocks.ResourcePool{}
rp.On("Probe").Return(false)
rp.On("GetResourceName").Return("fakename")
rp.On("StoreDeviceInfoFile", "fakeprefix").Return(nil)
rp.On("CleanDeviceInfoFile", "fakeprefix").Return(nil)

// Use faked dir as socket dir
Expand All @@ -78,7 +77,6 @@ var _ = Describe("Server", func() {
if shouldEnablePluginWatch {
_ = rs.Start()
rp.AssertCalled(t, "CleanDeviceInfoFile", "fakeprefix")
rp.AssertCalled(t, "StoreDeviceInfoFile", "fakeprefix")
} else {
_ = os.MkdirAll(pluginapi.DevicePluginPath, 0755)
registrationServer.start()
Expand Down Expand Up @@ -153,7 +151,6 @@ var _ = Describe("Server", func() {
On("DiscoverDevices").Return(nil).
On("GetDevices").Return(map[string]*pluginapi.Device{}).
On("Probe").Return(true).
On("StoreDeviceInfoFile", "fake").Return(nil).
On("CleanDeviceInfoFile", "fake").Return(nil)

// Create ResourceServer with plugin watch mode disabled
Expand Down Expand Up @@ -195,7 +192,6 @@ var _ = Describe("Server", func() {
On("DiscoverDevices").Return(nil).
On("GetDevices").Return(map[string]*pluginapi.Device{}).
On("Probe").Return(true).
On("StoreDeviceInfoFile", "fake").Return(nil).
On("CleanDeviceInfoFile", "fake").Return(nil)
// Create ResourceServer with plugin watch mode enabled
rs := NewResourceServer("fake", "fake", true, false, &rp).(*resourceServer)
Expand Down Expand Up @@ -230,7 +226,6 @@ var _ = Describe("Server", func() {
On("DiscoverDevices").Return(nil).
On("GetDevices").Return(map[string]*pluginapi.Device{}).
On("Probe").Return(true).
On("StoreDeviceInfoFile", "fake").Return(nil).
On("CleanDeviceInfoFile", "fake").Return(nil)

// Create ResourceServer with plugin watch mode disabled
Expand Down Expand Up @@ -274,7 +269,9 @@ var _ = Describe("Server", func() {
On("GetEnvs", "fake.com", []string{"00:00.01"}).
Return(map[string]string{"PCIDEVICE_FAKE_COM_FAKE_INFO": "{\"00:00.01\":{\"netdevice\":{\"pci\":\"00:00.01\"}}}"}, nil).
On("GetMounts", []string{"00:00.01"}).
Return([]*pluginapi.Mount{{ContainerPath: "/dev/fake", HostPath: "/dev/fake", ReadOnly: false}})
Return([]*pluginapi.Mount{{ContainerPath: "/dev/fake", HostPath: "/dev/fake", ReadOnly: false}}).
On("StoreDeviceInfoFile", "fake.com", []string{"00:00.01"}).
Return(nil)

rs := NewResourceServer("fake.com", "fake", true, false, &rp).(*resourceServer)

Expand Down Expand Up @@ -318,7 +315,9 @@ var _ = Describe("Server", func() {
On("GetMounts", []string{"00:00.01"}).
Return([]*pluginapi.Mount{{ContainerPath: "/dev/fake", HostPath: "/dev/fake", ReadOnly: false}}).
On("GetCDIName").
Return("fake.com")
Return("fake.com").
On("StoreDeviceInfoFile", "fake.com", []string{"00:00.01"}).
Return(nil)

rs := NewResourceServer("fake.com", "fake", true, true, &rp).(*resourceServer)

Expand Down
2 changes: 1 addition & 1 deletion pkg/types/mocks/APIDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/AccelDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/AuxNetDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/DeviceInfoProvider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/DeviceProvider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/DeviceSelector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/HostDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/LinkWatcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/NadUtils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/NetDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/PciDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions pkg/types/mocks/PciNetDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/RdmaSpec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/ResourceFactory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/types/mocks/ResourcePool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/ResourceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/mocks/VdpaDevice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ type ResourcePool interface {
GetDeviceSpecs(deviceIDs []string) []*pluginapi.DeviceSpec
GetEnvs(prefix string, deviceIDs []string) (map[string]string, error)
GetMounts(deviceIDs []string) []*pluginapi.Mount
StoreDeviceInfoFile(resourceNamePrefix string) error
StoreDeviceInfoFile(resourceNamePrefix string, deviceIDs []string) error
CleanDeviceInfoFile(resourceNamePrefix string) error
GetCDIName() string
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/mocks/NetlinkProvider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/utils/mocks/RdmaProvider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b3c1cda

Please sign in to comment.