From cf7bb91481b03572ade3fd43622669a84063b857 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 9 May 2022 14:13:42 +0200 Subject: [PATCH] Update nvidia-container-runtime config options Signed-off-by: Evan Lezar --- internal/config/config_test.go | 23 +++++++++++++++++++++++ internal/config/runtime.go | 23 +++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index a78611ce..97c49c04 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -66,6 +66,12 @@ func TestGetConfig(t *testing.T) { DiscoverMode: "auto", LogLevel: "info", Runtimes: []string{"docker-runc", "runc"}, + Mode: "auto", + Modes: modesConfig{ + CSV: csvModeConfig{ + MountSpecPath: "/etc/nvidia-container-runtime/host-files-for-container.d", + }, + }, }, NVIDIACTKConfig: CTKConfig{ Path: "nvidia-ctk", @@ -81,6 +87,8 @@ func TestGetConfig(t *testing.T) { "nvidia-container-runtime.discover-mode = \"not-legacy\"", "nvidia-container-runtime.log-level = \"debug\"", "nvidia-container-runtime.runtimes = [\"/some/runtime\",]", + "nvidia-container-runtime.mode = \"not-auto\"", + "nvidia-container-runtime.modes.csv.mount-spec-path = \"/not/etc/nvidia-container-runtime/host-files-for-container.d\"", "nvidia-ctk.path = \"/foo/bar/nvidia-ctk\"", }, expectedConfig: &Config{ @@ -93,6 +101,12 @@ func TestGetConfig(t *testing.T) { DiscoverMode: "not-legacy", LogLevel: "debug", Runtimes: []string{"/some/runtime"}, + Mode: "not-auto", + Modes: modesConfig{ + CSV: csvModeConfig{ + MountSpecPath: "/not/etc/nvidia-container-runtime/host-files-for-container.d", + }, + }, }, NVIDIACTKConfig: CTKConfig{ Path: "/foo/bar/nvidia-ctk", @@ -110,6 +124,9 @@ func TestGetConfig(t *testing.T) { "discover-mode = \"not-legacy\"", "log-level = \"debug\"", "runtimes = [\"/some/runtime\",]", + "mode = \"not-auto\"", + "[nvidia-container-runtime.modes.csv]", + "mount-spec-path = \"/not/etc/nvidia-container-runtime/host-files-for-container.d\"", "[nvidia-ctk]", "path = \"/foo/bar/nvidia-ctk\"", }, @@ -123,6 +140,12 @@ func TestGetConfig(t *testing.T) { DiscoverMode: "not-legacy", LogLevel: "debug", Runtimes: []string{"/some/runtime"}, + Mode: "not-auto", + Modes: modesConfig{ + CSV: csvModeConfig{ + MountSpecPath: "/not/etc/nvidia-container-runtime/host-files-for-container.d", + }, + }, }, NVIDIACTKConfig: CTKConfig{ Path: "/foo/bar/nvidia-ctk", diff --git a/internal/config/runtime.go b/internal/config/runtime.go index 43b67a0b..4ccdbbfe 100644 --- a/internal/config/runtime.go +++ b/internal/config/runtime.go @@ -26,6 +26,8 @@ import ( const ( dockerRuncExecutableName = "docker-runc" runcExecutableName = "runc" + + auto = "auto" ) // RuntimeConfig stores the config options for the NVIDIA Container Runtime @@ -36,7 +38,18 @@ type RuntimeConfig struct { // LogLevel defines the logging level for the application LogLevel string `toml:"log-level"` // Runtimes defines the candidates for the low-level runtime - Runtimes []string `toml:"runtimes"` + Runtimes []string `toml:"runtimes"` + Mode string `toml:"mode"` + Modes modesConfig `toml:"modes"` +} + +// modesConfig defines (optional) per-mode configs +type modesConfig struct { + CSV csvModeConfig `toml:"csv"` +} + +type csvModeConfig struct { + MountSpecPath string `toml:"mount-spec-path"` } // dummy allows us to unmarshal only a RuntimeConfig from a *toml.Tree @@ -68,12 +81,18 @@ func GetDefaultRuntimeConfig() *RuntimeConfig { c := RuntimeConfig{ DebugFilePath: "/dev/null", Experimental: false, - DiscoverMode: "auto", + DiscoverMode: auto, LogLevel: logrus.InfoLevel.String(), Runtimes: []string{ dockerRuncExecutableName, runcExecutableName, }, + Mode: auto, + Modes: modesConfig{ + CSV: csvModeConfig{ + MountSpecPath: "/etc/nvidia-container-runtime/host-files-for-container.d", + }, + }, } return &c