mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
gpu: add log messages for not found cards
Let a user know the plugin can't find any Intel GPU if that's the case. It might be cumbersome to realize that the plugin runs on a host which doesn't have any Intel GPUs. Also make the code less nested for better readability.
This commit is contained in:
parent
b504c6b30e
commit
44ff734be6
@ -85,50 +85,56 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
|||||||
|
|
||||||
devTree := dpapi.NewDeviceTree()
|
devTree := dpapi.NewDeviceTree()
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if dp.gpuDeviceReg.MatchString(f.Name()) {
|
var nodes []pluginapi.DeviceSpec
|
||||||
dat, err := ioutil.ReadFile(path.Join(dp.sysfsDir, f.Name(), "device/vendor"))
|
|
||||||
if err != nil {
|
if !dp.gpuDeviceReg.MatchString(f.Name()) {
|
||||||
fmt.Println("WARNING: Skipping. Can't read vendor file: ", err)
|
debug.Print("Not compatible device", f.Name())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dat, err := ioutil.ReadFile(path.Join(dp.sysfsDir, f.Name(), "device/vendor"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("WARNING: Skipping. Can't read vendor file: ", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(string(dat)) != vendorString {
|
||||||
|
debug.Print("Non-Intel GPU", f.Name())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
drmFiles, err := ioutil.ReadDir(path.Join(dp.sysfsDir, f.Name(), "device/drm"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "Can't read device folder")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, drmFile := range drmFiles {
|
||||||
|
if dp.controlDeviceReg.MatchString(drmFile.Name()) {
|
||||||
|
//Skipping possible drm control node
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
devPath := path.Join(dp.devfsDir, drmFile.Name())
|
||||||
|
if _, err := os.Stat(devPath); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.TrimSpace(string(dat)) == vendorString {
|
debug.Printf("Adding %s to GPU %s", devPath, f.Name())
|
||||||
var nodes []pluginapi.DeviceSpec
|
nodes = append(nodes, pluginapi.DeviceSpec{
|
||||||
|
HostPath: devPath,
|
||||||
|
ContainerPath: devPath,
|
||||||
|
Permissions: "rw",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
drmFiles, err := ioutil.ReadDir(path.Join(dp.sysfsDir, f.Name(), "device/drm"))
|
if len(nodes) > 0 {
|
||||||
if err != nil {
|
for i := 0; i < dp.sharedDevNum; i++ {
|
||||||
return nil, errors.Wrap(err, "Can't read device folder")
|
devID := fmt.Sprintf("%s-%d", f.Name(), i)
|
||||||
}
|
// Currently only one device type (i915) is supported.
|
||||||
|
// TODO: check model ID to differentiate device models.
|
||||||
for _, drmFile := range drmFiles {
|
devTree.AddDevice(deviceType, devID, dpapi.DeviceInfo{
|
||||||
if dp.controlDeviceReg.MatchString(drmFile.Name()) {
|
State: pluginapi.Healthy,
|
||||||
//Skipping possible drm control node
|
Nodes: nodes,
|
||||||
continue
|
})
|
||||||
}
|
|
||||||
devPath := path.Join(dp.devfsDir, drmFile.Name())
|
|
||||||
if _, err := os.Stat(devPath); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
debug.Printf("Adding %s to GPU %s", devPath, f.Name())
|
|
||||||
nodes = append(nodes, pluginapi.DeviceSpec{
|
|
||||||
HostPath: devPath,
|
|
||||||
ContainerPath: devPath,
|
|
||||||
Permissions: "rw",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(nodes) > 0 {
|
|
||||||
for i := 0; i < dp.sharedDevNum; i++ {
|
|
||||||
devID := fmt.Sprintf("%s-%d", f.Name(), i)
|
|
||||||
// Currently only one device type (i915) is supported.
|
|
||||||
// TODO: check model ID to differentiate device models.
|
|
||||||
devTree.AddDevice(deviceType, devID, dpapi.DeviceInfo{
|
|
||||||
State: pluginapi.Healthy,
|
|
||||||
Nodes: nodes,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,20 @@ func TestScan(t *testing.T) {
|
|||||||
expectedDevs: 1,
|
expectedDevs: 1,
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sysfsdirs: []string{"card0/device/drm/card0"},
|
||||||
|
sysfsfiles: map[string][]byte{
|
||||||
|
"card0/device/vendor": []byte("0xbeef"),
|
||||||
|
},
|
||||||
|
devfsdirs: []string{"card0"},
|
||||||
|
expectedDevs: 0,
|
||||||
|
expectedErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sysfsdirs: []string{"non_gpu_card"},
|
||||||
|
expectedDevs: 0,
|
||||||
|
expectedErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testPlugin := newDevicePlugin(sysfs, devfs, 1)
|
testPlugin := newDevicePlugin(sysfs, devfs, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user