Skip to content

Commit 91aadb7

Browse files
committed
[no-relnote] Use NVCT_CONFIG_FILE_PATH in toolkit install
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent abf6b8a commit 91aadb7

File tree

5 files changed

+20
-44
lines changed

5 files changed

+20
-44
lines changed

tools/container/toolkit/executable.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type executable struct {
3737
target executableTarget
3838
env map[string]string
3939
preLines []string
40-
argLines []string
4140
}
4241

4342
// install installs an executable component of the NVIDIA container toolkit. The source executable
@@ -128,10 +127,6 @@ func (e executable) writeWrapperTo(wrapper io.Writer, destFolder string, dotfile
128127
// Add the call to the target executable
129128
fmt.Fprintf(wrapper, "%s \\\n", dotfileName)
130129

131-
// Insert additional lines in the `arg` list
132-
for _, line := range e.argLines {
133-
fmt.Fprintf(wrapper, "\t%s \\\n", r.apply(line))
134-
}
135130
// Add the script arguments "$@"
136131
fmt.Fprintln(wrapper, "\t\"$@\"")
137132

tools/container/toolkit/executable_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,6 @@ func TestWrapper(t *testing.T) {
7676
"",
7777
},
7878
},
79-
{
80-
e: executable{
81-
argLines: []string{
82-
"argline1",
83-
"argline2",
84-
},
85-
},
86-
expectedLines: []string{
87-
shebang,
88-
"PATH=/dest/folder:$PATH \\",
89-
"source.real \\",
90-
"\targline1 \\",
91-
"\targline2 \\",
92-
"\t\"$@\"",
93-
"",
94-
},
95-
},
9679
}
9780

9881
for i, tc := range testCases {

tools/container/toolkit/runtime.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"path/filepath"
2222

23+
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
2324
"github.com/NVIDIA/nvidia-container-toolkit/tools/container/operator"
2425
)
2526

@@ -29,10 +30,10 @@ const (
2930

3031
// installContainerRuntimes sets up the NVIDIA container runtimes, copying the executables
3132
// and implementing the required wrapper
32-
func installContainerRuntimes(toolkitDir string, driverRoot string) error {
33+
func installContainerRuntimes(toolkitDir string, configFilePath string) error {
3334
runtimes := operator.GetRuntimes()
3435
for _, runtime := range runtimes {
35-
r := newNvidiaContainerRuntimeInstaller(runtime.Path)
36+
r := newNvidiaContainerRuntimeInstaller(runtime.Path, configFilePath)
3637

3738
_, err := r.install(toolkitDir)
3839
if err != nil {
@@ -46,17 +47,17 @@ func installContainerRuntimes(toolkitDir string, driverRoot string) error {
4647
// This installer will copy the specified source executable to the toolkit directory.
4748
// The executable is copied to a file with the same name as the source, but with a ".real" suffix and a wrapper is
4849
// created to allow for the configuration of the runtime environment.
49-
func newNvidiaContainerRuntimeInstaller(source string) *executable {
50+
func newNvidiaContainerRuntimeInstaller(source string, configFilePath string) *executable {
5051
wrapperName := filepath.Base(source)
5152
dotfileName := wrapperName + ".real"
5253
target := executableTarget{
5354
dotfileName: dotfileName,
5455
wrapperName: wrapperName,
5556
}
56-
return newRuntimeInstaller(source, target, nil)
57+
return newRuntimeInstaller(source, target, configFilePath, nil)
5758
}
5859

59-
func newRuntimeInstaller(source string, target executableTarget, env map[string]string) *executable {
60+
func newRuntimeInstaller(source string, target executableTarget, configFilePath string, env map[string]string) *executable {
6061
preLines := []string{
6162
"",
6263
"cat /proc/modules | grep -e \"^nvidia \" >/dev/null 2>&1",
@@ -68,7 +69,7 @@ func newRuntimeInstaller(source string, target executableTarget, env map[string]
6869
}
6970

7071
runtimeEnv := make(map[string]string)
71-
runtimeEnv["XDG_CONFIG_HOME"] = filepath.Join(destDirPattern, ".config")
72+
runtimeEnv[config.FilePathOverrideEnvVar] = configFilePath
7273
for k, v := range env {
7374
runtimeEnv[k] = v
7475
}

tools/container/toolkit/runtime_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
func TestNvidiaContainerRuntimeInstallerWrapper(t *testing.T) {
28-
r := newNvidiaContainerRuntimeInstaller(nvidiaContainerRuntimeSource)
28+
r := newNvidiaContainerRuntimeInstaller(nvidiaContainerRuntimeSource, "/config/file/path/config.toml")
2929

3030
const shebang = "#! /bin/sh"
3131
const destFolder = "/dest/folder"
@@ -45,8 +45,8 @@ func TestNvidiaContainerRuntimeInstallerWrapper(t *testing.T) {
4545
" exec runc \"$@\"",
4646
"fi",
4747
"",
48+
"NVCTK_CONFIG_FILE_PATH=/config/file/path/config.toml \\",
4849
"PATH=/dest/folder:$PATH \\",
49-
"XDG_CONFIG_HOME=/dest/folder/.config \\",
5050
"source.real \\",
5151
"\t\"$@\"",
5252
"",

tools/container/toolkit/toolkit.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ func Install(cli *cli.Context, opts *Options, toolkitRoot string) error {
297297
log.Errorf("Ignoring error: %v", fmt.Errorf("error removing toolkit directory: %v", err))
298298
}
299299

300-
toolkitConfigDir := filepath.Join(toolkitRoot, ".config", "nvidia-container-runtime")
301-
toolkitConfigPath := filepath.Join(toolkitConfigDir, configFilename)
300+
toolkitConfigFilePath := filepath.Join(toolkitRoot, ".config", config.RelativeFilePath)
302301

303-
err = createDirectories(toolkitRoot, toolkitConfigDir)
302+
err = createDirectories(toolkitRoot, filepath.Dir(toolkitConfigFilePath))
304303
if err != nil && !opts.ignoreErrors {
305304
return fmt.Errorf("could not create required directories: %v", err)
306305
} else if err != nil {
@@ -314,7 +313,7 @@ func Install(cli *cli.Context, opts *Options, toolkitRoot string) error {
314313
log.Errorf("Ignoring error: %v", fmt.Errorf("error installing NVIDIA container library: %v", err))
315314
}
316315

317-
err = installContainerRuntimes(toolkitRoot, opts.DriverRoot)
316+
err = installContainerRuntimes(toolkitRoot, toolkitConfigFilePath)
318317
if err != nil && !opts.ignoreErrors {
319318
return fmt.Errorf("error installing NVIDIA container runtime: %v", err)
320319
} else if err != nil {
@@ -328,7 +327,7 @@ func Install(cli *cli.Context, opts *Options, toolkitRoot string) error {
328327
log.Errorf("Ignoring error: %v", fmt.Errorf("error installing NVIDIA container CLI: %v", err))
329328
}
330329

331-
nvidiaContainerRuntimeHookPath, err := installRuntimeHook(toolkitRoot, toolkitConfigPath)
330+
nvidiaContainerRuntimeHookPath, err := installRuntimeHook(toolkitRoot, toolkitConfigFilePath)
332331
if err != nil && !opts.ignoreErrors {
333332
return fmt.Errorf("error installing NVIDIA container runtime hook: %v", err)
334333
} else if err != nil {
@@ -349,7 +348,7 @@ func Install(cli *cli.Context, opts *Options, toolkitRoot string) error {
349348
log.Errorf("Ignoring error: %v", fmt.Errorf("error installing NVIDIA Container CDI Hook CLI: %v", err))
350349
}
351350

352-
err = installToolkitConfig(cli, toolkitConfigPath, nvidiaContainerCliExecutable, nvidiaCTKPath, nvidiaContainerRuntimeHookPath, opts)
351+
err = installToolkitConfig(cli, toolkitConfigFilePath, nvidiaContainerCliExecutable, nvidiaCTKPath, nvidiaContainerRuntimeHookPath, opts)
353352
if err != nil && !opts.ignoreErrors {
354353
return fmt.Errorf("error installing NVIDIA container toolkit config: %v", err)
355354
} else if err != nil {
@@ -423,8 +422,8 @@ func installLibrary(libName string, toolkitRoot string) error {
423422

424423
// installToolkitConfig installs the config file for the NVIDIA container toolkit ensuring
425424
// that the settings are updated to match the desired install and nvidia driver directories.
426-
func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContainerCliExecutablePath string, nvidiaCTKPath string, nvidaContainerRuntimeHookPath string, opts *Options) error {
427-
log.Infof("Installing NVIDIA container toolkit config '%v'", toolkitConfigPath)
425+
func installToolkitConfig(c *cli.Context, toolkitConfigFilePath string, nvidiaContainerCliExecutablePath string, nvidiaCTKPath string, nvidaContainerRuntimeHookPath string, opts *Options) error {
426+
log.Infof("Installing NVIDIA container toolkit config '%v'", toolkitConfigFilePath)
428427

429428
cfg, err := config.New(
430429
config.WithConfigFile(nvidiaContainerToolkitConfigSource),
@@ -433,7 +432,7 @@ func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContai
433432
return fmt.Errorf("could not open source config file: %v", err)
434433
}
435434

436-
targetConfig, err := os.Create(toolkitConfigPath)
435+
targetConfig, err := os.Create(toolkitConfigFilePath)
437436
if err != nil {
438437
return fmt.Errorf("could not create target config file: %v", err)
439438
}
@@ -579,17 +578,15 @@ func installContainerCLI(toolkitRoot string) (string, error) {
579578
func installRuntimeHook(toolkitRoot string, configFilePath string) (string, error) {
580579
log.Infof("Installing NVIDIA container runtime hook from '%v'", nvidiaContainerRuntimeHookSource)
581580

582-
argLines := []string{
583-
fmt.Sprintf("-config \"%s\"", configFilePath),
584-
}
585-
586581
e := executable{
587582
source: nvidiaContainerRuntimeHookSource,
588583
target: executableTarget{
589584
dotfileName: "nvidia-container-runtime-hook.real",
590585
wrapperName: "nvidia-container-runtime-hook",
591586
},
592-
argLines: argLines,
587+
env: map[string]string{
588+
config.FilePathOverrideEnvVar: configFilePath,
589+
},
593590
}
594591

595592
installedPath, err := e.install(toolkitRoot)

0 commit comments

Comments
 (0)