Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the device spec file creation in rdma exclusive mode #611

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading