mirror of
				https://github.com/NVIDIA/nvidia-container-toolkit
				synced 2025-06-26 18:18:24 +00:00 
			
		
		
		
	Add nvidia-container-runtime-hook.skip-mode-detection option to config
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
		
							parent
							
								
									8f694bbfb7
								
							
						
					
					
						commit
						3a11f6ee0a
					
				| @ -43,8 +43,9 @@ type HookConfig struct { | |||||||
| 	AcceptDeviceListAsVolumeMounts bool               `toml:"accept-nvidia-visible-devices-as-volume-mounts"` | 	AcceptDeviceListAsVolumeMounts bool               `toml:"accept-nvidia-visible-devices-as-volume-mounts"` | ||||||
| 	SupportedDriverCapabilities    DriverCapabilities `toml:"supported-driver-capabilities"` | 	SupportedDriverCapabilities    DriverCapabilities `toml:"supported-driver-capabilities"` | ||||||
| 
 | 
 | ||||||
| 	NvidiaContainerCLI     CLIConfig            `toml:"nvidia-container-cli"` | 	NvidiaContainerCLI         CLIConfig                `toml:"nvidia-container-cli"` | ||||||
| 	NVIDIAContainerRuntime config.RuntimeConfig `toml:"nvidia-container-runtime"` | 	NVIDIAContainerRuntime     config.RuntimeConfig     `toml:"nvidia-container-runtime"` | ||||||
|  | 	NVIDIAContainerRuntimeHook config.RuntimeHookConfig `toml:"nvidia-container-runtime-hook"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getDefaultHookConfig() HookConfig { | func getDefaultHookConfig() HookConfig { | ||||||
| @ -66,7 +67,8 @@ func getDefaultHookConfig() HookConfig { | |||||||
| 			User:        nil, | 			User:        nil, | ||||||
| 			Ldconfig:    nil, | 			Ldconfig:    nil, | ||||||
| 		}, | 		}, | ||||||
| 		NVIDIAContainerRuntime: *config.GetDefaultRuntimeConfig(), | 		NVIDIAContainerRuntime:     *config.GetDefaultRuntimeConfig(), | ||||||
|  | 		NVIDIAContainerRuntimeHook: *config.GetDefaultRuntimeHookConfig(), | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -74,7 +74,7 @@ func doPrestart() { | |||||||
| 	hook := getHookConfig() | 	hook := getHookConfig() | ||||||
| 	cli := hook.NvidiaContainerCLI | 	cli := hook.NvidiaContainerCLI | ||||||
| 
 | 
 | ||||||
| 	if info.ResolveAutoMode(&logInterceptor{}, hook.NVIDIAContainerRuntime.Mode) != "legacy" { | 	if !hook.NVIDIAContainerRuntimeHook.SkipModeDetection && info.ResolveAutoMode(&logInterceptor{}, hook.NVIDIAContainerRuntime.Mode) != "legacy" { | ||||||
| 		log.Panicln("invoking the NVIDIA Container Runtime Hook directly (e.g. specifying the docker --gpus flag) is not supported. Please use the NVIDIA Container Runtime (e.g. specify the --runtime=nvidia flag) instead.") | 		log.Panicln("invoking the NVIDIA Container Runtime Hook directly (e.g. specifying the docker --gpus flag) is not supported. Please use the NVIDIA Container Runtime (e.g. specify the --runtime=nvidia flag) instead.") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -47,9 +47,10 @@ var ( | |||||||
| type Config struct { | type Config struct { | ||||||
| 	AcceptEnvvarUnprivileged bool `toml:"accept-nvidia-visible-devices-envvar-when-unprivileged"` | 	AcceptEnvvarUnprivileged bool `toml:"accept-nvidia-visible-devices-envvar-when-unprivileged"` | ||||||
| 
 | 
 | ||||||
| 	NVIDIAContainerCLIConfig     ContainerCLIConfig `toml:"nvidia-container-cli"` | 	NVIDIAContainerCLIConfig         ContainerCLIConfig `toml:"nvidia-container-cli"` | ||||||
| 	NVIDIACTKConfig              CTKConfig          `toml:"nvidia-ctk"` | 	NVIDIACTKConfig                  CTKConfig          `toml:"nvidia-ctk"` | ||||||
| 	NVIDIAContainerRuntimeConfig RuntimeConfig      `toml:"nvidia-container-runtime"` | 	NVIDIAContainerRuntimeConfig     RuntimeConfig      `toml:"nvidia-container-runtime"` | ||||||
|  | 	NVIDIAContainerRuntimeHookConfig RuntimeHookConfig  `toml:"nvidia-container-runtime-hook"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // GetConfig sets up the config struct. Values are read from a toml file
 | // GetConfig sets up the config struct. Values are read from a toml file
 | ||||||
| @ -103,6 +104,12 @@ func getConfigFrom(toml *toml.Tree) (*Config, error) { | |||||||
| 	} | 	} | ||||||
| 	cfg.NVIDIAContainerRuntimeConfig = *runtimeConfig | 	cfg.NVIDIAContainerRuntimeConfig = *runtimeConfig | ||||||
| 
 | 
 | ||||||
|  | 	runtimeHookConfig, err := getRuntimeHookConfigFrom(toml) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, fmt.Errorf("failed to load nvidia-container-runtime-hook config: %v", err) | ||||||
|  | 	} | ||||||
|  | 	cfg.NVIDIAContainerRuntimeHookConfig = *runtimeHookConfig | ||||||
|  | 
 | ||||||
| 	return cfg, nil | 	return cfg, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										62
									
								
								internal/config/hook.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								internal/config/hook.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,62 @@ | |||||||
|  | /** | ||||||
|  | # Copyright (c) 2022, NVIDIA CORPORATION.  All rights reserved. | ||||||
|  | # | ||||||
|  | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  | # you may not use this file except in compliance with the License. | ||||||
|  | # You may obtain a copy of the License at | ||||||
|  | # | ||||||
|  | #     http://www.apache.org/licenses/LICENSE-2.0
 | ||||||
|  | # | ||||||
|  | # Unless required by applicable law or agreed to in writing, software | ||||||
|  | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  | # See the License for the specific language governing permissions and | ||||||
|  | # limitations under the License. | ||||||
|  | **/ | ||||||
|  | 
 | ||||||
|  | package config | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 
 | ||||||
|  | 	"github.com/pelletier/go-toml" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | // RuntimeHookConfig stores the config options for the NVIDIA Container Runtime
 | ||||||
|  | type RuntimeHookConfig struct { | ||||||
|  | 	// SkipModeDetection disables the mode check for the runtime hook.
 | ||||||
|  | 	SkipModeDetection bool `toml:"skip-mode-detection"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // dummyHookConfig allows us to unmarshal only a RuntimeHookConfig from a *toml.Tree
 | ||||||
|  | type dummyHookConfig struct { | ||||||
|  | 	RuntimeHook RuntimeHookConfig `toml:"nvidia-container-runtime-hook"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // getRuntimeHookConfigFrom reads the nvidia container runtime config from the specified toml Tree.
 | ||||||
|  | func getRuntimeHookConfigFrom(toml *toml.Tree) (*RuntimeHookConfig, error) { | ||||||
|  | 	cfg := GetDefaultRuntimeHookConfig() | ||||||
|  | 
 | ||||||
|  | 	if toml == nil { | ||||||
|  | 		return cfg, nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	d := dummyHookConfig{ | ||||||
|  | 		RuntimeHook: *cfg, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if err := toml.Unmarshal(&d); err != nil { | ||||||
|  | 		return nil, fmt.Errorf("failed to unmarshal runtime config: %v", err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return &d.RuntimeHook, nil | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // GetDefaultRuntimeHookConfig defines the default values for the config
 | ||||||
|  | func GetDefaultRuntimeHookConfig() *RuntimeHookConfig { | ||||||
|  | 	c := RuntimeHookConfig{ | ||||||
|  | 		SkipModeDetection: false, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return &c | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user