Skip to content

Commit 9255c9c

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

File tree

3 files changed

+49
-60
lines changed

3 files changed

+49
-60
lines changed

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

+23-9
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,31 @@ 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
143-
156+
{{- if (.CheckModules) }}
144157
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
145158
if [ "${?}" != "0" ]; then
146159
echo "nvidia driver modules are not yet loaded, invoking runc directly"
147160
exec runc "$@"
148161
fi
162+
{{- end }}
149163
{{- range $key, $value := .Envvars }}
150164
{{$key}}={{$value}} \
151165
{{- end }}
152-
{{ .WrappedExecutable }} \
166+
{{ .DestDir }}/{{ .WrappedExecutable }} \
153167
{{- range $arg := .Args }}
154168
{{$arg}} \
155169
{{- end }}

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

+19-17
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,23 @@ func TestWrapperRender(t *testing.T) {
3535
WrappedExecutable: "some-runtime",
3636
},
3737
expected: `#! /bin/sh
38-
38+
/dest-dir/some-runtime \
39+
"$@"
40+
`,
41+
},
42+
{
43+
description: "module check is added",
44+
w: &wrapper{
45+
WrappedExecutable: "some-runtime",
46+
CheckModules: true,
47+
},
48+
expected: `#! /bin/sh
3949
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
4050
if [ "${?}" != "0" ]; then
4151
echo "nvidia driver modules are not yet loaded, invoking runc directly"
4252
exec runc "$@"
4353
fi
44-
some-runtime \
54+
/dest-dir/some-runtime \
4555
"$@"
4656
`,
4757
},
@@ -54,14 +64,8 @@ fi
5464
},
5565
},
5666
expected: `#! /bin/sh
57-
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
6367
PATH=/foo/bar/baz \
64-
some-runtime \
68+
/dest-dir/some-runtime \
6569
"$@"
6670
`,
6771
},
@@ -72,13 +76,7 @@ PATH=/foo/bar/baz \
7276
Args: []string{"--config foo", "bar"},
7377
},
7478
expected: `#! /bin/sh
75-
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 \
79+
/dest-dir/some-runtime \
8280
--config foo \
8381
bar \
8482
"$@"
@@ -88,7 +86,11 @@ fi
8886

8987
for _, tc := range testCases {
9088
t.Run(tc.description, func(t *testing.T) {
91-
reader, err := tc.w.render()
89+
r := render{
90+
wrapper: tc.w,
91+
DestDir: "/dest-dir",
92+
}
93+
reader, err := r.render()
9294
require.NoError(t, err)
9395

9496
var content bytes.Buffer

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

+7-34
Original file line numberDiff line numberDiff line change
@@ -166,108 +166,81 @@ func TestToolkitInstaller(t *testing.T) {
166166
path: "/foo/bar/baz/nvidia-container-runtime",
167167
mode: 0777,
168168
wrapper: `#! /bin/sh
169-
170169
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
171170
if [ "${?}" != "0" ]; then
172171
echo "nvidia driver modules are not yet loaded, invoking runc directly"
173172
exec runc "$@"
174173
fi
175174
PATH=/foo/bar/baz:$PATH \
176175
XDG_CONFIG_HOME=/foo/bar/baz/.config \
177-
nvidia-container-runtime.real \
176+
/foo/bar/baz/nvidia-container-runtime.real \
178177
"$@"
179178
`,
180179
},
181180
{
182181
path: "/foo/bar/baz/nvidia-container-runtime.cdi",
183182
mode: 0777,
184183
wrapper: `#! /bin/sh
185-
186184
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
187185
if [ "${?}" != "0" ]; then
188186
echo "nvidia driver modules are not yet loaded, invoking runc directly"
189187
exec runc "$@"
190188
fi
191189
PATH=/foo/bar/baz:$PATH \
192190
XDG_CONFIG_HOME=/foo/bar/baz/.config \
193-
nvidia-container-runtime.cdi.real \
191+
/foo/bar/baz/nvidia-container-runtime.cdi.real \
194192
"$@"
195193
`,
196194
},
197195
{
198196
path: "/foo/bar/baz/nvidia-container-runtime.legacy",
199197
mode: 0777,
200198
wrapper: `#! /bin/sh
201-
202199
cat /proc/modules | grep -e "^nvidia " >/dev/null 2>&1
203200
if [ "${?}" != "0" ]; then
204201
echo "nvidia driver modules are not yet loaded, invoking runc directly"
205202
exec runc "$@"
206203
fi
207204
PATH=/foo/bar/baz:$PATH \
208205
XDG_CONFIG_HOME=/foo/bar/baz/.config \
209-
nvidia-container-runtime.legacy.real \
206+
/foo/bar/baz/nvidia-container-runtime.legacy.real \
210207
"$@"
211208
`,
212209
},
213210
{
214211
path: "/foo/bar/baz/nvidia-ctk",
215212
mode: 0777,
216213
wrapper: `#! /bin/sh
217-
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
223214
PATH=/foo/bar/baz:$PATH \
224-
nvidia-ctk.real \
215+
/foo/bar/baz/nvidia-ctk.real \
225216
"$@"
226217
`,
227218
},
228219
{
229220
path: "/foo/bar/baz/nvidia-cdi-hook",
230221
mode: 0777,
231222
wrapper: `#! /bin/sh
232-
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
238223
PATH=/foo/bar/baz:$PATH \
239-
nvidia-cdi-hook.real \
224+
/foo/bar/baz/nvidia-cdi-hook.real \
240225
"$@"
241226
`,
242227
},
243228
{
244229
path: "/foo/bar/baz/nvidia-container-cli",
245230
mode: 0777,
246231
wrapper: `#! /bin/sh
247-
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
253232
LD_LIBRARY_PATH=/foo/bar/baz:$LD_LIBRARY_PATH \
254233
PATH=/foo/bar/baz:$PATH \
255-
nvidia-container-cli.real \
234+
/foo/bar/baz/nvidia-container-cli.real \
256235
"$@"
257236
`,
258237
},
259238
{
260239
path: "/foo/bar/baz/nvidia-container-runtime-hook",
261240
mode: 0777,
262241
wrapper: `#! /bin/sh
263-
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
269242
PATH=/foo/bar/baz:$PATH \
270-
nvidia-container-runtime-hook.real \
243+
/foo/bar/baz/nvidia-container-runtime-hook.real \
271244
-config /foo/bar/baz/.config/nvidia-container-runtime/config.toml \
272245
"$@"
273246
`,

0 commit comments

Comments
 (0)