Skip to content

Environment variable case issues when device name is not found. #70

@greg-bock

Description

@greg-bock

If a device id is not present in the pci id file it defaults to using the device id as the device name. However device name normalization and capitalization for use in the environment variable only occurs in getDeviceName during pci id lookup. This results in the resource name staying lowercase as well as the resource name portion of the environment variable. Kubevirt expects an all uppercase environment variable.

Suggested fixes include:

+++ b/pkg/device_plugin/device_plugin.go
@@ -101,7 +101,7 @@ func createDevicePlugins() {
                deviceName := getDeviceName(k)
                if deviceName == "" {
                        log.Printf("Error: Could not find device name for device id: %s", k)
-                       deviceName = k
+                       deviceName = strings.ToUpper(k)
                }
                log.Printf("DP Name %s", deviceName)
                dp := NewGenericDevicePlugin(deviceName, "/sys/kernel/iommu_groups/", devs)
@@ -123,7 +123,7 @@ func createDevicePlugins() {
                }
                deviceName := getDeviceName(k)
                if deviceName == "" {
-                       deviceName = k
+                       deviceName = strings.ToUpper(k)
                }
                log.Printf("DP Name %s", deviceName)
                dp := NewGenericVGpuDevicePlugin(deviceName, vGpuBasePath, devs)

or possibly

+++ b/pkg/device_plugin/device_plugin.go
@@ -99,10 +99,6 @@ func createDevicePlugins() {
                        })
                }
                deviceName := getDeviceName(k)
-               if deviceName == "" {
-                       log.Printf("Error: Could not find device name for device id: %s", k)
-                       deviceName = k
-               }
                log.Printf("DP Name %s", deviceName)
                dp := NewGenericDevicePlugin(deviceName, "/sys/kernel/iommu_groups/", devs)
                err := startDevicePlugin(dp)
@@ -122,9 +118,6 @@ func createDevicePlugins() {
                        })
                }
                deviceName := getDeviceName(k)
-               if deviceName == "" {
-                       deviceName = k
-               }
                log.Printf("DP Name %s", deviceName)
                dp := NewGenericVGpuDevicePlugin(deviceName, vGpuBasePath, devs)
                err := startVgpuDevicePlugin(dp)
@@ -319,7 +312,6 @@ func getDeviceName(deviceID string) string {
                                continue
                        }
                        deviceName = strings.TrimSpace(splits[1])
-                       deviceName = strings.ToUpper(deviceName)
                        deviceName = strings.Replace(deviceName, "/", "_", -1)
                        deviceName = strings.Replace(deviceName, ".", "_", -1)
                        reg, _ := regexp.Compile("\\s+")
@@ -333,5 +325,13 @@ func getDeviceName(deviceID string) string {
        if err := scanner.Err(); err != nil {
                log.Printf("Error reading pci ids file %s", err)
        }
+
+       if deviceName == "" {
+               log.Printf("Error: Could not find device name for device id: %s", deviceID)
+               deviceName = deviceID
+       }
+
+       deviceName = strings.ToUpper(deviceName)
+
        return deviceName
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions