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