Allow accept-visible-devices config options to be set

This change allows the
* accept-nvidia-visible-devices-envvar-when-unprivileged
* accept-nvidia-visible-devices-as-volume-mounts

options to be set in the toolkit-container. These are controlled
by command line flags or the following environment variables:

* ACCEPT_NVIDIA_VISIBLE_DEVICES_ENVVAR_WHEN_UNPRIVILEGED
* ACCEPT_NVIDIA_VISIBLE_DEVICES_AS_VOLUME_MOUNTS

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-07-25 10:31:31 +02:00
parent 9c060f06ba
commit 90518e0ce5

View File

@ -45,6 +45,9 @@ type options struct {
ContainerRuntimeLogLevel string ContainerRuntimeLogLevel string
ContainerCLIDebug string ContainerCLIDebug string
toolkitRoot string toolkitRoot string
acceptNVIDIAVisibleDevicesWhenUnprivileged bool
acceptNVIDIAVisibleDevicesAsVolumeMounts bool
} }
func main() { func main() {
@ -111,6 +114,18 @@ func main() {
Destination: &opts.ContainerCLIDebug, Destination: &opts.ContainerCLIDebug,
EnvVars: []string{"NVIDIA_CONTAINER_CLI_DEBUG"}, EnvVars: []string{"NVIDIA_CONTAINER_CLI_DEBUG"},
}, },
&cli.BoolFlag{
Name: "accept-nvidia-visible-devices-envvar-when-unprivileged",
Usage: "Set the accept-nvidia-visible-devices-envvar-when-unprivileged config option",
Destination: &opts.acceptNVIDIAVisibleDevicesWhenUnprivileged,
EnvVars: []string{"ACCEPT_NVIDIA_VISIBLE_DEVICES_ENVVAR_WHEN_UNPRIVILEGED"},
},
&cli.BoolFlag{
Name: "accept-nvidia-visible-devices-as-volume-mounts",
Usage: "Set the accept-nvidia-visible-devices-as-volume-mounts config option",
Destination: &opts.acceptNVIDIAVisibleDevicesWhenUnprivileged,
EnvVars: []string{"ACCEPT_NVIDIA_VISIBLE_DEVICES_AS_VOLUME_MOUNTS"},
},
&cli.StringFlag{ &cli.StringFlag{
Name: "toolkit-root", Name: "toolkit-root",
Usage: "The directory where the NVIDIA Container toolkit is to be installed", Usage: "The directory where the NVIDIA Container toolkit is to be installed",
@ -260,6 +275,10 @@ func installToolkitConfig(toolkitConfigPath string, nvidiaContainerCliExecutable
} }
defer targetConfig.Close() defer targetConfig.Close()
// Set the options in the root toml table
config.Set("accept-nvidia-visible-devices-envvar-when-unprivileged", opts.acceptNVIDIAVisibleDevicesWhenUnprivileged)
config.Set("accept-nvidia-visible-devices-as-volume-mounts", opts.acceptNVIDIAVisibleDevicesAsVolumeMounts)
nvidiaContainerCliKey := func(p string) []string { nvidiaContainerCliKey := func(p string) []string {
return []string{"nvidia-container-cli", p} return []string{"nvidia-container-cli", p}
} }