Skip to content

Commit f6b1b1a

Browse files
committed
Ignore NVIDIA_VISIBLE_DEVICES for containers with insufficent privileges
This change ignores the value of NVIDIA_VISIBLE_DEVICES instead of raising an error when launching a container with insufficient permissions. This changes the behaviour under the following conditions: NVIDIA_VISIBLE_DEVICES is set and accept-nvidia-visible-devices-envvar-when-unprivileged = false (default: true) or privileged = false (default: false) This means that a user need not explicitly clear the NVIDIA_VISIBLE_DEVICES environment variable if no GPUs are to be used in unprivileged containers. Note that this envvar is set to 'all' by default in many CUDA images that are used as base images. Signed-off-by: Evan Lezar <[email protected]>
1 parent 9751646 commit f6b1b1a

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

pkg/container_config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ func getDevices(hookConfig *HookConfig, env map[string]string, mounts []Mount, p
295295
return devices
296296
}
297297

298-
// Error out otherwise
299-
log.Panicln("insufficient privileges to read device list from NVIDIA_VISIBLE_DEVICES envvar")
298+
log.Printf("Ignoring devices specified in NVIDIA_VISIBLE_DEVICES (privileged=%v, config.accept-nvidia-visible-devices-envvar-when-unprivileged=%v) ", privileged, hookConfig.AcceptEnvvarUnprivileged)
300299

301300
return nil
302301
}

pkg/container_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ func TestDeviceListSourcePriority(t *testing.T) {
540540
acceptUnprivileged bool
541541
acceptMounts bool
542542
expectedDevices *string
543-
expectedPanic bool
544543
}{
545544
{
546545
description: "Mount devices, unprivileged, no accept unprivileged",
@@ -567,7 +566,7 @@ func TestDeviceListSourcePriority(t *testing.T) {
567566
privileged: false,
568567
acceptUnprivileged: false,
569568
acceptMounts: true,
570-
expectedPanic: true,
569+
expectedDevices: nil,
571570
},
572571
{
573572
description: "No mount devices, privileged, no accept unprivileged",
@@ -621,7 +620,7 @@ func TestDeviceListSourcePriority(t *testing.T) {
621620
privileged: false,
622621
acceptUnprivileged: false,
623622
acceptMounts: false,
624-
expectedPanic: true,
623+
expectedDevices: nil,
625624
},
626625
}
627626
for _, tc := range tests {
@@ -638,12 +637,6 @@ func TestDeviceListSourcePriority(t *testing.T) {
638637
devices = getDevices(&hookConfig, env, tc.mountDevices, tc.privileged, false)
639638
}
640639

641-
// For any tests that are expected to panic, make sure they do.
642-
if tc.expectedPanic {
643-
mustPanic(t, getDevices)
644-
return
645-
}
646-
647640
// For all other tests, just grab the devices and check the results
648641
getDevices()
649642
if !reflect.DeepEqual(devices, tc.expectedDevices) {

0 commit comments

Comments
 (0)