mirror of
				https://github.com/NVIDIA/nvidia-container-toolkit
				synced 2025-06-26 18:18:24 +00:00 
			
		
		
		
	Add nvidia-container-runtime.runtimes config option
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
		
							parent
							
								
									e93bafa6d4
								
							
						
					
					
						commit
						c76946cbcc
					
				| @ -24,6 +24,10 @@ const ( | |||||||
| 	unmodifiedSpecFileSuffix = "test/input/test_spec.json" | 	unmodifiedSpecFileSuffix = "test/input/test_spec.json" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | const ( | ||||||
|  | 	runcExecutableName = "runc" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
| type testConfig struct { | type testConfig struct { | ||||||
| 	root    string | 	root    string | ||||||
| 	binPath string | 	binPath string | ||||||
|  | |||||||
| @ -26,15 +26,9 @@ import ( | |||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const ( |  | ||||||
| 	dockerRuncExecutableName = "docker-runc" |  | ||||||
| 	runcExecutableName       = "runc" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| // newNVIDIAContainerRuntime is a factory method that constructs a runtime based on the selected configuration and specified logger
 | // newNVIDIAContainerRuntime is a factory method that constructs a runtime based on the selected configuration and specified logger
 | ||||||
| func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.Config, argv []string) (oci.Runtime, error) { | func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.Config, argv []string) (oci.Runtime, error) { | ||||||
| 	lowLevelRuntimeCandidates := []string{dockerRuncExecutableName, runcExecutableName} | 	lowLevelRuntime, err := oci.NewLowLevelRuntime(logger, cfg.NVIDIAContainerRuntimeConfig.Runtimes) | ||||||
| 	lowLevelRuntime, err := oci.NewLowLevelRuntime(logger, lowLevelRuntimeCandidates) |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("error constructing low-level runtime: %v", err) | 		return nil, fmt.Errorf("error constructing low-level runtime: %v", err) | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -38,10 +38,19 @@ func TestFactoryMethod(t *testing.T) { | |||||||
| 		expectedError bool | 		expectedError bool | ||||||
| 	}{ | 	}{ | ||||||
| 		{ | 		{ | ||||||
| 			description: "empty config no error", | 			description: "empty config raises error", | ||||||
| 			cfg: &config.Config{ | 			cfg: &config.Config{ | ||||||
| 				NVIDIAContainerRuntimeConfig: config.RuntimeConfig{}, | 				NVIDIAContainerRuntimeConfig: config.RuntimeConfig{}, | ||||||
| 			}, | 			}, | ||||||
|  | 			expectedError: true, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			description: "config with runtime raises no error", | ||||||
|  | 			cfg: &config.Config{ | ||||||
|  | 				NVIDIAContainerRuntimeConfig: config.RuntimeConfig{ | ||||||
|  | 					Runtimes: []string{"runc"}, | ||||||
|  | 				}, | ||||||
|  | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			description: "experimental flag supported", | 			description: "experimental flag supported", | ||||||
| @ -49,6 +58,7 @@ func TestFactoryMethod(t *testing.T) { | |||||||
| 				NVIDIAContainerRuntimeConfig: config.RuntimeConfig{ | 				NVIDIAContainerRuntimeConfig: config.RuntimeConfig{ | ||||||
| 					Experimental: true, | 					Experimental: true, | ||||||
| 					DiscoverMode: "legacy", | 					DiscoverMode: "legacy", | ||||||
|  | 					Runtimes:     []string{"runc"}, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			spec: &specs.Spec{ | 			spec: &specs.Spec{ | ||||||
|  | |||||||
| @ -17,3 +17,10 @@ ldconfig = "@/sbin/ldconfig.real" | |||||||
| [nvidia-container-runtime] | [nvidia-container-runtime] | ||||||
| #debug = "/var/log/nvidia-container-runtime.log" | #debug = "/var/log/nvidia-container-runtime.log" | ||||||
| #experimental = false | #experimental = false | ||||||
|  | 
 | ||||||
|  | # Specify the runtimes to consider. This list is processed in order and the PATH | ||||||
|  | # searched for matching executables unless the entry is an absolute path. | ||||||
|  | runtimes = [ | ||||||
|  |     "docker-runc", | ||||||
|  |     "runc", | ||||||
|  | ] | ||||||
|  | |||||||
| @ -65,6 +65,7 @@ func TestGetConfig(t *testing.T) { | |||||||
| 					Experimental:  false, | 					Experimental:  false, | ||||||
| 					DiscoverMode:  "auto", | 					DiscoverMode:  "auto", | ||||||
| 					LogLevel:      "info", | 					LogLevel:      "info", | ||||||
|  | 					Runtimes:      []string{"docker-runc", "runc"}, | ||||||
| 				}, | 				}, | ||||||
| 				NVIDIACTKConfig: CTKConfig{ | 				NVIDIACTKConfig: CTKConfig{ | ||||||
| 					Path: "nvidia-ctk", | 					Path: "nvidia-ctk", | ||||||
| @ -79,6 +80,7 @@ func TestGetConfig(t *testing.T) { | |||||||
| 				"nvidia-container-runtime.experimental = true", | 				"nvidia-container-runtime.experimental = true", | ||||||
| 				"nvidia-container-runtime.discover-mode = \"not-legacy\"", | 				"nvidia-container-runtime.discover-mode = \"not-legacy\"", | ||||||
| 				"nvidia-container-runtime.log-level = \"debug\"", | 				"nvidia-container-runtime.log-level = \"debug\"", | ||||||
|  | 				"nvidia-container-runtime.runtimes = [\"/some/runtime\",]", | ||||||
| 				"nvidia-ctk.path = \"/foo/bar/nvidia-ctk\"", | 				"nvidia-ctk.path = \"/foo/bar/nvidia-ctk\"", | ||||||
| 			}, | 			}, | ||||||
| 			expectedConfig: &Config{ | 			expectedConfig: &Config{ | ||||||
| @ -90,6 +92,7 @@ func TestGetConfig(t *testing.T) { | |||||||
| 					Experimental:  true, | 					Experimental:  true, | ||||||
| 					DiscoverMode:  "not-legacy", | 					DiscoverMode:  "not-legacy", | ||||||
| 					LogLevel:      "debug", | 					LogLevel:      "debug", | ||||||
|  | 					Runtimes:      []string{"/some/runtime"}, | ||||||
| 				}, | 				}, | ||||||
| 				NVIDIACTKConfig: CTKConfig{ | 				NVIDIACTKConfig: CTKConfig{ | ||||||
| 					Path: "/foo/bar/nvidia-ctk", | 					Path: "/foo/bar/nvidia-ctk", | ||||||
| @ -106,6 +109,7 @@ func TestGetConfig(t *testing.T) { | |||||||
| 				"experimental = true", | 				"experimental = true", | ||||||
| 				"discover-mode = \"not-legacy\"", | 				"discover-mode = \"not-legacy\"", | ||||||
| 				"log-level = \"debug\"", | 				"log-level = \"debug\"", | ||||||
|  | 				"runtimes = [\"/some/runtime\",]", | ||||||
| 				"[nvidia-ctk]", | 				"[nvidia-ctk]", | ||||||
| 				"path = \"/foo/bar/nvidia-ctk\"", | 				"path = \"/foo/bar/nvidia-ctk\"", | ||||||
| 			}, | 			}, | ||||||
| @ -118,6 +122,7 @@ func TestGetConfig(t *testing.T) { | |||||||
| 					Experimental:  true, | 					Experimental:  true, | ||||||
| 					DiscoverMode:  "not-legacy", | 					DiscoverMode:  "not-legacy", | ||||||
| 					LogLevel:      "debug", | 					LogLevel:      "debug", | ||||||
|  | 					Runtimes:      []string{"/some/runtime"}, | ||||||
| 				}, | 				}, | ||||||
| 				NVIDIACTKConfig: CTKConfig{ | 				NVIDIACTKConfig: CTKConfig{ | ||||||
| 					Path: "/foo/bar/nvidia-ctk", | 					Path: "/foo/bar/nvidia-ctk", | ||||||
|  | |||||||
| @ -21,6 +21,11 @@ import ( | |||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | const ( | ||||||
|  | 	dockerRuncExecutableName = "docker-runc" | ||||||
|  | 	runcExecutableName       = "runc" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
| // RuntimeConfig stores the config options for the NVIDIA Container Runtime
 | // RuntimeConfig stores the config options for the NVIDIA Container Runtime
 | ||||||
| type RuntimeConfig struct { | type RuntimeConfig struct { | ||||||
| 	DebugFilePath string | 	DebugFilePath string | ||||||
| @ -28,6 +33,8 @@ type RuntimeConfig struct { | |||||||
| 	DiscoverMode  string | 	DiscoverMode  string | ||||||
| 	// LogLevel defines the logging level for the application
 | 	// LogLevel defines the logging level for the application
 | ||||||
| 	LogLevel string | 	LogLevel string | ||||||
|  | 	// Runtimes defines the candidates for the low-level runtime
 | ||||||
|  | 	Runtimes []string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // getRuntimeConfigFrom reads the nvidia container runtime config from the specified toml Tree.
 | // getRuntimeConfigFrom reads the nvidia container runtime config from the specified toml Tree.
 | ||||||
| @ -43,6 +50,15 @@ func getRuntimeConfigFrom(toml *toml.Tree) *RuntimeConfig { | |||||||
| 	cfg.DiscoverMode = toml.GetDefault("nvidia-container-runtime.discover-mode", cfg.DiscoverMode).(string) | 	cfg.DiscoverMode = toml.GetDefault("nvidia-container-runtime.discover-mode", cfg.DiscoverMode).(string) | ||||||
| 	cfg.LogLevel = toml.GetDefault("nvidia-container-runtime.log-level", cfg.LogLevel).(string) | 	cfg.LogLevel = toml.GetDefault("nvidia-container-runtime.log-level", cfg.LogLevel).(string) | ||||||
| 
 | 
 | ||||||
|  | 	configRuntimes := toml.Get("nvidia-container-runtime.runtimes") | ||||||
|  | 	if configRuntimes != nil { | ||||||
|  | 		var runtimes []string | ||||||
|  | 		for _, r := range configRuntimes.([]interface{}) { | ||||||
|  | 			runtimes = append(runtimes, r.(string)) | ||||||
|  | 		} | ||||||
|  | 		cfg.Runtimes = runtimes | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return cfg | 	return cfg | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -53,6 +69,10 @@ func GetDefaultRuntimeConfig() *RuntimeConfig { | |||||||
| 		Experimental:  false, | 		Experimental:  false, | ||||||
| 		DiscoverMode:  "auto", | 		DiscoverMode:  "auto", | ||||||
| 		LogLevel:      logrus.InfoLevel.String(), | 		LogLevel:      logrus.InfoLevel.String(), | ||||||
|  | 		Runtimes: []string{ | ||||||
|  | 			dockerRuncExecutableName, | ||||||
|  | 			runcExecutableName, | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return &c | 	return &c | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user