Skip to content

Commit 772bc62

Browse files
committed
Fix paths
Signed-off-by: Evan Lezar <[email protected]>
1 parent 3e32c7e commit 772bc62

File tree

3 files changed

+57
-49
lines changed

3 files changed

+57
-49
lines changed

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

+23-8
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import (
3030
)
3131

3232
type executable struct {
33-
path string
34-
symlink string
35-
args []string
36-
env map[string]string
33+
requiresKernelModule bool
34+
path string
35+
symlink string
36+
args []string
37+
env map[string]string
3738
}
3839

3940
func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, error) {
@@ -51,7 +52,8 @@ func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
5152
}
5253
for _, runtime := range operator.GetRuntimes() {
5354
e := executable{
54-
path: runtime.Path,
55+
path: runtime.Path,
56+
requiresKernelModule: true,
5557
env: map[string]string{
5658
"XDG_CONFIG_HOME": configHome,
5759
},
@@ -90,6 +92,7 @@ func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
9092
w := &wrapper{
9193
Source: executablePath,
9294
WrappedExecutable: dotRealFilename,
95+
CheckModules: executable.requiresKernelModule,
9396
Args: executable.args,
9497
Envvars: map[string]string{
9598
"PATH": strings.Join([]string{destDir, "$PATH"}, ":"),
@@ -119,9 +122,15 @@ type wrapper struct {
119122
Source string
120123
Envvars map[string]string
121124
WrappedExecutable string
125+
CheckModules bool
122126
Args []string
123127
}
124128

129+
type render struct {
130+
*wrapper
131+
DestDir string
132+
}
133+
125134
func (w *wrapper) Install(destDir string) error {
126135
// Copy the executable with a .real extension.
127136
mode, err := installFile(w.Source, filepath.Join(destDir, w.WrappedExecutable))
@@ -130,26 +139,32 @@ func (w *wrapper) Install(destDir string) error {
130139
}
131140

132141
// Create a wrapper file.
133-
content, err := w.render()
142+
r := render{
143+
wrapper: w,
144+
DestDir: destDir,
145+
}
146+
content, err := r.render()
134147
if err != nil {
135148
return nil
136149
}
137150
wrapperFile := filepath.Join(destDir, filepath.Base(w.Source))
138151
return installContent(content, wrapperFile, mode|0111)
139152
}
140153

141-
func (w *wrapper) render() (io.Reader, error) {
154+
func (w *render) render() (io.Reader, error) {
142155
wrapperTemplate := `#! /bin/sh
143156
157+
{{ if (.CheckModules) -}}
144158
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
145159
if [ "${?}" != "0" ]; then
146160
echo "nvidia driver modules are not yet loaded, invoking runc directly"
147161
exec runc "$@"
148162
fi
163+
{{- end -}}
149164
{{- range $key, $value := .Envvars }}
150165
{{$key}}={{$value}} \
151166
{{- end }}
152-
{{ .WrappedExecutable }} \
167+
{{ .DestDir }}/{{ .WrappedExecutable }} \
153168
{{- range $arg := .Args }}
154169
{{$arg}} \
155170
{{- end }}

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

+23-14
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,25 @@ func TestWrapperRender(t *testing.T) {
3636
},
3737
expected: `#! /bin/sh
3838
39+
40+
/dest-dir/some-runtime \
41+
"$@"
42+
`,
43+
},
44+
{
45+
description: "module check is added",
46+
w: &wrapper{
47+
WrappedExecutable: "some-runtime",
48+
CheckModules: true,
49+
},
50+
expected: `#! /bin/sh
51+
3952
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
4053
if [ "${?}" != "0" ]; then
4154
echo "nvidia driver modules are not yet loaded, invoking runc directly"
4255
exec runc "$@"
4356
fi
44-
some-runtime \
57+
/dest-dir/some-runtime \
4558
"$@"
4659
`,
4760
},
@@ -55,13 +68,9 @@ fi
5568
},
5669
expected: `#! /bin/sh
5770
58-
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
59-
if [ "${?}" != "0" ]; then
60-
echo "nvidia driver modules are not yet loaded, invoking runc directly"
61-
exec runc "$@"
62-
fi
71+
6372
PATH=/foo/bar/baz \
64-
some-runtime \
73+
/dest-dir/some-runtime \
6574
"$@"
6675
`,
6776
},
@@ -73,12 +82,8 @@ PATH=/foo/bar/baz \
7382
},
7483
expected: `#! /bin/sh
7584
76-
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
77-
if [ "${?}" != "0" ]; then
78-
echo "nvidia driver modules are not yet loaded, invoking runc directly"
79-
exec runc "$@"
80-
fi
81-
some-runtime \
85+
86+
/dest-dir/some-runtime \
8287
--config foo \
8388
bar \
8489
"$@"
@@ -88,7 +93,11 @@ fi
8893

8994
for _, tc := range testCases {
9095
t.Run(tc.description, func(t *testing.T) {
91-
reader, err := tc.w.render()
96+
r := render{
97+
wrapper: tc.w,
98+
DestDir: "/dest-dir",
99+
}
100+
reader, err := r.render()
92101
require.NoError(t, err)
93102

94103
var content bytes.Buffer

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

+11-27
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ if [ "${?}" != "0" ]; then
174174
fi
175175
PATH=/foo/bar/baz:$PATH \
176176
XDG_CONFIG_HOME=/foo/bar/baz/.config \
177-
nvidia-container-runtime.real \
177+
/foo/bar/baz/nvidia-container-runtime.real \
178178
"$@"
179179
`,
180180
},
@@ -190,7 +190,7 @@ if [ "${?}" != "0" ]; then
190190
fi
191191
PATH=/foo/bar/baz:$PATH \
192192
XDG_CONFIG_HOME=/foo/bar/baz/.config \
193-
nvidia-container-runtime.cdi.real \
193+
/foo/bar/baz/nvidia-container-runtime.cdi.real \
194194
"$@"
195195
`,
196196
},
@@ -206,7 +206,7 @@ if [ "${?}" != "0" ]; then
206206
fi
207207
PATH=/foo/bar/baz:$PATH \
208208
XDG_CONFIG_HOME=/foo/bar/baz/.config \
209-
nvidia-container-runtime.legacy.real \
209+
/foo/bar/baz/nvidia-container-runtime.legacy.real \
210210
"$@"
211211
`,
212212
},
@@ -215,13 +215,9 @@ XDG_CONFIG_HOME=/foo/bar/baz/.config \
215215
mode: 0777,
216216
wrapper: `#! /bin/sh
217217
218-
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
219-
if [ "${?}" != "0" ]; then
220-
echo "nvidia driver modules are not yet loaded, invoking runc directly"
221-
exec runc "$@"
222-
fi
218+
223219
PATH=/foo/bar/baz:$PATH \
224-
nvidia-ctk.real \
220+
/foo/bar/baz/nvidia-ctk.real \
225221
"$@"
226222
`,
227223
},
@@ -230,13 +226,9 @@ PATH=/foo/bar/baz:$PATH \
230226
mode: 0777,
231227
wrapper: `#! /bin/sh
232228
233-
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
234-
if [ "${?}" != "0" ]; then
235-
echo "nvidia driver modules are not yet loaded, invoking runc directly"
236-
exec runc "$@"
237-
fi
229+
238230
PATH=/foo/bar/baz:$PATH \
239-
nvidia-cdi-hook.real \
231+
/foo/bar/baz/nvidia-cdi-hook.real \
240232
"$@"
241233
`,
242234
},
@@ -245,14 +237,10 @@ PATH=/foo/bar/baz:$PATH \
245237
mode: 0777,
246238
wrapper: `#! /bin/sh
247239
248-
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
249-
if [ "${?}" != "0" ]; then
250-
echo "nvidia driver modules are not yet loaded, invoking runc directly"
251-
exec runc "$@"
252-
fi
240+
253241
LD_LIBRARY_PATH=/foo/bar/baz:$LD_LIBRARY_PATH \
254242
PATH=/foo/bar/baz:$PATH \
255-
nvidia-container-cli.real \
243+
/foo/bar/baz/nvidia-container-cli.real \
256244
"$@"
257245
`,
258246
},
@@ -261,13 +249,9 @@ PATH=/foo/bar/baz:$PATH \
261249
mode: 0777,
262250
wrapper: `#! /bin/sh
263251
264-
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
265-
if [ "${?}" != "0" ]; then
266-
echo "nvidia driver modules are not yet loaded, invoking runc directly"
267-
exec runc "$@"
268-
fi
252+
269253
PATH=/foo/bar/baz:$PATH \
270-
nvidia-container-runtime-hook.real \
254+
/foo/bar/baz/nvidia-container-runtime-hook.real \
271255
-config /foo/bar/baz/.config/nvidia-container-runtime/config.toml \
272256
"$@"
273257
`,

0 commit comments

Comments
 (0)