Update getDevices() to account for getting the devices list from mounts

Signed-off-by: Kevin Klues <kklues@nvidia.com>
This commit is contained in:
Kevin Klues 2020-07-23 14:44:22 +00:00
parent f46d1861d3
commit 7313069d4c

View File

@ -240,7 +240,25 @@ func getDevicesFromMounts(root string, mounts []Mount) *string {
} }
func getDevices(hookConfig *HookConfig, env map[string]string, mounts []Mount, privileged bool, legacyImage bool) *string { func getDevices(hookConfig *HookConfig, env map[string]string, mounts []Mount, privileged bool, legacyImage bool) *string {
return getDevicesFromEnvvar(env, legacyImage) // Try and get the device list from mount volumes first
devices := getDevicesFromMounts(*hookConfig.DeviceListVolumeMount, mounts)
if devices != nil {
return devices
}
// Fallback to reading from the environment variable if privileges are correct
devices = getDevicesFromEnvvar(env, legacyImage)
if devices == nil {
return nil
}
if privileged || hookConfig.AcceptEnvvarUnprivileged {
return devices
}
// Error out otherwise
log.Panicln("insufficient privileges to read device list from NVIDIA_VISIBLE_DEVICES envvar")
return nil
} }
func getMigConfigDevices(env map[string]string) *string { func getMigConfigDevices(env map[string]string) *string {