-
Notifications
You must be signed in to change notification settings - Fork 353
Make CDI device requests consistent with other methods #1132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
} | ||
return devices | ||
} | ||
|
||
// DevicesFromMounts returns a list of device specified as mounts. | ||
func (i CUDA) DevicesFromMounts() []string { | ||
// requestsFromMounts returns a list of device specified as mounts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed this function since we're returning all requests including:
- device requests (legacy and CDI)
- imex channel requests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: DevicesFromMounts has been renamed and turned private to the config pkg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It was not used outside this package.
5d667fc
to
0e11147
Compare
Pull Request Test Coverage Report for Build 15475890809Details
💛 - Coveralls |
0e11147
to
58c6c17
Compare
Following the refactoring of device request extraction, we can now make CDI device requests consistent with other methods. This change moves to using image.VisibleDevices instead of separate calls to CDIDevicesFromMounts and VisibleDevicesFromEnvVar. The handling of annotation-based requests will be addressed in a follow-up. Signed-off-by: Evan Lezar <[email protected]>
58c6c17
to
1b0f07a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors CDI device request handling to use image.VisibleDevices
uniformly, adds a new cdiModifier
wrapper for spec-based retrieval, and updates related tests.
- Introduce
cdiModifier
to centralize spec parsing and device extraction - Replace direct calls to
CDIDevicesFromMounts
/VisibleDevicesFromEnvVar
withVisibleDevices
- Update tests in
internal/modifier
,internal/info
, andinternal/config
to reflect the new behavior
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
internal/modifier/cdi.go | Add cdiModifier type, consolidate device extraction |
internal/modifier/cdi_test.go | New tests for getDevicesFromSpec |
internal/info/auto_test.go | Adjust TestResolveAutoMode expectations and setup |
internal/config/image/cuda_image.go | Rename/move mount helpers, parse CDI mount requests |
internal/config/image/cuda_image_test.go | Update expected mount-based CDI device inclusion |
Comments suppressed due to low confidence (1)
internal/config/image/cuda_image.go:219
- The mount-based CDI device checks were removed, so
OnlyFullyQualifiedCDIDevices
no longer accounts for devices requested via mounts. Consider re-adding logic usingrequestsFromMounts
and parsingcdiDeviceMountRequest
to correctly detect mount-based CDI devices.
func (i CUDA) OnlyFullyQualifiedCDIDevices() bool {
case strings.HasPrefix(device, volumeMountDevicePrefixCDI): | ||
name, err := cdiDeviceMountRequest(device).qualifiedName() | ||
if err != nil { | ||
i.logger.Warningf("Ignoring invalid mount request for CDI device %v: %w", device, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The %w
verb is only supported by fmt.Errorf
. In logging calls, use %v
or %s
to ensure the error is formatted correctly.
i.logger.Warningf("Ignoring invalid mount request for CDI device %v: %w", device, err) | |
i.logger.Warningf("Ignoring invalid mount request for CDI device %v: %v", device, err) |
Copilot uses AI. Check for mistakes.
cdiModifier := &cdiModifier{ | ||
logger: logger, | ||
acceptDeviceListAsVolumeMounts: cfg.AcceptDeviceListAsVolumeMounts, | ||
acceptEnvvarUnprivileged: cfg.AcceptEnvvarUnprivileged, | ||
annotationPrefixes: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.AnnotationPrefixes, | ||
defaultKind: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.DefaultKind, | ||
} | ||
return cdiModifier.getDevicesFromSpec(ociSpec) | ||
} | ||
|
||
// TODO: We should rename this type. | ||
type cdiModifier struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The cdiModifier
type has a TODO to rename it. Consider selecting a more descriptive name or removing the TODO if this is the intended name.
cdiModifier := &cdiModifier{ | |
logger: logger, | |
acceptDeviceListAsVolumeMounts: cfg.AcceptDeviceListAsVolumeMounts, | |
acceptEnvvarUnprivileged: cfg.AcceptEnvvarUnprivileged, | |
annotationPrefixes: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.AnnotationPrefixes, | |
defaultKind: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.DefaultKind, | |
} | |
return cdiModifier.getDevicesFromSpec(ociSpec) | |
} | |
// TODO: We should rename this type. | |
type cdiModifier struct { | |
deviceHandler := &CDIDeviceHandler{ | |
logger: logger, | |
acceptDeviceListAsVolumeMounts: cfg.AcceptDeviceListAsVolumeMounts, | |
acceptEnvvarUnprivileged: cfg.AcceptEnvvarUnprivileged, | |
annotationPrefixes: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.AnnotationPrefixes, | |
defaultKind: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.DefaultKind, | |
} | |
return deviceHandler.getDevicesFromSpec(ociSpec) | |
} | |
// This type handles CDI-related device configurations and annotations. | |
type CDIDeviceHandler struct { |
Copilot uses AI. Check for mistakes.
Following the refactoring of device request extraction, we can now make CDI device requests consistent with other methods.
This change moves to using image.VisibleDevices instead of separate calls to CDIDevicesFromMounts and VisibleDevicesFromEnvVar. The handling of annotation-based requests will be addressed in a follow-up.
See: