Skip to content

Commit 3570e10

Browse files
committed
cmd/initContainer: Unbreak application of CDI hooks for NVIDIA
NVIDIA Container Toolkit 0.16.0 changed the hook arguments in the Container Device Interface specification generated by it [1]. Fallout from 649d02f [1] NVIDIA Container Toolkit commit 179d8655f9b5fce6 NVIDIA/nvidia-container-toolkit@179d8655f9b5fce6 NVIDIA/nvidia-container-toolkit#435
1 parent c386a44 commit 3570e10

11 files changed

+19
-72
lines changed

src/cmd/initContainer.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,9 @@ func applyCDISpecForNvidia(spec *specs.Spec) error {
474474
continue
475475
}
476476

477-
if len(hook.Args) < 3 ||
478-
hook.Args[0] != "nvidia-ctk" ||
479-
hook.Args[1] != "hook" ||
480-
hook.Args[2] != "update-ldcache" {
477+
if len(hook.Args) < 2 ||
478+
hook.Args[0] != "nvidia-cdi-hook" ||
479+
hook.Args[1] != "update-ldcache" {
481480
logrus.Debug("Applying Container Device Interface for NVIDIA: unknown hook arguments:")
482481
for _, arg := range hook.Args {
483482
logrus.Debugf("%s", arg)
@@ -488,7 +487,7 @@ func applyCDISpecForNvidia(spec *specs.Spec) error {
488487

489488
var folderFlag bool
490489
var folders []string
491-
hookArgs := hook.Args[3:]
490+
hookArgs := hook.Args[2:]
492491

493492
for _, hookArg := range hookArgs {
494493
if hookArg == "--folder" {

test/system/230-cdi.bats

+1-30
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ teardown() {
280280
assert [ ${#stderr_lines[@]} -eq 0 ]
281281
}
282282

283-
@test "cdi: Try hook with unknown args (a)" {
283+
@test "cdi: Try hook with unknown args" {
284284
local toolbx_runtime_directory="$XDG_RUNTIME_DIR/toolbox"
285285

286286
create_default_container
@@ -309,35 +309,6 @@ teardown() {
309309
assert [ ${#stderr_lines[@]} -eq 0 ]
310310
}
311311

312-
@test "cdi: Try hook with unknown args (b)" {
313-
local toolbx_runtime_directory="$XDG_RUNTIME_DIR/toolbox"
314-
315-
create_default_container
316-
317-
# shellcheck disable=SC2174
318-
mkdir --mode 700 --parents "$toolbx_runtime_directory"
319-
320-
cp "$BATS_TEST_DIRNAME/data/cdi-hooks-13.json" "$toolbx_runtime_directory/cdi-nvidia.json"
321-
chmod 644 "$toolbx_runtime_directory/cdi-nvidia.json"
322-
323-
run --keep-empty-lines --separate-stderr "$TOOLBX" run \
324-
test /etc/ld.so.cache -ot "$toolbx_runtime_directory/cdi-nvidia.json"
325-
326-
if ! cmp --silent "$BATS_TEST_DIRNAME/data/cdi-hooks-13.json" "$toolbx_runtime_directory/cdi-nvidia.json"; then
327-
skip "found NVIDIA hardware"
328-
fi
329-
330-
assert_success
331-
assert [ ${#lines[@]} -eq 0 ]
332-
assert [ ${#stderr_lines[@]} -eq 0 ]
333-
334-
run --keep-empty-lines --separate-stderr "$TOOLBX" run test -e /etc/ld.so.conf.d/toolbx-nvidia.conf
335-
336-
assert_failure
337-
assert [ ${#lines[@]} -eq 0 ]
338-
assert [ ${#stderr_lines[@]} -eq 0 ]
339-
}
340-
341312
@test "cdi: Try hook with invalid name" {
342313
local toolbx_runtime_directory="$XDG_RUNTIME_DIR/toolbox"
343314

test/system/data/cdi-hooks-00.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"hooks": [
44
{
55
"args": [
6-
"nvidia-ctk",
7-
"hook",
6+
"nvidia-cdi-hook",
87
"update-ldcache"
98
],
109
"hookName": "createContainer",
11-
"path": "/usr/bin/nvidia-ctk"
10+
"path": "/usr/bin/nvidia-cdi-hook"
1211
}
1312
]
1413
}

test/system/data/cdi-hooks-01.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
"hooks": [
44
{
55
"args": [
6-
"nvidia-ctk",
7-
"hook",
6+
"nvidia-cdi-hook",
87
"update-ldcache",
98
"--folder",
109
"/usr/lib64"
1110
],
1211
"hookName": "createContainer",
13-
"path": "/usr/bin/nvidia-ctk"
12+
"path": "/usr/bin/nvidia-cdi-hook"
1413
}
1514
]
1615
}

test/system/data/cdi-hooks-02.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
"hooks": [
44
{
55
"args": [
6-
"nvidia-ctk",
7-
"hook",
6+
"nvidia-cdi-hook",
87
"update-ldcache",
98
"--folder",
109
"/usr/lib",
1110
"--folder",
1211
"/usr/lib64"
1312
],
1413
"hookName": "createContainer",
15-
"path": "/usr/bin/nvidia-ctk"
14+
"path": "/usr/bin/nvidia-cdi-hook"
1615
}
1716
]
1817
}

test/system/data/cdi-hooks-10.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"hooks": [
44
{
55
"args": [
6-
"nvidia-ctk",
7-
"hook",
6+
"nvidia-cdi-hook",
87
"update-ldcache"
98
],
109
"hookName": "createContainer",

test/system/data/cdi-hooks-11.json

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{
55
"args": [
66
"unknown",
7-
"hook",
87
"update-ldcache"
98
],
109
"hookName": "createContainer",

test/system/data/cdi-hooks-12.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"hooks": [
44
{
55
"args": [
6-
"nvidia-ctk",
7-
"unknown",
8-
"update-ldcache"
6+
"nvidia-cdi-hook",
7+
"unknown"
98
],
109
"hookName": "createContainer",
11-
"path": "/usr/bin/nvidia-ctk"
10+
"path": "/usr/bin/nvidia-cdi-hook"
1211
}
1312
]
1413
}

test/system/data/cdi-hooks-13.json

-15
This file was deleted.

test/system/data/cdi-hooks-14.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"hooks": [
44
{
55
"args": [
6-
"nvidia-ctk",
7-
"hook",
6+
"nvidia-cdi-hook",
87
"update-ldcache"
98
],
109
"hookName": "invalid",
11-
"path": "/usr/bin/nvidia-ctk"
10+
"path": "/usr/bin/nvidia-cdi-hook"
1211
}
1312
]
1413
}

test/system/data/cdi-hooks-15.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"hooks": [
44
{
55
"args": [
6-
"nvidia-ctk",
7-
"hook",
6+
"nvidia-cdi-hook",
87
"update-ldcache"
98
],
109
"hookName": "createRuntime",
11-
"path": "/usr/bin/nvidia-ctk"
10+
"path": "/usr/bin/nvidia-cdi-hook"
1211
}
1312
]
1413
}

0 commit comments

Comments
 (0)