Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elezar
Copy link
Member

@elezar elezar commented Jun 5, 2025

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:

}
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.
Copy link
Member Author

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

Copy link
Collaborator

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

Copy link
Member Author

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.

@ArangoGutierrez ArangoGutierrez added this to the v1.18.0 milestone Jun 5, 2025
@ArangoGutierrez ArangoGutierrez self-requested a review June 5, 2025 14:38
@elezar elezar force-pushed the make-cdi-device-extraction-consistent branch from 5d667fc to 0e11147 Compare June 5, 2025 15:09
@coveralls
Copy link

coveralls commented Jun 5, 2025

Pull Request Test Coverage Report for Build 15475890809

Details

  • 18 of 54 (33.33%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 33.731%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/modifier/cdi.go 12 26 46.15%
internal/config/image/cuda_image.go 6 28 21.43%
Files with Coverage Reduction New Missed Lines %
internal/config/image/cuda_image.go 1 72.41%
Totals Coverage Status
Change from base Build 15466637032: 0.2%
Covered Lines: 4296
Relevant Lines: 12736

💛 - Coveralls

@elezar elezar force-pushed the make-cdi-device-extraction-consistent branch from 0e11147 to 58c6c17 Compare June 5, 2025 15:44
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]>
@elezar elezar force-pushed the make-cdi-device-extraction-consistent branch from 58c6c17 to 1b0f07a Compare June 5, 2025 19:47
@elezar elezar self-assigned this Jun 5, 2025
@ArangoGutierrez ArangoGutierrez requested a review from Copilot June 6, 2025 13:09
Copy link

@Copilot Copilot AI left a 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 with VisibleDevices
  • Update tests in internal/modifier, internal/info, and internal/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 using requestsFromMounts and parsing cdiDeviceMountRequest 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)
Copy link
Preview

Copilot AI Jun 6, 2025

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.

Suggested change
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.

Comment on lines +69 to +80
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 {
Copy link
Preview

Copilot AI Jun 6, 2025

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants