@@ -20,14 +20,12 @@ import (
20
20
"fmt"
21
21
"os"
22
22
"path/filepath"
23
- "strings"
24
23
25
24
"github.com/urfave/cli/v2"
26
25
"tags.cncf.io/container-device-interface/pkg/cdi"
27
26
"tags.cncf.io/container-device-interface/pkg/parser"
28
27
29
28
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/toolkit/installer"
30
- "github.com/NVIDIA/nvidia-container-toolkit/internal/config"
31
29
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
32
30
"github.com/NVIDIA/nvidia-container-toolkit/internal/system/nvdevices"
33
31
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi"
@@ -38,11 +36,7 @@ const (
38
36
// DefaultNvidiaDriverRoot specifies the default NVIDIA driver run directory
39
37
DefaultNvidiaDriverRoot = "/run/nvidia/driver"
40
38
41
- nvidiaContainerCliSource = "/usr/bin/nvidia-container-cli"
42
- nvidiaContainerRuntimeHookSource = "/usr/bin/nvidia-container-runtime-hook"
43
-
44
39
nvidiaContainerToolkitConfigSource = "/etc/nvidia-container-runtime/config.toml"
45
- configFilename = "config.toml"
46
40
)
47
41
48
42
type cdiOptions struct {
@@ -319,20 +313,7 @@ func (t *Installer) Install(cli *cli.Context, opts *Options) error {
319
313
t .logger .Errorf ("Ignoring error: %v" , fmt .Errorf ("could not install toolkit components: %w" , err ))
320
314
}
321
315
322
- toolkitConfigDir := filepath .Join (t .toolkitRoot , ".config" , "nvidia-container-runtime" )
323
- toolkitConfigPath := filepath .Join (toolkitConfigDir , configFilename )
324
-
325
- err = t .createDirectories (toolkitConfigDir )
326
- if err != nil && ! opts .ignoreErrors {
327
- return fmt .Errorf ("could not create required directories: %v" , err )
328
- } else if err != nil {
329
- t .logger .Errorf ("Ignoring error: %v" , fmt .Errorf ("could not create required directories: %v" , err ))
330
- }
331
- nvidiaContainerCliExecutable := filepath .Join (t .toolkitRoot , "nvidia-container-cli" )
332
- nvidiaCTKPath := filepath .Join (t .toolkitRoot , "nvidia-ctk" )
333
- nvidiaCDIHookPath := filepath .Join (t .toolkitRoot , "nvidia-cdi-hook" )
334
- nvidiaContainerRuntimeHookPath := filepath .Join (t .toolkitRoot , "nvidia-container-runtime-hook" )
335
- err = t .installToolkitConfig (cli , toolkitConfigPath , nvidiaContainerCliExecutable , nvidiaCTKPath , nvidiaContainerRuntimeHookPath , opts )
316
+ err = t .installToolkitConfig (cli , opts )
336
317
if err != nil && ! opts .ignoreErrors {
337
318
return fmt .Errorf ("error installing NVIDIA container toolkit config: %v" , err )
338
319
} else if err != nil {
@@ -346,6 +327,7 @@ func (t *Installer) Install(cli *cli.Context, opts *Options) error {
346
327
t .logger .Errorf ("Ignoring error: %v" , fmt .Errorf ("error creating device nodes: %v" , err ))
347
328
}
348
329
330
+ nvidiaCDIHookPath := filepath .Join (t .toolkitRoot , "nvidia-cdi-hook" )
349
331
err = t .generateCDISpec (opts , nvidiaCDIHookPath )
350
332
if err != nil && ! opts .ignoreErrors {
351
333
return fmt .Errorf ("error generating CDI specification: %v" , err )
@@ -356,108 +338,6 @@ func (t *Installer) Install(cli *cli.Context, opts *Options) error {
356
338
return nil
357
339
}
358
340
359
- // installToolkitConfig installs the config file for the NVIDIA container toolkit ensuring
360
- // that the settings are updated to match the desired install and nvidia driver directories.
361
- func (t * Installer ) installToolkitConfig (c * cli.Context , toolkitConfigPath string , nvidiaContainerCliExecutablePath string , nvidiaCTKPath string , nvidaContainerRuntimeHookPath string , opts * Options ) error {
362
- t .logger .Infof ("Installing NVIDIA container toolkit config '%v'" , toolkitConfigPath )
363
-
364
- cfg , err := config .New (
365
- config .WithConfigFile (nvidiaContainerToolkitConfigSource ),
366
- )
367
- if err != nil {
368
- return fmt .Errorf ("could not open source config file: %v" , err )
369
- }
370
-
371
- targetConfig , err := os .Create (toolkitConfigPath )
372
- if err != nil {
373
- return fmt .Errorf ("could not create target config file: %v" , err )
374
- }
375
- defer targetConfig .Close ()
376
-
377
- // Read the ldconfig path from the config as this may differ per platform
378
- // On ubuntu-based systems this ends in `.real`
379
- ldconfigPath := fmt .Sprintf ("%s" , cfg .GetDefault ("nvidia-container-cli.ldconfig" , "/sbin/ldconfig" ))
380
- // Use the driver run root as the root:
381
- driverLdconfigPath := config .NormalizeLDConfigPath ("@" + filepath .Join (opts .DriverRoot , strings .TrimPrefix (ldconfigPath , "@/" )))
382
-
383
- configValues := map [string ]interface {}{
384
- // Set the options in the root toml table
385
- "accept-nvidia-visible-devices-envvar-when-unprivileged" : opts .acceptNVIDIAVisibleDevicesWhenUnprivileged ,
386
- "accept-nvidia-visible-devices-as-volume-mounts" : opts .acceptNVIDIAVisibleDevicesAsVolumeMounts ,
387
- // Set the nvidia-container-cli options
388
- "nvidia-container-cli.root" : opts .DriverRoot ,
389
- "nvidia-container-cli.path" : nvidiaContainerCliExecutablePath ,
390
- "nvidia-container-cli.ldconfig" : driverLdconfigPath ,
391
- // Set nvidia-ctk options
392
- "nvidia-ctk.path" : nvidiaCTKPath ,
393
- // Set the nvidia-container-runtime-hook options
394
- "nvidia-container-runtime-hook.path" : nvidaContainerRuntimeHookPath ,
395
- "nvidia-container-runtime-hook.skip-mode-detection" : opts .ContainerRuntimeHookSkipModeDetection ,
396
- }
397
-
398
- toolkitRuntimeList := opts .ContainerRuntimeRuntimes .Value ()
399
- if len (toolkitRuntimeList ) > 0 {
400
- configValues ["nvidia-container-runtime.runtimes" ] = toolkitRuntimeList
401
- }
402
-
403
- for _ , optInFeature := range opts .optInFeatures .Value () {
404
- configValues ["features." + optInFeature ] = true
405
- }
406
-
407
- for key , value := range configValues {
408
- cfg .Set (key , value )
409
- }
410
-
411
- // Set the optional config options
412
- optionalConfigValues := map [string ]interface {}{
413
- "nvidia-container-runtime.debug" : opts .ContainerRuntimeDebug ,
414
- "nvidia-container-runtime.log-level" : opts .ContainerRuntimeLogLevel ,
415
- "nvidia-container-runtime.mode" : opts .ContainerRuntimeMode ,
416
- "nvidia-container-runtime.modes.cdi.annotation-prefixes" : opts .ContainerRuntimeModesCDIAnnotationPrefixes ,
417
- "nvidia-container-runtime.modes.cdi.default-kind" : opts .ContainerRuntimeModesCdiDefaultKind ,
418
- "nvidia-container-runtime.runtimes" : opts .ContainerRuntimeRuntimes ,
419
- "nvidia-container-cli.debug" : opts .ContainerCLIDebug ,
420
- }
421
-
422
- for key , value := range optionalConfigValues {
423
- if ! c .IsSet (key ) {
424
- t .logger .Infof ("Skipping unset option: %v" , key )
425
- continue
426
- }
427
- if value == nil {
428
- t .logger .Infof ("Skipping option with nil value: %v" , key )
429
- continue
430
- }
431
-
432
- switch v := value .(type ) {
433
- case string :
434
- if v == "" {
435
- continue
436
- }
437
- case cli.StringSlice :
438
- if len (v .Value ()) == 0 {
439
- continue
440
- }
441
- value = v .Value ()
442
- default :
443
- t .logger .Warningf ("Unexpected type for option %v=%v: %T" , key , value , v )
444
- }
445
-
446
- cfg .Set (key , value )
447
- }
448
-
449
- if _ , err := cfg .WriteTo (targetConfig ); err != nil {
450
- return fmt .Errorf ("error writing config: %v" , err )
451
- }
452
-
453
- os .Stdout .WriteString ("Using config:\n " )
454
- if _ , err = cfg .WriteTo (os .Stdout ); err != nil {
455
- t .logger .Warningf ("Failed to output config to STDOUT: %v" , err )
456
- }
457
-
458
- return nil
459
- }
460
-
461
341
func (t * Installer ) createDirectories (dir ... string ) error {
462
342
for _ , d := range dir {
463
343
t .logger .Infof ("Creating directory '%v'" , d )
0 commit comments