From 0134ba42509a8795a77ba80a252f8656b7084ddc Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 12 Jun 2025 16:08:09 +0200 Subject: [PATCH 1/2] Add device IDs to nvcdi.GetSpec API This change allows device IDs to the specified in the GetSpec API. This simplifies cases where CDI specs are being generated for specific devices by ID. Signed-off-by: Evan Lezar --- internal/modifier/cdi.go | 19 ++----------------- pkg/nvcdi/api.go | 2 +- pkg/nvcdi/gds.go | 2 +- pkg/nvcdi/lib-csv.go | 2 +- pkg/nvcdi/lib-imex.go | 2 +- pkg/nvcdi/lib-nvml.go | 2 +- pkg/nvcdi/lib-wsl.go | 2 +- pkg/nvcdi/management.go | 2 +- pkg/nvcdi/mofed.go | 2 +- pkg/nvcdi/wrapper.go | 17 +++++++++++++++-- 10 files changed, 25 insertions(+), 27 deletions(-) diff --git a/internal/modifier/cdi.go b/internal/modifier/cdi.go index 6c7286af6..1137af26b 100644 --- a/internal/modifier/cdi.go +++ b/internal/modifier/cdi.go @@ -195,26 +195,11 @@ func generateAutomaticCDISpec(logger logger.Interface, cfg *config.Config, devic return nil, fmt.Errorf("failed to construct CDI library: %w", err) } - identifiers := []string{} + var identifiers []string for _, device := range devices { _, _, id := parser.ParseDevice(device) identifiers = append(identifiers, id) } - deviceSpecs, err := cdilib.GetDeviceSpecsByID(identifiers...) - if err != nil { - return nil, fmt.Errorf("failed to get CDI device specs: %w", err) - } - - commonEdits, err := cdilib.GetCommonEdits() - if err != nil { - return nil, fmt.Errorf("failed to get common CDI spec edits: %w", err) - } - - return spec.New( - spec.WithDeviceSpecs(deviceSpecs), - spec.WithEdits(*commonEdits.ContainerEdits), - spec.WithVendor("runtime.nvidia.com"), - spec.WithClass("gpu"), - ) + return cdilib.GetSpec(identifiers...) } diff --git a/pkg/nvcdi/api.go b/pkg/nvcdi/api.go index 4ff11e47f..ba541fcf1 100644 --- a/pkg/nvcdi/api.go +++ b/pkg/nvcdi/api.go @@ -27,7 +27,7 @@ import ( // Interface defines the API for the nvcdi package type Interface interface { - GetSpec() (spec.Interface, error) + GetSpec(...string) (spec.Interface, error) GetCommonEdits() (*cdi.ContainerEdits, error) GetAllDeviceSpecs() ([]specs.Device, error) GetGPUDeviceEdits(device.Device) (*cdi.ContainerEdits, error) diff --git a/pkg/nvcdi/gds.go b/pkg/nvcdi/gds.go index 915cb94a2..73892f967 100644 --- a/pkg/nvcdi/gds.go +++ b/pkg/nvcdi/gds.go @@ -58,7 +58,7 @@ func (l *gdslib) GetCommonEdits() (*cdi.ContainerEdits, error) { // GetSpec is unsppported for the gdslib specs. // gdslib is typically wrapped by a spec that implements GetSpec. -func (l *gdslib) GetSpec() (spec.Interface, error) { +func (l *gdslib) GetSpec(...string) (spec.Interface, error) { return nil, fmt.Errorf("GetSpec is not supported") } diff --git a/pkg/nvcdi/lib-csv.go b/pkg/nvcdi/lib-csv.go index 4d59941a2..4414f54fc 100644 --- a/pkg/nvcdi/lib-csv.go +++ b/pkg/nvcdi/lib-csv.go @@ -34,7 +34,7 @@ type csvlib nvcdilib var _ Interface = (*csvlib)(nil) // GetSpec should not be called for wsllib -func (l *csvlib) GetSpec() (spec.Interface, error) { +func (l *csvlib) GetSpec(...string) (spec.Interface, error) { return nil, fmt.Errorf("unexpected call to csvlib.GetSpec()") } diff --git a/pkg/nvcdi/lib-imex.go b/pkg/nvcdi/lib-imex.go index 3c375d56f..cc8852c6f 100644 --- a/pkg/nvcdi/lib-imex.go +++ b/pkg/nvcdi/lib-imex.go @@ -41,7 +41,7 @@ const ( ) // GetSpec should not be called for imexlib. -func (l *imexlib) GetSpec() (spec.Interface, error) { +func (l *imexlib) GetSpec(...string) (spec.Interface, error) { return nil, fmt.Errorf("unexpected call to imexlib.GetSpec()") } diff --git a/pkg/nvcdi/lib-nvml.go b/pkg/nvcdi/lib-nvml.go index c940b090d..fee99e7b0 100644 --- a/pkg/nvcdi/lib-nvml.go +++ b/pkg/nvcdi/lib-nvml.go @@ -36,7 +36,7 @@ type nvmllib nvcdilib var _ Interface = (*nvmllib)(nil) // GetSpec should not be called for nvmllib -func (l *nvmllib) GetSpec() (spec.Interface, error) { +func (l *nvmllib) GetSpec(...string) (spec.Interface, error) { return nil, fmt.Errorf("unexpected call to nvmllib.GetSpec()") } diff --git a/pkg/nvcdi/lib-wsl.go b/pkg/nvcdi/lib-wsl.go index 82be607e0..8f4f8a0dd 100644 --- a/pkg/nvcdi/lib-wsl.go +++ b/pkg/nvcdi/lib-wsl.go @@ -32,7 +32,7 @@ type wsllib nvcdilib var _ Interface = (*wsllib)(nil) // GetSpec should not be called for wsllib -func (l *wsllib) GetSpec() (spec.Interface, error) { +func (l *wsllib) GetSpec(...string) (spec.Interface, error) { return nil, fmt.Errorf("unexpected call to wsllib.GetSpec()") } diff --git a/pkg/nvcdi/management.go b/pkg/nvcdi/management.go index 0d2f98703..662f63f7b 100644 --- a/pkg/nvcdi/management.go +++ b/pkg/nvcdi/management.go @@ -180,7 +180,7 @@ func (m managementDiscoverer) nodeIsBlocked(path string) bool { // GetSpec is unsppported for the managementlib specs. // managementlib is typically wrapped by a spec that implements GetSpec. -func (m *managementlib) GetSpec() (spec.Interface, error) { +func (m *managementlib) GetSpec(...string) (spec.Interface, error) { return nil, fmt.Errorf("GetSpec is not supported") } diff --git a/pkg/nvcdi/mofed.go b/pkg/nvcdi/mofed.go index 9f45cfc97..0d3c14380 100644 --- a/pkg/nvcdi/mofed.go +++ b/pkg/nvcdi/mofed.go @@ -58,7 +58,7 @@ func (l *mofedlib) GetCommonEdits() (*cdi.ContainerEdits, error) { // GetSpec is unsppported for the mofedlib specs. // mofedlib is typically wrapped by a spec that implements GetSpec. -func (l *mofedlib) GetSpec() (spec.Interface, error) { +func (l *mofedlib) GetSpec(...string) (spec.Interface, error) { return nil, fmt.Errorf("GetSpec is not supported") } diff --git a/pkg/nvcdi/wrapper.go b/pkg/nvcdi/wrapper.go index f45b34e70..682581875 100644 --- a/pkg/nvcdi/wrapper.go +++ b/pkg/nvcdi/wrapper.go @@ -35,8 +35,11 @@ type wrapper struct { } // GetSpec combines the device specs and common edits from the wrapped Interface to a single spec.Interface. -func (l *wrapper) GetSpec() (spec.Interface, error) { - deviceSpecs, err := l.GetAllDeviceSpecs() +func (l *wrapper) GetSpec(devices ...string) (spec.Interface, error) { + if len(devices) == 0 { + devices = append(devices, "all") + } + deviceSpecs, err := l.GetDeviceSpecsByID(devices...) if err != nil { return nil, err } @@ -55,6 +58,16 @@ func (l *wrapper) GetSpec() (spec.Interface, error) { ) } +func (l *wrapper) GetDeviceSpecsByID(devices ...string) ([]specs.Device, error) { + for _, device := range devices { + if device != "all" { + continue + } + return l.GetAllDeviceSpecs() + } + return l.Interface.GetDeviceSpecsByID(devices...) +} + // GetAllDeviceSpecs returns the device specs for all available devices. func (l *wrapper) GetAllDeviceSpecs() ([]specs.Device, error) { return l.Interface.GetAllDeviceSpecs() From 2ccf67c40f7eb71b7e4783ef3d75b656d2512035 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 7 Feb 2025 23:03:00 +0100 Subject: [PATCH 2/2] [no-relnote] Remove test output file Signed-off-by: Evan Lezar --- tests/output/bundle/config.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/output/bundle/config.json diff --git a/tests/output/bundle/config.json b/tests/output/bundle/config.json deleted file mode 100644 index fa1ab6725..000000000 --- a/tests/output/bundle/config.json +++ /dev/null @@ -1 +0,0 @@ -{"ociVersion":"1.0.1-dev","process":{"terminal":true,"user":{"uid":0,"gid":0},"args":["sh"],"env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","TERM=xterm"],"cwd":"/","capabilities":{"bounding":["CAP_AUDIT_WRITE","CAP_KILL","CAP_NET_BIND_SERVICE"],"effective":["CAP_AUDIT_WRITE","CAP_KILL","CAP_NET_BIND_SERVICE"],"inheritable":["CAP_AUDIT_WRITE","CAP_KILL","CAP_NET_BIND_SERVICE"],"permitted":["CAP_AUDIT_WRITE","CAP_KILL","CAP_NET_BIND_SERVICE"],"ambient":["CAP_AUDIT_WRITE","CAP_KILL","CAP_NET_BIND_SERVICE"]},"rlimits":[{"type":"RLIMIT_NOFILE","hard":1024,"soft":1024}],"noNewPrivileges":true},"root":{"path":"rootfs","readonly":true},"hostname":"runc","mounts":[{"destination":"/proc","type":"proc","source":"proc"},{"destination":"/dev","type":"tmpfs","source":"tmpfs","options":["nosuid","strictatime","mode=755","size=65536k"]},{"destination":"/dev/pts","type":"devpts","source":"devpts","options":["nosuid","noexec","newinstance","ptmxmode=0666","mode=0620","gid=5"]},{"destination":"/dev/shm","type":"tmpfs","source":"shm","options":["nosuid","noexec","nodev","mode=1777","size=65536k"]},{"destination":"/dev/mqueue","type":"mqueue","source":"mqueue","options":["nosuid","noexec","nodev"]},{"destination":"/sys","type":"sysfs","source":"sysfs","options":["nosuid","noexec","nodev","ro"]},{"destination":"/sys/fs/cgroup","type":"cgroup","source":"cgroup","options":["nosuid","noexec","nodev","relatime","ro"]}],"hooks":{"prestart":[{"path":"nvidia-container-runtime-hook","args":["nvidia-container-runtime-hook","prestart"]}]},"linux":{"resources":{"devices":[{"allow":false,"access":"rwm"}]},"namespaces":[{"type":"pid"},{"type":"network"},{"type":"ipc"},{"type":"uts"},{"type":"mount"}],"maskedPaths":["/proc/kcore","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/sys/firmware","/proc/scsi"],"readonlyPaths":["/proc/asound","/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]}}