Skip to content

Commit 4fd94d7

Browse files
authored
Merge pull request #1365 from NVIDIA/install-wrapper-default-runtime-exec-path
invoke the actual default low-level runtime in the nvidia-ctk wrapper script
2 parents f0f9f37 + 733755d commit 4fd94d7

File tree

8 files changed

+52
-15
lines changed

8 files changed

+52
-15
lines changed

cmd/nvidia-ctk-installer/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (a *app) Run(c *cli.Command, o *options) error {
211211
o.toolkitOptions.ContainerRuntimeRuntimes = lowlevelRuntimePaths
212212
}
213213

214-
err = a.toolkit.Install(c, &o.toolkitOptions)
214+
err = a.toolkit.Install(c, &o.toolkitOptions, o.runtime)
215215
if err != nil {
216216
return fmt.Errorf("unable to install toolkit: %v", err)
217217
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ func (t *ToolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
102102
w.Envvars[k] = v
103103
}
104104

105+
if len(t.defaultRuntimeExecutablePath) > 0 {
106+
w.DefaultRuntimeExecutablePath = t.defaultRuntimeExecutablePath
107+
} else {
108+
w.DefaultRuntimeExecutablePath = "runc"
109+
}
110+
105111
installers = append(installers, w)
106112

107113
if executable.symlink == "" {
@@ -119,10 +125,11 @@ func (t *ToolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
119125
}
120126

121127
type wrapper struct {
122-
Source string
123-
Envvars map[string]string
124-
WrappedExecutable string
125-
CheckModules bool
128+
Source string
129+
Envvars map[string]string
130+
WrappedExecutable string
131+
CheckModules bool
132+
DefaultRuntimeExecutablePath string
126133
}
127134

128135
type render struct {
@@ -155,8 +162,8 @@ func (w *render) render() (io.Reader, error) {
155162
{{- if (.CheckModules) }}
156163
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
157164
if [ "${?}" != "0" ]; then
158-
echo "nvidia driver modules are not yet loaded, invoking runc directly"
159-
exec runc "$@"
165+
echo "nvidia driver modules are not yet loaded, invoking {{ .DefaultRuntimeExecutablePath }} directly"
166+
exec {{ .DefaultRuntimeExecutablePath }} "$@"
160167
fi
161168
{{- end }}
162169
{{- 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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"tags.cncf.io/container-device-interface/pkg/cdi"
2727
"tags.cncf.io/container-device-interface/pkg/parser"
2828

29+
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/runtime/crio"
2930
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/toolkit/installer"
3031
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
3132
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
@@ -281,7 +282,7 @@ func (t *Installer) ValidateOptions(opts *Options) error {
281282

282283
// Install installs the components of the NVIDIA container toolkit.
283284
// Any existing installation is removed.
284-
func (t *Installer) Install(cli *cli.Command, opts *Options) error {
285+
func (t *Installer) Install(cli *cli.Command, opts *Options, runtime string) error {
285286
if t == nil {
286287
return fmt.Errorf("toolkit installer is not initilized")
287288
}
@@ -295,18 +296,35 @@ 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+
var defaultRuntimeExecutable string
300+
if len(opts.ContainerRuntimeRuntimes) > 0 {
301+
defaultRuntimeExecutable = opts.ContainerRuntimeRuntimes[0]
302+
}
303+
304+
// If opts.ContainerRuntimeRuntimes is empty (highly unlikely), we fall back to either runc or crun
305+
// depending on the runtime
306+
if len(defaultRuntimeExecutable) == 0 {
307+
if runtime == crio.Name {
308+
defaultRuntimeExecutable = "crun"
309+
} else {
310+
defaultRuntimeExecutable = "runc"
311+
}
312+
}
313+
298314
// Create a toolkit installer to actually install the toolkit components.
299315
toolkit, err := installer.New(
300316
installer.WithLogger(t.logger),
301317
installer.WithSourceRoot(t.sourceRoot),
302318
installer.WithIgnoreErrors(opts.ignoreErrors),
319+
installer.WithDefaultRuntimeExecutablePath(defaultRuntimeExecutable),
303320
)
304321
if err != nil {
305322
if !opts.ignoreErrors {
306323
return fmt.Errorf("could not create toolkit installer: %w", err)
307324
}
308325
t.logger.Errorf("Ignoring error: %v", fmt.Errorf("could not create toolkit installer: %w", err))
309326
}
327+
310328
if err := toolkit.Install(t.toolkitRoot); err != nil {
311329
if !opts.ignoreErrors {
312330
return fmt.Errorf("could not install toolkit components: %w", err)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ containerEdits:
156156
)
157157
require.NoError(t, ti.ValidateOptions(&options))
158158

159-
err := ti.Install(&cli.Command{}, &options)
159+
err := ti.Install(&cli.Command{}, &options, "containerd")
160160
if tc.expectedError == nil {
161161
require.NoError(t, err)
162162
} else {

0 commit comments

Comments
 (0)