From da36874e91beeb7de19a4a0b18253bb5ea33e691 Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Wed, 22 Jul 2020 14:42:29 +0000 Subject: [PATCH] Add new config options to pull device list from mounted files not ENVVAR Signed-off-by: Kevin Klues --- config/config.toml.amzn | 2 ++ config/config.toml.centos | 2 ++ config/config.toml.debian | 2 ++ config/config.toml.opensuse-leap | 2 ++ config/config.toml.ubuntu | 2 ++ pkg/hook_config.go | 16 ++++++++++++---- 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config/config.toml.amzn b/config/config.toml.amzn index 33d8e827..4de3d1c9 100644 --- a/config/config.toml.amzn +++ b/config/config.toml.amzn @@ -1,5 +1,7 @@ disable-require = false #swarm-resource = "DOCKER_RESOURCE_GPU" +#accept-nvidia-visible-devices-envvar-when-unprivileged = true +#look-for-nvidia-visible-devices-as-volume-mounts-under = "/var/run/nvidia-container-devices" [nvidia-container-cli] #root = "/run/nvidia/driver" diff --git a/config/config.toml.centos b/config/config.toml.centos index 33d8e827..4de3d1c9 100644 --- a/config/config.toml.centos +++ b/config/config.toml.centos @@ -1,5 +1,7 @@ disable-require = false #swarm-resource = "DOCKER_RESOURCE_GPU" +#accept-nvidia-visible-devices-envvar-when-unprivileged = true +#look-for-nvidia-visible-devices-as-volume-mounts-under = "/var/run/nvidia-container-devices" [nvidia-container-cli] #root = "/run/nvidia/driver" diff --git a/config/config.toml.debian b/config/config.toml.debian index 33d8e827..4de3d1c9 100644 --- a/config/config.toml.debian +++ b/config/config.toml.debian @@ -1,5 +1,7 @@ disable-require = false #swarm-resource = "DOCKER_RESOURCE_GPU" +#accept-nvidia-visible-devices-envvar-when-unprivileged = true +#look-for-nvidia-visible-devices-as-volume-mounts-under = "/var/run/nvidia-container-devices" [nvidia-container-cli] #root = "/run/nvidia/driver" diff --git a/config/config.toml.opensuse-leap b/config/config.toml.opensuse-leap index cee982ad..fe28e163 100644 --- a/config/config.toml.opensuse-leap +++ b/config/config.toml.opensuse-leap @@ -1,5 +1,7 @@ disable-require = false #swarm-resource = "DOCKER_RESOURCE_GPU" +#accept-nvidia-visible-devices-envvar-when-unprivileged = true +#look-for-nvidia-visible-devices-as-volume-mounts-under = "/var/run/nvidia-container-devices" [nvidia-container-cli] #root = "/run/nvidia/driver" diff --git a/config/config.toml.ubuntu b/config/config.toml.ubuntu index 0acaae6a..061c0759 100644 --- a/config/config.toml.ubuntu +++ b/config/config.toml.ubuntu @@ -1,5 +1,7 @@ disable-require = false #swarm-resource = "DOCKER_RESOURCE_GPU" +#accept-nvidia-visible-devices-envvar-when-unprivileged = true +#look-for-nvidia-visible-devices-as-volume-mounts-under = "/var/run/nvidia-container-devices" [nvidia-container-cli] #root = "/run/nvidia/driver" diff --git a/pkg/hook_config.go b/pkg/hook_config.go index 23cafcbd..09b78e14 100644 --- a/pkg/hook_config.go +++ b/pkg/hook_config.go @@ -13,6 +13,10 @@ const ( driverPath = "/run/nvidia/driver" ) +const ( + defaultDeviceListVolumeMount = "/var/run/nvidia-container-devices" +) + var defaultPaths = [...]string{ path.Join(driverPath, configPath), configPath, @@ -34,16 +38,20 @@ type CLIConfig struct { // HookConfig : options for the nvidia-container-toolkit. type HookConfig struct { - DisableRequire bool `toml:"disable-require"` - SwarmResource *string `toml:"swarm-resource"` + DisableRequire bool `toml:"disable-require"` + SwarmResource *string `toml:"swarm-resource"` + AcceptEnvvarUnprivileged bool `toml:"accept-nvidia-visible-devices-envvar-when-unprivileged"` + DeviceListVolumeMount *string `toml:"look-for-nvidia-visible-devices-as-volume-mounts-under"` NvidiaContainerCLI CLIConfig `toml:"nvidia-container-cli"` } func getDefaultHookConfig() (config HookConfig) { return HookConfig{ - DisableRequire: false, - SwarmResource: nil, + DisableRequire: false, + SwarmResource: nil, + AcceptEnvvarUnprivileged: true, + DeviceListVolumeMount: &[]string{defaultDeviceListVolumeMount}[0], NvidiaContainerCLI: CLIConfig{ Root: nil, Path: nil,