From 154cd4ecf3b94a8446dc8a436690225e1e40c8e5 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 9 Mar 2023 11:14:38 +0200 Subject: [PATCH] Add to config struct Signed-off-by: Evan Lezar --- internal/config/config.go | 5 +++++ internal/config/config_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index 6adc604e..b3c6f890 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -45,6 +45,8 @@ var ( // Config represents the contents of the config.toml file for the NVIDIA Container Toolkit // Note: This is currently duplicated by the HookConfig in cmd/nvidia-container-toolkit/hook_config.go type Config struct { + AcceptEnvvarUnprivileged bool `toml:"accept-nvidia-visible-devices-envvar-when-unprivileged"` + NVIDIAContainerCLIConfig ContainerCLIConfig `toml:"nvidia-container-cli"` NVIDIACTKConfig CTKConfig `toml:"nvidia-ctk"` NVIDIAContainerRuntimeConfig RuntimeConfig `toml:"nvidia-container-runtime"` @@ -91,6 +93,8 @@ func getConfigFrom(toml *toml.Tree) (*Config, error) { return cfg, nil } + cfg.AcceptEnvvarUnprivileged = toml.GetDefault("accept-nvidia-visible-devices-envvar-when-unprivileged", cfg.AcceptEnvvarUnprivileged).(bool) + cfg.NVIDIAContainerCLIConfig = *getContainerCLIConfigFrom(toml) cfg.NVIDIACTKConfig = *getCTKConfigFrom(toml) runtimeConfig, err := getRuntimeConfigFrom(toml) @@ -105,6 +109,7 @@ func getConfigFrom(toml *toml.Tree) (*Config, error) { // getDefaultConfig defines the default values for the config func getDefaultConfig() *Config { c := Config{ + AcceptEnvvarUnprivileged: true, NVIDIAContainerCLIConfig: *getDefaultContainerCLIConfig(), NVIDIACTKConfig: *getDefaultCTKConfig(), NVIDIAContainerRuntimeConfig: *GetDefaultRuntimeConfig(), diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 12683ae2..4c378d55 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -57,6 +57,7 @@ func TestGetConfig(t *testing.T) { { description: "empty config is default", expectedConfig: &Config{ + AcceptEnvvarUnprivileged: true, NVIDIAContainerCLIConfig: ContainerCLIConfig{ Root: "", }, @@ -82,6 +83,7 @@ func TestGetConfig(t *testing.T) { { description: "config options set inline", contents: []string{ + "accept-nvidia-visible-devices-envvar-when-unprivileged = false", "nvidia-container-cli.root = \"/bar/baz\"", "nvidia-container-runtime.debug = \"/foo/bar\"", "nvidia-container-runtime.experimental = true", @@ -94,6 +96,7 @@ func TestGetConfig(t *testing.T) { "nvidia-ctk.path = \"/foo/bar/nvidia-ctk\"", }, expectedConfig: &Config{ + AcceptEnvvarUnprivileged: false, NVIDIAContainerCLIConfig: ContainerCLIConfig{ Root: "/bar/baz", }, @@ -119,6 +122,7 @@ func TestGetConfig(t *testing.T) { { description: "config options set in section", contents: []string{ + "accept-nvidia-visible-devices-envvar-when-unprivileged = false", "[nvidia-container-cli]", "root = \"/bar/baz\"", "[nvidia-container-runtime]", @@ -136,6 +140,7 @@ func TestGetConfig(t *testing.T) { "path = \"/foo/bar/nvidia-ctk\"", }, expectedConfig: &Config{ + AcceptEnvvarUnprivileged: false, NVIDIAContainerCLIConfig: ContainerCLIConfig{ Root: "/bar/baz", },