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
					
				| @ -45,6 +45,7 @@ type HookConfig struct { | ||||
| 
 | ||||
| 	NvidiaContainerCLI         CLIConfig                `toml:"nvidia-container-cli"` | ||||
| 	NVIDIAContainerRuntime     config.RuntimeConfig     `toml:"nvidia-container-runtime"` | ||||
| 	NVIDIAContainerRuntimeHook config.RuntimeHookConfig `toml:"nvidia-container-runtime-hook"` | ||||
| } | ||||
| 
 | ||||
| func getDefaultHookConfig() HookConfig { | ||||
| @ -67,6 +68,7 @@ func getDefaultHookConfig() HookConfig { | ||||
| 			Ldconfig:    nil, | ||||
| 		}, | ||||
| 		NVIDIAContainerRuntime:     *config.GetDefaultRuntimeConfig(), | ||||
| 		NVIDIAContainerRuntimeHook: *config.GetDefaultRuntimeHookConfig(), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -74,7 +74,7 @@ func doPrestart() { | ||||
| 	hook := getHookConfig() | ||||
| 	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.") | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -50,6 +50,7 @@ type Config struct { | ||||
| 	NVIDIAContainerCLIConfig         ContainerCLIConfig `toml:"nvidia-container-cli"` | ||||
| 	NVIDIACTKConfig                  CTKConfig          `toml:"nvidia-ctk"` | ||||
| 	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
 | ||||
| @ -103,6 +104,12 @@ func getConfigFrom(toml *toml.Tree) (*Config, error) { | ||||
| 	} | ||||
| 	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 | ||||
| } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										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