-
Notifications
You must be signed in to change notification settings - Fork 1.1k
internal/factory/container: take dedicated CRI ContainerConfig.CDIDevices field into use. #6944
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,12 +176,53 @@ func (c *container) specAddContainerConfigDevices(enableDeviceOwnershipFromSecur | |
| } | ||
|
|
||
| func (c *container) specInjectCDIDevices() error { | ||
| // TODO: Once CRI is extended with native CDI support this will need to be updated... | ||
| _, names, err := cdi.ParseAnnotations(c.Config().GetAnnotations()) | ||
| var ( | ||
| cdiDevices = c.Config().CDIDevices | ||
| fromCRI = map[string]struct{}{} | ||
| requested = make([]string, 0, len(cdiDevices)) | ||
| annotated []string | ||
| err error | ||
| ) | ||
|
|
||
| // Take CDI devices from the dedicated CDIDevices CRI field. | ||
| for _, dev := range cdiDevices { | ||
| requested = append(requested, dev.Name) | ||
| fromCRI[dev.Name] = struct{}{} | ||
| } | ||
|
|
||
| // Extract CDI devices from annotations which is still supported as a means | ||
| // of injecting CDI devices to give people time to update their DRA drivers. | ||
| // TODO(klihub): Change the log message to a warning once annotations are | ||
| // deprecated, and to an error once support is removed altogether. | ||
| _, annotated, err = cdi.ParseAnnotations(c.Config().GetAnnotations()) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse CDI device annotations: %w", err) | ||
| } | ||
| if names == nil { | ||
|
|
||
| // Allow injecting the same device using both a dedicated field and an | ||
| // annotation. This helps the transition from annotations to dedicated | ||
| // CDI fields. DRA drivers can be updated to first inject devices using | ||
| // both. This allows updated drivers to be used in clusters that still | ||
| // talk old, pre-CDIDevices CRI. Then once annotations are deprecated | ||
| // drivers can be updated to stop using annotations. This also mirrors | ||
| // the behavior implemented in containerd. | ||
| if len(annotated) > 0 { | ||
| for _, name := range annotated { | ||
| if _, ok := fromCRI[name]; ok { | ||
| // TODO(klihub): change to a warning once annotations are deprecated | ||
| log.Infof(context.TODO(), | ||
| "Skipping duplicate annotated CDI device %s", name) | ||
| continue | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Above is a valid warning. Can you add a test case covering this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @klihub would you like to handle this as a follow-up?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's handle this in the follow-up PR
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, if it is OK for folks to just get this in and then handle that and anything else that might come up with with a follow-up PR, then I'd be for that, too.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But let me rebase on latest main and check at the same time if I could add such a test with minimal effort. |
||
| requested = append(requested, name) | ||
| } | ||
| // TODO(klihub): change to a warning once annotations are deprecated | ||
| log.Infof(context.TODO(), | ||
| "Passing CDI devices as annotations will be deprecated soon "+ | ||
| "please use the CDIDevices CRI field instead") | ||
| } | ||
|
|
||
| if len(requested) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -196,7 +237,7 @@ func (c *container) specInjectCDIDevices() error { | |
| log.Warnf(context.TODO(), "CDI registry has errors: %v", err) | ||
| } | ||
|
|
||
| if _, err := registry.InjectDevices(c.Spec().Config, names...); err != nil { | ||
| if _, err := registry.InjectDevices(c.Spec().Config, requested...); err != nil { | ||
| return fmt.Errorf("CDI device injection failed: %w", 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.
should we mark them as deprecated for 1.28 and then remove them in 1.29?
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, I think we should mark it deprecated. About removing support for it altogether, I think we should go in sync with what @bart0sh is doing on that front in containerd.