Skip to content

Commit f7a9d4d

Browse files
committed
fix: Return error on JIT CDI spec generation failure
This change ensures that errors that occur when generating jit CDI specs are returned instead of silently ignored. Signed-off-by: Evan Lezar <[email protected]>
1 parent 786aa3b commit f7a9d4d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

internal/modifier/cdi.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,36 @@ func NewCDIModifier(logger logger.Interface, cfg *config.Config, image image.CUD
5555
logger.Debugf("No devices requested; no modification required.")
5656
return nil, nil
5757
}
58-
logger.Debugf("Creating CDI modifier for devices: %v", devices)
5958

6059
automaticDevices := filterAutomaticDevices(devices)
6160
if len(automaticDevices) != len(devices) && len(automaticDevices) > 0 {
6261
return nil, fmt.Errorf("requesting a CDI device with vendor 'runtime.nvidia.com' is not supported when requesting other CDI devices")
6362
}
6463
if len(automaticDevices) > 0 {
65-
automaticDevices = append(automaticDevices, withUniqueDevices(gatedDevices(image)).DeviceRequests()...)
66-
automaticDevices = append(automaticDevices, withUniqueDevices(imexDevices(image)).DeviceRequests()...)
67-
68-
automaticModifier, err := newAutomaticCDISpecModifier(logger, cfg, automaticDevices)
69-
if err == nil {
70-
return automaticModifier, nil
64+
logger.Debugf("Using automatic CDI modfier for devices %v", automaticDevices)
65+
modifier, err := newJitCDIModifier(logger, cfg, image, automaticDevices)
66+
if err != nil {
67+
return nil, fmt.Errorf("failed to create the automatic CDI modifier: %w", err)
7168
}
72-
logger.Warningf("Failed to create the automatic CDI modifier: %w", err)
73-
logger.Debugf("Falling back to the standard CDI modifier")
69+
return modifier, nil
7470
}
7571

72+
logger.Debugf("Creating CDI modifier for devices: %v", devices)
7673
return cdi.New(
7774
cdi.WithLogger(logger),
7875
cdi.WithDevices(devices...),
7976
cdi.WithSpecDirs(cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.SpecDirs...),
8077
)
8178
}
8279

80+
// newJitCDIModifier creates a modifier that for a generated in-memory CDI spec for the specified CDI devices.
81+
func newJitCDIModifier(logger logger.Interface, cfg *config.Config, image image.CUDA, automaticDevices []string) (oci.SpecModifier, error) {
82+
automaticDevices = append(automaticDevices, withUniqueDevices(gatedDevices(image)).DeviceRequests()...)
83+
automaticDevices = append(automaticDevices, withUniqueDevices(imexDevices(image)).DeviceRequests()...)
84+
85+
return newAutomaticCDISpecModifier(logger, cfg, automaticDevices)
86+
}
87+
8388
type deviceRequestor interface {
8489
DeviceRequests() []string
8590
}

0 commit comments

Comments
 (0)