diff --git a/internal/modifier/cdi.go b/internal/modifier/cdi.go index f8559d3f..ff75eccc 100644 --- a/internal/modifier/cdi.go +++ b/internal/modifier/cdi.go @@ -144,28 +144,13 @@ 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...) } type deduplicatedDeviceRequestor struct { diff --git a/pkg/nvcdi/api.go b/pkg/nvcdi/api.go index 4ff11e47..ba541fcf 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 915cb94a..73892f96 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 4d59941a..4414f54f 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 3c375d56..cc8852c6 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 c940b090..fee99e7b 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 82be607e..8f4f8a0d 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 0d2f9870..662f63f7 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 9f45cfc9..0d3c1438 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 f45b34e7..68258187 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() diff --git a/tests/output/bundle/config.json b/tests/output/bundle/config.json deleted file mode 100644 index fa1ab672..00000000 --- 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"]}}