-
Notifications
You must be signed in to change notification settings - Fork 86
Add API support for NRI-native CDI injection #98
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
f1aa58f
01f3b7a
65282fe
44773bd
4bd8da8
4eb7075
8783973
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 |
|---|---|---|
|
|
@@ -91,6 +91,7 @@ func collectCreateContainerResult(request *CreateContainerRequest) *result { | |
| Env: []*KeyValue{}, | ||
| Hooks: &Hooks{}, | ||
| Rlimits: []*POSIXRlimit{}, | ||
| CDIDevices: []*CDIDevice{}, | ||
| Linux: &LinuxContainerAdjustment{ | ||
| Devices: []*LinuxDevice{}, | ||
| Resources: &LinuxResources{ | ||
|
|
@@ -219,6 +220,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error { | |
| if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil { | ||
| return err | ||
| } | ||
| if err := r.adjustCDIDevices(rpl.CDIDevices, plugin); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
@@ -388,6 +392,36 @@ func (r *result) adjustDevices(devices []*LinuxDevice, plugin string) error { | |
| return nil | ||
| } | ||
|
|
||
| func (r *result) adjustCDIDevices(devices []*CDIDevice, plugin string) error { | ||
| if len(devices) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| // Notes: | ||
| // CDI devices are opaque references, typically to vendor specific | ||
| // devices. They get resolved to actual devices and potential related | ||
| // mounts, environment variables, etc. in the runtime. Unlike with | ||
| // devices, we only allow CDI device references to be added to a | ||
| // container, not removed. We pass them unresolved to the runtime and | ||
| // have them resolved there. Also unlike with devices, we don't include | ||
| // CDI device references in creation requests. However, since there | ||
| // is typically a strong ownership and a single related management entity | ||
| // per vendor/class for these devices we do treat multiple injection of | ||
| // the same CDI device reference as an error here. | ||
|
|
||
| id := r.request.create.Container.Id | ||
|
|
||
| // apply additions to collected adjustments | ||
| for _, d := range devices { | ||
| if err := r.owners.claimCDIDevice(id, d.Name, plugin); err != nil { | ||
| return err | ||
|
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. // TODO: consider support for a higher level management plugin having the cap to adjust, esp. outside k8s scenarios
Member
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. Do you mean to verbatim include that comment here... as a reminder to consider that in the future ?
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. sort of.. suggesting the consideration of a TODO here, not that explicit text, or we can just open an issue though the way issues get removed when the bots are turned on :-) |
||
| } | ||
| r.reply.adjust.CDIDevices = append(r.reply.adjust.CDIDevices, d) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (r *result) adjustEnv(env []*KeyValue, plugin string) error { | ||
| if len(env) == 0 { | ||
| return nil | ||
|
|
@@ -891,6 +925,7 @@ type owners struct { | |
| annotations map[string]string | ||
| mounts map[string]string | ||
| devices map[string]string | ||
| cdiDevices map[string]string | ||
| env map[string]string | ||
| memLimit string | ||
| memReservation string | ||
|
|
@@ -937,6 +972,10 @@ func (ro resultOwners) claimDevice(id, path, plugin string) error { | |
| return ro.ownersFor(id).claimDevice(path, plugin) | ||
| } | ||
|
|
||
| func (ro resultOwners) claimCDIDevice(id, path, plugin string) error { | ||
| return ro.ownersFor(id).claimCDIDevice(path, plugin) | ||
| } | ||
|
|
||
| func (ro resultOwners) claimEnv(id, name, plugin string) error { | ||
| return ro.ownersFor(id).claimEnv(name, plugin) | ||
| } | ||
|
|
@@ -1062,6 +1101,17 @@ func (o *owners) claimDevice(path, plugin string) error { | |
| return nil | ||
| } | ||
|
|
||
| func (o *owners) claimCDIDevice(name, plugin string) error { | ||
| if o.cdiDevices == nil { | ||
| o.cdiDevices = make(map[string]string) | ||
| } | ||
| if other, taken := o.cdiDevices[name]; taken { | ||
| return conflict(plugin, other, "CDI device", name) | ||
| } | ||
| o.cdiDevices[name] = plugin | ||
| return nil | ||
| } | ||
|
|
||
| func (o *owners) claimEnv(name, plugin string) error { | ||
| if o.env == nil { | ||
| o.env = make(map[string]string) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.