Skip to content

Commit

Permalink
Use require-nvidia-kernel-modules feature for toolkit installation
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Lezar <[email protected]>
  • Loading branch information
elezar committed Oct 30, 2024
1 parent 7263d26 commit bf34b13
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 44 deletions.
6 changes: 0 additions & 6 deletions tools/container/toolkit/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type executable struct {
source string
target executableTarget
env map[string]string
preLines []string
argLines []string
}

Expand Down Expand Up @@ -96,11 +95,6 @@ func (e executable) writeWrapperTo(wrapper io.Writer, destFolder string, dotfile
// Add the shebang
fmt.Fprintln(wrapper, "#! /bin/sh")

// Add the preceding lines if any
for _, line := range e.preLines {
fmt.Fprintf(wrapper, "%s\n", r.apply(line))
}

// Update the path to include the destination folder
var env map[string]string
if e.env == nil {
Expand Down
17 changes: 0 additions & 17 deletions tools/container/toolkit/executable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,6 @@ func TestWrapper(t *testing.T) {
"",
},
},
{
e: executable{
preLines: []string{
"preline1",
"preline2",
},
},
expectedLines: []string{
shebang,
"preline1",
"preline2",
"PATH=/dest/folder:$PATH \\",
"source.real \\",
"\t\"$@\"",
"",
},
},
{
e: executable{
argLines: []string{
Expand Down
17 changes: 3 additions & 14 deletions tools/container/toolkit/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,16 @@ func newNvidiaContainerRuntimeInstaller(source string) *executable {
}

func newRuntimeInstaller(source string, target executableTarget, env map[string]string) *executable {
preLines := []string{
"",
"cat /proc/modules | grep -e \"^nvidia \" >/dev/null 2>&1",
"if [ \"${?}\" != \"0\" ]; then",
" echo \"nvidia driver modules are not yet loaded, invoking runc directly\"",
" exec runc \"$@\"",
"fi",
"",
}

runtimeEnv := make(map[string]string)
runtimeEnv["XDG_CONFIG_HOME"] = filepath.Join(destDirPattern, ".config")
for k, v := range env {
runtimeEnv[k] = v
}

r := executable{
source: source,
target: target,
env: runtimeEnv,
preLines: preLines,
source: source,
target: target,
env: runtimeEnv,
}

return &r
Expand Down
7 changes: 0 additions & 7 deletions tools/container/toolkit/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ func TestNvidiaContainerRuntimeInstallerWrapper(t *testing.T) {

expectedLines := []string{
shebang,
"",
"cat /proc/modules | grep -e \"^nvidia \" >/dev/null 2>&1",
"if [ \"${?}\" != \"0\" ]; then",
" echo \"nvidia driver modules are not yet loaded, invoking runc directly\"",
" exec runc \"$@\"",
"fi",
"",
"PATH=/dest/folder:$PATH \\",
"XDG_CONFIG_HOME=/dest/folder/.config \\",
"source.real \\",
Expand Down
2 changes: 2 additions & 0 deletions tools/container/toolkit/toolkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContai
// Set the nvidia-container-runtime-hook options
"nvidia-container-runtime-hook.path": nvidaContainerRuntimeHookPath,
"nvidia-container-runtime-hook.skip-mode-detection": opts.ContainerRuntimeHookSkipModeDetection,
// We require the NVIDIA kernel modules to be loaded.
"features.require-nvidia-kernel-modules": true,
}

toolkitRuntimeList := opts.ContainerRuntimeRuntimes.Value()
Expand Down

0 comments on commit bf34b13

Please sign in to comment.