Skip to content

Commit aea4607

Browse files
committed
invoke the actual default low-level runtime in the nvidia-ctk wrapper script
Signed-off-by: Tariq Ibrahim <[email protected]>
1 parent f0f9f37 commit aea4607

File tree

6 files changed

+54
-15
lines changed

6 files changed

+54
-15
lines changed

cmd/nvidia-ctk-installer/toolkit/installer/executables.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ func (t *ToolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
9191
dotRealFilename := wrappedExecutableFilename + ".real"
9292

9393
w := &wrapper{
94-
Source: executablePath,
95-
WrappedExecutable: dotRealFilename,
96-
CheckModules: executable.requiresKernelModule,
94+
Source: executablePath,
95+
WrappedExecutable: dotRealFilename,
96+
CheckModules: executable.requiresKernelModule,
97+
DefaultRuntimeExecutablePath: t.defaultRuntimeExecutablePath,
9798
Envvars: map[string]string{
9899
"PATH": strings.Join([]string{destDir, "$PATH"}, ":"),
99100
},
@@ -119,10 +120,11 @@ func (t *ToolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
119120
}
120121

121122
type wrapper struct {
122-
Source string
123-
Envvars map[string]string
124-
WrappedExecutable string
125-
CheckModules bool
123+
Source string
124+
Envvars map[string]string
125+
WrappedExecutable string
126+
CheckModules bool
127+
DefaultRuntimeExecutablePath string
126128
}
127129

128130
type render struct {
@@ -155,8 +157,8 @@ func (w *render) render() (io.Reader, error) {
155157
{{- if (.CheckModules) }}
156158
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
157159
if [ "${?}" != "0" ]; then
158-
echo "nvidia driver modules are not yet loaded, invoking runc directly"
159-
exec runc "$@"
160+
echo "nvidia driver modules are not yet loaded, invoking {{ .DefaultRuntimeExecutablePath }} directly"
161+
exec {{ .DefaultRuntimeExecutablePath }} "$@"
160162
fi
161163
{{- end }}
162164
{{- range $key, $value := .Envvars }}

cmd/nvidia-ctk-installer/toolkit/installer/executables_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func TestWrapperRender(t *testing.T) {
3333
{
3434
description: "executable is added",
3535
w: &wrapper{
36-
WrappedExecutable: "some-runtime",
36+
WrappedExecutable: "some-runtime",
37+
DefaultRuntimeExecutablePath: "runc",
3738
},
3839
expected: `#! /bin/sh
3940
/dest-dir/some-runtime \
@@ -43,8 +44,9 @@ func TestWrapperRender(t *testing.T) {
4344
{
4445
description: "module check is added",
4546
w: &wrapper{
46-
WrappedExecutable: "some-runtime",
47-
CheckModules: true,
47+
WrappedExecutable: "some-runtime",
48+
CheckModules: true,
49+
DefaultRuntimeExecutablePath: "runc",
4850
},
4951
expected: `#! /bin/sh
5052
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
@@ -63,6 +65,7 @@ fi
6365
Envvars: map[string]string{
6466
"PATH": "/foo/bar/baz",
6567
},
68+
DefaultRuntimeExecutablePath: "runc",
6669
},
6770
expected: `#! /bin/sh
6871
PATH=/foo/bar/baz \

cmd/nvidia-ctk-installer/toolkit/installer/installer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type ToolkitInstaller struct {
4141
artifactRoot *artifactRoot
4242

4343
ensureTargetDirectory Installer
44+
45+
defaultRuntimeExecutablePath string
4446
}
4547

4648
var _ Installer = (*ToolkitInstaller)(nil)

cmd/nvidia-ctk-installer/toolkit/installer/installer_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ func TestToolkitInstaller(t *testing.T) {
113113
},
114114
}
115115
i := ToolkitInstaller{
116-
logger: logger,
117-
artifactRoot: r,
118-
ensureTargetDirectory: createDirectory,
116+
logger: logger,
117+
artifactRoot: r,
118+
ensureTargetDirectory: createDirectory,
119+
defaultRuntimeExecutablePath: "runc",
119120
}
120121

121122
err := i.Install("/foo/bar/baz")

cmd/nvidia-ctk-installer/toolkit/installer/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ func WithSourceRoot(sourceRoot string) Option {
4545
ti.sourceRoot = sourceRoot
4646
}
4747
}
48+
49+
func WithDefaultRuntimeExecutablePath(path string) Option {
50+
return func(ti *ToolkitInstaller) {
51+
ti.defaultRuntimeExecutablePath = path
52+
}
53+
}

cmd/nvidia-ctk-installer/toolkit/toolkit.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package toolkit
1919
import (
2020
"fmt"
2121
"os"
22+
"os/exec"
2223
"path/filepath"
2324
"strings"
2425

@@ -295,18 +296,42 @@ func (t *Installer) Install(cli *cli.Command, opts *Options) error {
295296
t.logger.Errorf("Ignoring error: %v", fmt.Errorf("error removing toolkit directory: %v", err))
296297
}
297298

299+
// Loop through the low-level runtime binary paths and pick the first valid PATH resolvable runtime binary
300+
// as the fallback for the nvidia-container-runtime wrapper
301+
var defaultRuntimeExecutable string
302+
t.logger.Infof("WE HAVE container runtimes: %v", opts.ContainerRuntimeRuntimes)
303+
if len(opts.ContainerRuntimeRuntimes) > 0 {
304+
for _, r := range opts.ContainerRuntimeRuntimes {
305+
t.logger.Infof("CHECKING container runtime: %s", r)
306+
_, err := exec.LookPath(r)
307+
if err == nil {
308+
defaultRuntimeExecutable = r
309+
break
310+
}
311+
}
312+
}
313+
314+
// If there are no valid low-level runtime binaries from opts.ContainerRuntimeRuntimes (highly unlikely),
315+
// we fall back to old default "runc"
316+
if len(defaultRuntimeExecutable) == 0 {
317+
t.logger.Infof("SHOULD NOT ENTER HERE")
318+
defaultRuntimeExecutable = "runc"
319+
}
320+
298321
// Create a toolkit installer to actually install the toolkit components.
299322
toolkit, err := installer.New(
300323
installer.WithLogger(t.logger),
301324
installer.WithSourceRoot(t.sourceRoot),
302325
installer.WithIgnoreErrors(opts.ignoreErrors),
326+
installer.WithDefaultRuntimeExecutablePath(defaultRuntimeExecutable),
303327
)
304328
if err != nil {
305329
if !opts.ignoreErrors {
306330
return fmt.Errorf("could not create toolkit installer: %w", err)
307331
}
308332
t.logger.Errorf("Ignoring error: %v", fmt.Errorf("could not create toolkit installer: %w", err))
309333
}
334+
310335
if err := toolkit.Install(t.toolkitRoot); err != nil {
311336
if !opts.ignoreErrors {
312337
return fmt.Errorf("could not install toolkit components: %w", err)

0 commit comments

Comments
 (0)