mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Add all option to disable all hooks
Some checks failed
Some checks failed
Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
This commit is contained in:
parent
d657e0a16a
commit
191f11e3f9
@ -57,7 +57,7 @@ type options struct {
|
|||||||
|
|
||||||
configSearchPaths cli.StringSlice
|
configSearchPaths cli.StringSlice
|
||||||
librarySearchPaths cli.StringSlice
|
librarySearchPaths cli.StringSlice
|
||||||
disableHooks cli.StringSlice
|
disabledHooks cli.StringSlice
|
||||||
|
|
||||||
csv struct {
|
csv struct {
|
||||||
files cli.StringSlice
|
files cli.StringSlice
|
||||||
@ -179,9 +179,10 @@ func (m command) build() *cli.Command {
|
|||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "disable-hook",
|
Name: "disable-hook",
|
||||||
Usage: "Comma-separated list of hooks to skip when generating the CDI specification.",
|
Aliases: []string{"disable-hooks"},
|
||||||
|
Usage: "Hook to skip when generating the CDI specification. Can be specified multiple times. Can be a comma-separated list of hooks or a single hook name.",
|
||||||
Value: cli.NewStringSlice(),
|
Value: cli.NewStringSlice(),
|
||||||
Destination: &opts.disableHooks,
|
Destination: &opts.disabledHooks,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,10 +286,8 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
|
|||||||
nvcdi.WithNvmlLib(opts.nvmllib),
|
nvcdi.WithNvmlLib(opts.nvmllib),
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.disableHooks.Value()) > 0 {
|
for _, hook := range opts.disabledHooks.Value() {
|
||||||
for _, hook := range opts.disableHooks.Value() {
|
initOpts = append(initOpts, nvcdi.WithDisabledHook(hook))
|
||||||
initOpts = append(initOpts, nvcdi.WithDisabledHook(nvcdi.HookName(hook)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cdilib, err := nvcdi.New(initOpts...)
|
cdilib, err := nvcdi.New(initOpts...)
|
||||||
|
@ -37,7 +37,9 @@ func TestGenerateSpec(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
driverRoot := filepath.Join(moduleRoot, "testdata", "lookup", "rootfs-1")
|
driverRoot := filepath.Join(moduleRoot, "testdata", "lookup", "rootfs-1")
|
||||||
disableHook := cli.NewStringSlice("enable-cuda-compat", "create-symlinks", "update-ldcache")
|
disableHook1 := cli.NewStringSlice("enable-cuda-compat")
|
||||||
|
disableHook2 := cli.NewStringSlice("enable-cuda-compat", "update-ldcache")
|
||||||
|
disableHook3 := cli.NewStringSlice("all")
|
||||||
|
|
||||||
logger, _ := testlog.NewNullLogger()
|
logger, _ := testlog.NewNullLogger()
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -117,14 +119,14 @@ containerEdits:
|
|||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "disableHooks",
|
description: "disableHooks1",
|
||||||
options: options{
|
options: options{
|
||||||
format: "yaml",
|
format: "yaml",
|
||||||
mode: "nvml",
|
mode: "nvml",
|
||||||
vendor: "example.com",
|
vendor: "example.com",
|
||||||
class: "device",
|
class: "device",
|
||||||
driverRoot: driverRoot,
|
driverRoot: driverRoot,
|
||||||
disableHooks: *disableHook,
|
disabledHooks: *disableHook1,
|
||||||
},
|
},
|
||||||
expectedOptions: options{
|
expectedOptions: options{
|
||||||
format: "yaml",
|
format: "yaml",
|
||||||
@ -133,7 +135,128 @@ containerEdits:
|
|||||||
class: "device",
|
class: "device",
|
||||||
nvidiaCDIHookPath: "/usr/bin/nvidia-cdi-hook",
|
nvidiaCDIHookPath: "/usr/bin/nvidia-cdi-hook",
|
||||||
driverRoot: driverRoot,
|
driverRoot: driverRoot,
|
||||||
disableHooks: *disableHook,
|
disabledHooks: *disableHook1,
|
||||||
|
},
|
||||||
|
expectedSpec: `---
|
||||||
|
cdiVersion: 0.5.0
|
||||||
|
kind: example.com/device
|
||||||
|
devices:
|
||||||
|
- name: "0"
|
||||||
|
containerEdits:
|
||||||
|
deviceNodes:
|
||||||
|
- path: /dev/nvidia0
|
||||||
|
hostPath: {{ .driverRoot }}/dev/nvidia0
|
||||||
|
- name: all
|
||||||
|
containerEdits:
|
||||||
|
deviceNodes:
|
||||||
|
- path: /dev/nvidia0
|
||||||
|
hostPath: {{ .driverRoot }}/dev/nvidia0
|
||||||
|
containerEdits:
|
||||||
|
env:
|
||||||
|
- NVIDIA_VISIBLE_DEVICES=void
|
||||||
|
deviceNodes:
|
||||||
|
- path: /dev/nvidiactl
|
||||||
|
hostPath: {{ .driverRoot }}/dev/nvidiactl
|
||||||
|
hooks:
|
||||||
|
- hookName: createContainer
|
||||||
|
path: /usr/bin/nvidia-cdi-hook
|
||||||
|
args:
|
||||||
|
- nvidia-cdi-hook
|
||||||
|
- create-symlinks
|
||||||
|
- --link
|
||||||
|
- libcuda.so.1::/lib/x86_64-linux-gnu/libcuda.so
|
||||||
|
- hookName: createContainer
|
||||||
|
path: /usr/bin/nvidia-cdi-hook
|
||||||
|
args:
|
||||||
|
- nvidia-cdi-hook
|
||||||
|
- update-ldcache
|
||||||
|
- --folder
|
||||||
|
- /lib/x86_64-linux-gnu
|
||||||
|
mounts:
|
||||||
|
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/libcuda.so.999.88.77
|
||||||
|
containerPath: /lib/x86_64-linux-gnu/libcuda.so.999.88.77
|
||||||
|
options:
|
||||||
|
- ro
|
||||||
|
- nosuid
|
||||||
|
- nodev
|
||||||
|
- bind
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "disableHooks2",
|
||||||
|
options: options{
|
||||||
|
format: "yaml",
|
||||||
|
mode: "nvml",
|
||||||
|
vendor: "example.com",
|
||||||
|
class: "device",
|
||||||
|
driverRoot: driverRoot,
|
||||||
|
disabledHooks: *disableHook2,
|
||||||
|
},
|
||||||
|
expectedOptions: options{
|
||||||
|
format: "yaml",
|
||||||
|
mode: "nvml",
|
||||||
|
vendor: "example.com",
|
||||||
|
class: "device",
|
||||||
|
nvidiaCDIHookPath: "/usr/bin/nvidia-cdi-hook",
|
||||||
|
driverRoot: driverRoot,
|
||||||
|
disabledHooks: *disableHook2,
|
||||||
|
},
|
||||||
|
expectedSpec: `---
|
||||||
|
cdiVersion: 0.5.0
|
||||||
|
kind: example.com/device
|
||||||
|
devices:
|
||||||
|
- name: "0"
|
||||||
|
containerEdits:
|
||||||
|
deviceNodes:
|
||||||
|
- path: /dev/nvidia0
|
||||||
|
hostPath: {{ .driverRoot }}/dev/nvidia0
|
||||||
|
- name: all
|
||||||
|
containerEdits:
|
||||||
|
deviceNodes:
|
||||||
|
- path: /dev/nvidia0
|
||||||
|
hostPath: {{ .driverRoot }}/dev/nvidia0
|
||||||
|
containerEdits:
|
||||||
|
env:
|
||||||
|
- NVIDIA_VISIBLE_DEVICES=void
|
||||||
|
deviceNodes:
|
||||||
|
- path: /dev/nvidiactl
|
||||||
|
hostPath: {{ .driverRoot }}/dev/nvidiactl
|
||||||
|
hooks:
|
||||||
|
- hookName: createContainer
|
||||||
|
path: /usr/bin/nvidia-cdi-hook
|
||||||
|
args:
|
||||||
|
- nvidia-cdi-hook
|
||||||
|
- create-symlinks
|
||||||
|
- --link
|
||||||
|
- libcuda.so.1::/lib/x86_64-linux-gnu/libcuda.so
|
||||||
|
mounts:
|
||||||
|
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/libcuda.so.999.88.77
|
||||||
|
containerPath: /lib/x86_64-linux-gnu/libcuda.so.999.88.77
|
||||||
|
options:
|
||||||
|
- ro
|
||||||
|
- nosuid
|
||||||
|
- nodev
|
||||||
|
- bind
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "disableHooksAll",
|
||||||
|
options: options{
|
||||||
|
format: "yaml",
|
||||||
|
mode: "nvml",
|
||||||
|
vendor: "example.com",
|
||||||
|
class: "device",
|
||||||
|
driverRoot: driverRoot,
|
||||||
|
disabledHooks: *disableHook3,
|
||||||
|
},
|
||||||
|
expectedOptions: options{
|
||||||
|
format: "yaml",
|
||||||
|
mode: "nvml",
|
||||||
|
vendor: "example.com",
|
||||||
|
class: "device",
|
||||||
|
nvidiaCDIHookPath: "/usr/bin/nvidia-cdi-hook",
|
||||||
|
driverRoot: driverRoot,
|
||||||
|
disabledHooks: *disableHook3,
|
||||||
},
|
},
|
||||||
expectedSpec: `---
|
expectedSpec: `---
|
||||||
cdiVersion: 0.5.0
|
cdiVersion: 0.5.0
|
||||||
|
@ -44,4 +44,17 @@ const (
|
|||||||
// HookEnableCudaCompat refers to the hook used to enable CUDA Forward Compatibility.
|
// HookEnableCudaCompat refers to the hook used to enable CUDA Forward Compatibility.
|
||||||
// This was added with v1.17.5 of the NVIDIA Container Toolkit.
|
// This was added with v1.17.5 of the NVIDIA Container Toolkit.
|
||||||
HookEnableCudaCompat = HookName("enable-cuda-compat")
|
HookEnableCudaCompat = HookName("enable-cuda-compat")
|
||||||
|
// HookCreateSymlinks refers to the hook used create symlinks inside the
|
||||||
|
// directory path to be mounted into a container.
|
||||||
|
HookCreateSymlinks = HookName("create-symlinks")
|
||||||
|
// HookUpdateLDCache refers to the hook used to Update the dynamic linker
|
||||||
|
// cache inside the directory path to be mounted into a container.
|
||||||
|
HookUpdateLDCache = HookName("update-ldcache")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AllHooks maintains a future-proof list of all defined hooks.
|
||||||
|
var AllHooks = []HookName{
|
||||||
|
HookEnableCudaCompat,
|
||||||
|
HookCreateSymlinks,
|
||||||
|
HookUpdateLDCache,
|
||||||
|
}
|
||||||
|
@ -99,7 +99,7 @@ func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover
|
|||||||
|
|
||||||
var discoverers []discover.Discover
|
var discoverers []discover.Discover
|
||||||
|
|
||||||
if l.HookIsSupported("create-symlinks") {
|
if l.HookIsSupported(HookCreateSymlinks) {
|
||||||
driverDotSoSymlinksDiscoverer := discover.WithDriverDotSoSymlinks(
|
driverDotSoSymlinksDiscoverer := discover.WithDriverDotSoSymlinks(
|
||||||
libraries,
|
libraries,
|
||||||
version,
|
version,
|
||||||
@ -118,7 +118,7 @@ func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover
|
|||||||
discoverers = append(discoverers, cudaCompatLibHookDiscoverer)
|
discoverers = append(discoverers, cudaCompatLibHookDiscoverer)
|
||||||
}
|
}
|
||||||
|
|
||||||
if l.HookIsSupported("update-ldcache") {
|
if l.HookIsSupported(HookUpdateLDCache) {
|
||||||
updateLDCache, _ := discover.NewLDCacheUpdateHook(
|
updateLDCache, _ := discover.NewLDCacheUpdateHook(
|
||||||
l.logger,
|
l.logger,
|
||||||
libraries,
|
libraries,
|
||||||
|
@ -28,3 +28,14 @@ func (l *nvcdilib) HookIsSupported(h HookName) bool {
|
|||||||
}
|
}
|
||||||
return !l.disabledHooks[h]
|
return !l.disabledHooks[h]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d disabledHooks) Set(value HookName) {
|
||||||
|
if value == "all" {
|
||||||
|
for _, hook := range AllHooks {
|
||||||
|
d[hook] = true
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
d[value] = true
|
||||||
|
}
|
||||||
|
@ -158,11 +158,11 @@ func WithLibrarySearchPaths(paths []string) Option {
|
|||||||
|
|
||||||
// WithDisabledHook allows specific hooks to the disabled.
|
// WithDisabledHook allows specific hooks to the disabled.
|
||||||
// This option can be specified multiple times for each hook.
|
// This option can be specified multiple times for each hook.
|
||||||
func WithDisabledHook(hook HookName) Option {
|
func WithDisabledHook[T string | HookName](hook T) Option {
|
||||||
return func(o *nvcdilib) {
|
return func(o *nvcdilib) {
|
||||||
if o.disabledHooks == nil {
|
if o.disabledHooks == nil {
|
||||||
o.disabledHooks = make(map[HookName]bool)
|
o.disabledHooks = make(map[HookName]bool)
|
||||||
}
|
}
|
||||||
o.disabledHooks[hook] = true
|
o.disabledHooks.Set(HookName(hook))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user