diff --git a/config/config.toml.amzn b/config/config.toml.amzn index 23d056ca..33d8e827 100644 --- a/config/config.toml.amzn +++ b/config/config.toml.amzn @@ -11,7 +11,6 @@ load-kmods = true #no-cgroups = false #user = "root:video" ldconfig = "@/sbin/ldconfig" -#alpha-merge-visible-devices-envvars = false [nvidia-container-runtime] #debug = "/var/log/nvidia-container-runtime.log" diff --git a/config/config.toml.centos b/config/config.toml.centos index 23d056ca..33d8e827 100644 --- a/config/config.toml.centos +++ b/config/config.toml.centos @@ -11,7 +11,6 @@ load-kmods = true #no-cgroups = false #user = "root:video" ldconfig = "@/sbin/ldconfig" -#alpha-merge-visible-devices-envvars = false [nvidia-container-runtime] #debug = "/var/log/nvidia-container-runtime.log" diff --git a/config/config.toml.debian b/config/config.toml.debian index 23d056ca..33d8e827 100644 --- a/config/config.toml.debian +++ b/config/config.toml.debian @@ -11,7 +11,6 @@ load-kmods = true #no-cgroups = false #user = "root:video" ldconfig = "@/sbin/ldconfig" -#alpha-merge-visible-devices-envvars = false [nvidia-container-runtime] #debug = "/var/log/nvidia-container-runtime.log" diff --git a/config/config.toml.opensuse-leap b/config/config.toml.opensuse-leap index 4d51e51f..cee982ad 100644 --- a/config/config.toml.opensuse-leap +++ b/config/config.toml.opensuse-leap @@ -11,7 +11,6 @@ load-kmods = true #no-cgroups = false user = "root:video" ldconfig = "@/sbin/ldconfig" -#alpha-merge-visible-devices-envvars = false [nvidia-container-runtime] #debug = "/var/log/nvidia-container-runtime.log" diff --git a/config/config.toml.ubuntu b/config/config.toml.ubuntu index 1c2c2b6e..0acaae6a 100644 --- a/config/config.toml.ubuntu +++ b/config/config.toml.ubuntu @@ -11,7 +11,6 @@ load-kmods = true #no-cgroups = false #user = "root:video" ldconfig = "@/sbin/ldconfig.real" -#alpha-merge-visible-devices-envvars = false [nvidia-container-runtime] #debug = "/var/log/nvidia-container-runtime.log" diff --git a/container_config_test.go b/container_config_test.go deleted file mode 100644 index 7e5b0699..00000000 --- a/container_config_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package main - -import ( - "github.com/stretchr/testify/require" - "sort" - "strings" - "testing" -) - -func TestMergeVisibleDevicesEnvvars(t *testing.T) { - var tests = []struct { - name string - input []string - expected string - enableMerge bool - }{ - { - "Simple Merge Enabled", - []string{ - "NVIDIA_VISIBLE_DEVICES_0=0,1", - "NVIDIA_VISIBLE_DEVICES_1=2,3", - "NVIDIA_VISIBLE_DEVICES_WHATEVER=4,5", - }, - "0,1,2,3,4,5", - true, - }, - { - "Simple Merge Disabled", - []string{ - "NVIDIA_VISIBLE_DEVICES_0=0,1", - "NVIDIA_VISIBLE_DEVICES_1=2,3", - "NVIDIA_VISIBLE_DEVICES_WHATEVER=4,5", - }, - "", - false, - }, - { - "Merge No Override (Enabled)", - []string{ - "NVIDIA_VISIBLE_DEVICES=all", - }, - "all", - true, - }, - { - "Merge No Override (Disabled)", - []string{ - "NVIDIA_VISIBLE_DEVICES=all", - }, - "all", - false, - }, - { - "Merge Override (Enabled, Before)", - []string{ - "NVIDIA_VISIBLE_DEVICES=all", - "NVIDIA_VISIBLE_DEVICES_0=0,1", - "NVIDIA_VISIBLE_DEVICES_1=2,3", - "NVIDIA_VISIBLE_DEVICES_WHATEVER=4,5", - }, - "0,1,2,3,4,5", - true, - }, - { - "Merge Override (Enabled, After)", - []string{ - "NVIDIA_VISIBLE_DEVICES_0=0,1", - "NVIDIA_VISIBLE_DEVICES_1=2,3", - "NVIDIA_VISIBLE_DEVICES_WHATEVER=4,5", - "NVIDIA_VISIBLE_DEVICES=all", - }, - "0,1,2,3,4,5", - true, - }, - { - "Merge Override (Enabled, In Between)", - []string{ - "NVIDIA_VISIBLE_DEVICES_0=0,1", - "NVIDIA_VISIBLE_DEVICES_1=2,3", - "NVIDIA_VISIBLE_DEVICES=all", - "NVIDIA_VISIBLE_DEVICES_WHATEVER=4,5", - }, - "0,1,2,3,4,5", - true, - }, - { - "Merge Override (Disabled, Before)", - []string{ - "NVIDIA_VISIBLE_DEVICES=all", - "NVIDIA_VISIBLE_DEVICES_0=0,1", - "NVIDIA_VISIBLE_DEVICES_1=2,3", - "NVIDIA_VISIBLE_DEVICES_WHATEVER=4,5", - }, - "all", - false, - }, - { - "Merge Override (Disabled, After)", - []string{ - "NVIDIA_VISIBLE_DEVICES_0=0,1", - "NVIDIA_VISIBLE_DEVICES_1=2,3", - "NVIDIA_VISIBLE_DEVICES_WHATEVER=4,5", - "NVIDIA_VISIBLE_DEVICES=all", - }, - "all", - false, - }, - { - "Merge Override (Disabled, In Between)", - []string{ - "NVIDIA_VISIBLE_DEVICES_0=0,1", - "NVIDIA_VISIBLE_DEVICES_1=2,3", - "NVIDIA_VISIBLE_DEVICES=all", - "NVIDIA_VISIBLE_DEVICES_WHATEVER=4,5", - }, - "all", - false, - }, - } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - config := CLIConfig{ - AlphaMergeVisibleDevicesEnvvars: tc.enableMerge, - } - envvars := getEnvMap(tc.input, config) - devices := strings.Split(envvars[envNVVisibleDevices], ",") - sort.Strings(devices) - require.Equal(t, tc.expected, strings.Join(devices, ",")) - }) - } -} diff --git a/pkg/container_config.go b/pkg/container_config.go index 15bbc0f4..4d129acd 100644 --- a/pkg/container_config.go +++ b/pkg/container_config.go @@ -108,7 +108,7 @@ func parseCudaVersion(cudaVersion string) (vmaj, vmin, vpatch uint32) { return } -func getEnvMap(e []string, config CLIConfig) (m map[string]string) { +func getEnvMap(e []string) (m map[string]string) { m = make(map[string]string) for _, s := range e { p := strings.SplitN(s, "=", 2) @@ -117,17 +117,6 @@ func getEnvMap(e []string, config CLIConfig) (m map[string]string) { } m[p[0]] = p[1] } - if config.AlphaMergeVisibleDevicesEnvvars { - var mergable []string - for k, v := range m { - if strings.HasPrefix(k, envNVVisibleDevices+"_") { - mergable = append(mergable, v) - } - } - if len(mergable) > 0 { - m[envNVVisibleDevices] = strings.Join(mergable, ",") - } - } return } @@ -357,7 +346,7 @@ func getContainerConfig(hook HookConfig) (config containerConfig) { s := loadSpec(path.Join(b, "config.json")) - env := getEnvMap(s.Process.Env, hook.NvidiaContainerCLI) + env := getEnvMap(s.Process.Env) privileged := isPrivileged(s) envSwarmGPU = hook.SwarmResource return containerConfig{ diff --git a/pkg/hook_config.go b/pkg/hook_config.go index 3790fc46..23cafcbd 100644 --- a/pkg/hook_config.go +++ b/pkg/hook_config.go @@ -20,17 +20,16 @@ var defaultPaths = [...]string{ // CLIConfig : options for nvidia-container-cli. type CLIConfig struct { - Root *string `toml:"root"` - Path *string `toml:"path"` - Environment []string `toml:"environment"` - Debug *string `toml:"debug"` - Ldcache *string `toml:"ldcache"` - LoadKmods bool `toml:"load-kmods"` - NoPivot bool `toml:"no-pivot"` - NoCgroups bool `toml:"no-cgroups"` - User *string `toml:"user"` - Ldconfig *string `toml:"ldconfig"` - AlphaMergeVisibleDevicesEnvvars bool `toml:"alpha-merge-visible-devices-envvars"` + Root *string `toml:"root"` + Path *string `toml:"path"` + Environment []string `toml:"environment"` + Debug *string `toml:"debug"` + Ldcache *string `toml:"ldcache"` + LoadKmods bool `toml:"load-kmods"` + NoPivot bool `toml:"no-pivot"` + NoCgroups bool `toml:"no-cgroups"` + User *string `toml:"user"` + Ldconfig *string `toml:"ldconfig"` } // HookConfig : options for the nvidia-container-toolkit. @@ -46,17 +45,16 @@ func getDefaultHookConfig() (config HookConfig) { DisableRequire: false, SwarmResource: nil, NvidiaContainerCLI: CLIConfig{ - Root: nil, - Path: nil, - Environment: []string{}, - Debug: nil, - Ldcache: nil, - LoadKmods: true, - NoPivot: false, - NoCgroups: false, - User: nil, - Ldconfig: nil, - AlphaMergeVisibleDevicesEnvvars: false, + Root: nil, + Path: nil, + Environment: []string{}, + Debug: nil, + Ldcache: nil, + LoadKmods: true, + NoPivot: false, + NoCgroups: false, + User: nil, + Ldconfig: nil, }, } }