@@ -66,6 +66,8 @@ type options struct {
6666
6767 acceptNVIDIAVisibleDevicesWhenUnprivileged bool
6868 acceptNVIDIAVisibleDevicesAsVolumeMounts bool
69+
70+ ignoreErrors bool
6971}
7072
7173func main () {
@@ -204,6 +206,12 @@ func main() {
204206 Destination : & opts .cdiKind ,
205207 EnvVars : []string {"CDI_KIND" },
206208 },
209+ & cli.BoolFlag {
210+ Name : "ignore-errors" ,
211+ Usage : "ignore errors when installing the NVIDIA Container toolkit. This is used for testing purposes only." ,
212+ Hidden : true ,
213+ Destination : & opts .ignoreErrors ,
214+ },
207215 }
208216
209217 // Update the subcommand flags with the common subcommand flags
@@ -252,46 +260,62 @@ func Install(cli *cli.Context, opts *options) error {
252260
253261 log .Infof ("Removing existing NVIDIA container toolkit installation" )
254262 err := os .RemoveAll (opts .toolkitRoot )
255- if err != nil {
263+ if err != nil && ! opts . ignoreErrors {
256264 return fmt .Errorf ("error removing toolkit directory: %v" , err )
265+ } else if err != nil {
266+ log .Errorf ("Ignoring error: %v" , fmt .Errorf ("error removing toolkit directory: %v" , err ))
257267 }
258268
259269 toolkitConfigDir := filepath .Join (opts .toolkitRoot , ".config" , "nvidia-container-runtime" )
260270 toolkitConfigPath := filepath .Join (toolkitConfigDir , configFilename )
261271
262272 err = createDirectories (opts .toolkitRoot , toolkitConfigDir )
263- if err != nil {
273+ if err != nil && ! opts . ignoreErrors {
264274 return fmt .Errorf ("could not create required directories: %v" , err )
275+ } else if err != nil {
276+ log .Errorf ("Ignoring error: %v" , fmt .Errorf ("could not create required directories: %v" , err ))
265277 }
266278
267279 err = installContainerLibraries (opts .toolkitRoot )
268- if err != nil {
280+ if err != nil && ! opts . ignoreErrors {
269281 return fmt .Errorf ("error installing NVIDIA container library: %v" , err )
282+ } else if err != nil {
283+ log .Errorf ("Ignoring error: %v" , fmt .Errorf ("error installing NVIDIA container library: %v" , err ))
270284 }
271285
272286 err = installContainerRuntimes (opts .toolkitRoot , opts .DriverRoot )
273- if err != nil {
287+ if err != nil && ! opts . ignoreErrors {
274288 return fmt .Errorf ("error installing NVIDIA container runtime: %v" , err )
289+ } else if err != nil {
290+ log .Errorf ("Ignoring error: %v" , fmt .Errorf ("error installing NVIDIA container runtime: %v" , err ))
275291 }
276292
277293 nvidiaContainerCliExecutable , err := installContainerCLI (opts .toolkitRoot )
278- if err != nil {
294+ if err != nil && ! opts . ignoreErrors {
279295 return fmt .Errorf ("error installing NVIDIA container CLI: %v" , err )
296+ } else if err != nil {
297+ log .Errorf ("Ignoring error: %v" , fmt .Errorf ("error installing NVIDIA container CLI: %v" , err ))
280298 }
281299
282300 _ , err = installRuntimeHook (opts .toolkitRoot , toolkitConfigPath )
283- if err != nil {
301+ if err != nil && ! opts . ignoreErrors {
284302 return fmt .Errorf ("error installing NVIDIA container runtime hook: %v" , err )
303+ } else if err != nil {
304+ log .Errorf ("Ignoring error: %v" , fmt .Errorf ("error installing NVIDIA container runtime hook: %v" , err ))
285305 }
286306
287307 nvidiaCTKPath , err := installContainerToolkitCLI (opts .toolkitRoot )
288- if err != nil {
308+ if err != nil && ! opts . ignoreErrors {
289309 return fmt .Errorf ("error installing NVIDIA Container Toolkit CLI: %v" , err )
310+ } else if err != nil {
311+ log .Errorf ("Ignoring error: %v" , fmt .Errorf ("error installing NVIDIA Container Toolkit CLI: %v" , err ))
290312 }
291313
292314 err = installToolkitConfig (cli , toolkitConfigPath , nvidiaContainerCliExecutable , nvidiaCTKPath , opts )
293- if err != nil {
315+ if err != nil && ! opts . ignoreErrors {
294316 return fmt .Errorf ("error installing NVIDIA container toolkit config: %v" , err )
317+ } else if err != nil {
318+ log .Errorf ("Ignoring error: %v" , fmt .Errorf ("error installing NVIDIA container toolkit config: %v" , err ))
295319 }
296320
297321 return generateCDISpec (opts , nvidiaCTKPath )
@@ -350,7 +374,7 @@ func installLibrary(libName string, toolkitRoot string) error {
350374func installToolkitConfig (c * cli.Context , toolkitConfigPath string , nvidiaContainerCliExecutablePath string , nvidiaCTKPath string , opts * options ) error {
351375 log .Infof ("Installing NVIDIA container toolkit config '%v'" , toolkitConfigPath )
352376
353- config , err := toml . LoadFile (nvidiaContainerToolkitConfigSource )
377+ config , err := loadConfig (nvidiaContainerToolkitConfigSource )
354378 if err != nil {
355379 return fmt .Errorf ("could not open source config file: %v" , err )
356380 }
@@ -431,6 +455,16 @@ func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContai
431455 return nil
432456}
433457
458+ func loadConfig (path string ) (* toml.Tree , error ) {
459+ _ , err := os .Stat (path )
460+ if err == nil {
461+ return toml .LoadFile (path )
462+ } else if os .IsNotExist (err ) {
463+ return toml .TreeFromMap (nil )
464+ }
465+ return nil , err
466+ }
467+
434468// installContainerToolkitCLI installs the nvidia-ctk CLI executable and wrapper.
435469func installContainerToolkitCLI (toolkitDir string ) (string , error ) {
436470 e := executable {
0 commit comments