Skip to content

Commit 007faf8

Browse files
committed
Add envvar to control debug logging in CDI hooks
This change allows hooks to be configured with debug logging. This is currently always set to false, but may be extended in future. Signed-off-by: Evan Lezar <[email protected]>
1 parent d7f498a commit 007faf8

File tree

10 files changed

+27
-2
lines changed

10 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## v1.17.8
44

55
- Updated the ordering of Mounts in CDI to have a deterministic output. This makes testing more consistent.
6+
- Added NVIDIA_CTK_DEBUG envvar to hooks.
67

78
### Changes in libnvidia-container
89

cmd/nvidia-cdi-hook/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ func main() {
5858
Aliases: []string{"d"},
5959
Usage: "Enable debug-level logging",
6060
Destination: &opts.Debug,
61-
EnvVars: []string{"NVIDIA_CDI_DEBUG"},
61+
// TODO: Support for NVIDIA_CDI_DEBUG is deprecated and NVIDIA_CTK_DEBUG should be used instead.
62+
EnvVars: []string{"NVIDIA_CTK_DEBUG", "NVIDIA_CDI_DEBUG"},
6263
},
6364
&cli.BoolFlag{
6465
Name: "quiet",
6566
Usage: "Suppress all output except for errors; overrides --debug",
6667
Destination: &opts.Quiet,
67-
EnvVars: []string{"NVIDIA_CDI_QUIET"},
68+
// TODO: Support for NVIDIA_CDI_QUIET is deprecated and NVIDIA_CTK_QUIET should be used instead.
69+
EnvVars: []string{"NVDIA_CTK_QUIET", "NVIDIA_CDI_QUIET"},
6870
},
6971
}
7072

internal/discover/discover.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Hook struct {
3434
Lifecycle string
3535
Path string
3636
Args []string
37+
Env []string
3738
}
3839

3940
// Discover defines an interface for discovering the devices, mounts, and hooks available on a system

internal/discover/graphics_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func TestGraphicsLibrariesDiscoverer(t *testing.T) {
7070
Args: []string{"nvidia-cdi-hook", "create-symlinks",
7171
"--link", "../libnvidia-allocator.so.1::/usr/lib64/gbm/nvidia-drm_gbm.so",
7272
},
73+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
7374
},
7475
},
7576
},
@@ -97,6 +98,7 @@ func TestGraphicsLibrariesDiscoverer(t *testing.T) {
9798
Args: []string{"nvidia-cdi-hook", "create-symlinks",
9899
"--link", "libnvidia-vulkan-producer.so.123.45.67::/usr/lib64/libnvidia-vulkan-producer.so",
99100
},
101+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
100102
},
101103
},
102104
},
@@ -128,6 +130,7 @@ func TestGraphicsLibrariesDiscoverer(t *testing.T) {
128130
"--link", "../libnvidia-allocator.so.1::/usr/lib64/gbm/nvidia-drm_gbm.so",
129131
"--link", "libnvidia-vulkan-producer.so.123.45.67::/usr/lib64/libnvidia-vulkan-producer.so",
130132
},
133+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
131134
},
132135
},
133136
},

internal/discover/hooks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package discover
1818

1919
import (
20+
"fmt"
2021
"path/filepath"
2122

2223
"tags.cncf.io/container-device-interface/pkg/cdi"
@@ -69,6 +70,7 @@ func (c cdiHook) Create(name string, args ...string) Hook {
6970
Lifecycle: cdi.CreateContainerHook,
7071
Path: string(c),
7172
Args: append(c.requiredArgs(name), args...),
73+
Env: []string{fmt.Sprintf("NVIDIA_CTK_DEBUG=%v", false)},
7274
}
7375
}
7476
func (c cdiHook) requiredArgs(name string) []string {

internal/discover/ldconfig_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func TestLDCacheUpdateHook(t *testing.T) {
9595
Path: testNvidiaCDIHookPath,
9696
Args: tc.expectedArgs,
9797
Lifecycle: "createContainer",
98+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
9899
}
99100

100101
d, err := NewLDCacheUpdateHook(logger, mountMock, testNvidiaCDIHookPath, tc.ldconfigPath)

internal/discover/symlinks_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func TestWithWithDriverDotSoSymlinks(t *testing.T) {
115115
Lifecycle: "createContainer",
116116
Path: "/path/to/nvidia-cdi-hook",
117117
Args: []string{"nvidia-cdi-hook", "create-symlinks", "--link", "libcuda.so.1::/usr/lib/libcuda.so"},
118+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
118119
},
119120
},
120121
},
@@ -147,6 +148,7 @@ func TestWithWithDriverDotSoSymlinks(t *testing.T) {
147148
Lifecycle: "createContainer",
148149
Path: "/path/to/nvidia-cdi-hook",
149150
Args: []string{"nvidia-cdi-hook", "create-symlinks", "--link", "libcuda.so.1::/usr/lib/libcuda.so"},
151+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
150152
},
151153
},
152154
},
@@ -178,6 +180,7 @@ func TestWithWithDriverDotSoSymlinks(t *testing.T) {
178180
Lifecycle: "createContainer",
179181
Path: "/path/to/nvidia-cdi-hook",
180182
Args: []string{"nvidia-cdi-hook", "create-symlinks", "--link", "libcuda.so.1::/usr/lib/libcuda.so"},
183+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
181184
},
182185
},
183186
},
@@ -247,6 +250,7 @@ func TestWithWithDriverDotSoSymlinks(t *testing.T) {
247250
Lifecycle: "createContainer",
248251
Path: "/path/to/nvidia-cdi-hook",
249252
Args: []string{"nvidia-cdi-hook", "create-symlinks", "--link", "libcuda.so.1::/usr/lib/libcuda.so"},
253+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
250254
},
251255
},
252256
},
@@ -301,6 +305,7 @@ func TestWithWithDriverDotSoSymlinks(t *testing.T) {
301305
"--link", "libGLX_nvidia.so.1.2.3::/usr/lib/libGLX_indirect.so.0",
302306
"--link", "libnvidia-opticalflow.so.1::/usr/lib/libnvidia-opticalflow.so",
303307
},
308+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
304309
},
305310
},
306311
},

internal/edits/hook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ func (d hook) toEdits() *cdi.ContainerEdits {
3838
// toSpec converts a discovered Hook to a CDI Spec Hook. Note
3939
// that missing info is filled in when edits are applied by querying the Hook node.
4040
func (d hook) toSpec() *specs.Hook {
41+
env := d.Env
42+
if env == nil {
43+
env = []string{"NVIDIA_CTK_DEBUG=false"}
44+
}
4145
s := specs.Hook{
4246
HookName: d.Lifecycle,
4347
Path: d.Path,
4448
Args: d.Args,
49+
Env: env,
4550
}
4651

4752
return &s

internal/platform-support/tegra/csv_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func TestDiscovererFromCSVFiles(t *testing.T) {
9797
"--link",
9898
"/usr/lib/aarch64-linux-gnu/tegra/libv4l2_nvargus.so::/usr/lib/aarch64-linux-gnu/libv4l/plugins/nv/libv4l2_nvargus.so",
9999
},
100+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
100101
},
101102
},
102103
},
@@ -153,6 +154,7 @@ func TestDiscovererFromCSVFiles(t *testing.T) {
153154
"--link",
154155
"/usr/lib/aarch64-linux-gnu/tegra/libv4l2_nvargus.so::/usr/lib/aarch64-linux-gnu/libv4l/plugins/nv/libv4l2_nvargus.so",
155156
},
157+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
156158
},
157159
},
158160
},

pkg/nvcdi/driver-wsl_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func TestNvidiaSMISymlinkHook(t *testing.T) {
9595
Path: "nvidia-cdi-hook",
9696
Args: []string{"nvidia-cdi-hook", "create-symlinks",
9797
"--link", "nvidia-smi::/usr/bin/nvidia-smi"},
98+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
9899
},
99100
},
100101
},
@@ -115,6 +116,7 @@ func TestNvidiaSMISymlinkHook(t *testing.T) {
115116
Path: "nvidia-cdi-hook",
116117
Args: []string{"nvidia-cdi-hook", "create-symlinks",
117118
"--link", "/some/path/nvidia-smi::/usr/bin/nvidia-smi"},
119+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
118120
},
119121
},
120122
},
@@ -135,6 +137,7 @@ func TestNvidiaSMISymlinkHook(t *testing.T) {
135137
Path: "nvidia-cdi-hook",
136138
Args: []string{"nvidia-cdi-hook", "create-symlinks",
137139
"--link", "/some/path/nvidia-smi::/usr/bin/nvidia-smi"},
140+
Env: []string{"NVIDIA_CTK_DEBUG=false"},
138141
},
139142
},
140143
},

0 commit comments

Comments
 (0)