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()
|
||||
for _, f := range files {
|
||||
if dp.gpuDeviceReg.MatchString(f.Name()) {
|
||||
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)
|
||||
var nodes []pluginapi.DeviceSpec
|
||||
|
||||
if !dp.gpuDeviceReg.MatchString(f.Name()) {
|
||||
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
|
||||
}
|
||||
|
||||
if strings.TrimSpace(string(dat)) == vendorString {
|
||||
var nodes []pluginapi.DeviceSpec
|
||||
debug.Printf("Adding %s to GPU %s", devPath, f.Name())
|
||||
nodes = append(nodes, pluginapi.DeviceSpec{
|
||||
HostPath: devPath,
|
||||
ContainerPath: devPath,
|
||||
Permissions: "rw",
|
||||
})
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
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,
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user