DRA policy boundary #803
A ResourceSlice may contain at most 128 devices (resourceapi.ResourceSliceMaxDevices). Putting the policy's entire list into one slice makes publication fail for larger CPU inventories. Split the list across multiple resourceslice.Slice values while retaining one empty slice for an empty policy; add a boundary test with 129 devices.
<!-- ccr-overview-v2 -->
Copilot review overview
🟡 Changes recommended
Device lists exceeding Kubernetes’ 128-device ResourceSlice limit cannot currently be published.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>
<details open>
<summary><strong>Open (1)</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
Adds a policy-controlled DRA boundary and publishes devices supplied by the active policy.
Changes:
| File | Description |
| ---- | ----------- |
| pkg/resmgr/policy/policy.go | Defines and forwards DRA policy methods. |
| pkg/resmgr/policy/policy_test.go | Tests DRA forwarding. |
| pkg/resmgr/policy/error.go | Adds the unsupported-claims error. |
| pkg/resmgr/dra/plugin.go | Publishes policy-provided devices. |
| pkg/resmgr/dra/plugin_test.go | Tests publication and policy errors. |
| pkg/resmgr/dra.go | Passes the active policy to the plugin. |
| pkg/resmgr/dra_test.go | Updates resource-manager DRA tests. |
| go.mod | Adds the CDI specifications dependency. |
| go.sum | Records CDI dependency checksums. |
| cmd/plugins/topology-aware/policy/dra.go | Adds topology-aware DRA stubs. |
| cmd/plugins/template/policy/template-policy.go | Adds template-policy DRA stubs. |
| cmd/plugins/balloons/policy/balloons-policy.go | Adds balloons-policy DRA stubs. |
</details>
---
💡 <a href="/containers/nri-plugins/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
<!-- ccr-overview-v2 -->
Copilot review overview
🟢 Approval recommended
The policy boundary, driver integration, backend stubs, and relevant edge cases are implemented consistently and adequately tested.
Review effort: Balanced
Findings: None
<details>
<summary><strong>Resolved since last review (1)</strong></summary>
</details>
I skimmed through this once and it looks good to me. I'll give it another read tomorrow.
@bart0sh There is a duplicated (test) function flagged by linting...
LGTM.
nit: let's stick with pure ASCII.
Just a nit on a non-ASCII character, otherwise LGTM.
Looking forward to currently out-of-scope resource updates from policies...
@askervin Thank you for the review! Fixed.
@bart0sh, @klihub, thinking of this series over night, especially in the perspective of updating resources.
Would you see problems if a policy would publish DRA resource slices via cache, instead of resmgr asking it DRADevices()?
That would enable the policy to push new "desired state" of what it wants to have published to the cache at any point of time. That would cover, not only resmgr-triggered actions (reconfigure, allocate/free resources for a container), but also unsolicited policy events, such as detecting hotplugging of CXL memory.
resmgr's DRA subsystem could be wired to listen to these updates in cache and update published resource slices accordingly.
@bart0sh, @klihub, thinking of this series over night, especially in the perspective of updating resources.
> Would you see problems if a policy would publish DRA resource slices viacache, instead of resmgr asking itDRADevices()?
> That would enable the policy to push new "desired state" of what it wants to have published to the cache at any point of time.
That would cover, not only resmgr-triggered actions (reconfigure, allocate/free resources for a container), but also unsolicited policy events, such as detecting hotplugging of CXL memory.
> resmgr's DRA subsystem could be wired to listen to these updates in cache and update published resource slices accordingly.
Couldn't that also be accomplished by changing the resource publishing control flow to a push model, or allowing a push model as well ? So basically adding an interface (to the policy backend options) for pushing resources to be published to the resmgr-level DRA driver/logic. I think that's how it was in the prototype. But I don't know what kind of problems that could potentially cause in the new/real driver logic.
> @bart0sh, @klihub, thinking of this series over night, especially in the perspective of updating resources.
> Would you see problems if a policy would publish DRA resource slices viacache, instead of resmgr asking itDRADevices()?
> That would enable the policy to push new "desired state" of what it wants to have published to the cache at any point of time.
> > That would cover, not only resmgr-triggered actions (reconfigure, allocate/free resources for a container), but also unsolicited policy events, such as detecting hotplugging of CXL memory.
> resmgr's DRA subsystem could be wired to listen to these updates in cache and update published resource slices accordingly.
> Couldn't that also be accomplished by changing the resource publishing control flow to a push model, or allowing a push model as well ? So basically adding an interface (to the policy backend options) for pushing resources to be published to the resmgr-level DRA driver/logic. I think that's how it was in the prototype. But I don't know what kind of problems that could potentially cause in the new/real driver logic.
Can we add push functionality using existing BackendOptions.SendEvent, so a policy would send an event to resource manager, telling it what kind of its data has changed, e.g. devices, topology zones, extended resources, etc. Resmgr then can handle it. Handling would call existing policy interfaces (DRADevices(), GetTopologyZones(), GetExtendedResources(), etc) to get the latest data from policy and do whatever is needed with it, e.g. if devices change, it would republish the resource slice(s).
> > @bart0sh, @klihub, thinking of this series over night, especially in the perspective of updating resources.
> > Would you see problems if a policy would publish DRA resource slices viacache, instead of resmgr asking itDRADevices()?
> > That would enable the policy to push new "desired state" of what it wants to have published to the cache at any point of time.
>
>
> > That would cover, not only resmgr-triggered actions (reconfigure, allocate/free resources for a container), but also unsolicited policy events, such as detecting hotplugging of CXL memory.
> > resmgr's DRA subsystem could be wired to listen to these updates in cache and update published resource slices accordingly.
>
>
> Couldn't that also be accomplished by changing the resource publishing control flow to a push model, or allowing a push model as well ? So basically adding an interface (to the policy backend options) for pushing resources to be published to the resmgr-level DRA driver/logic. I think that's how it was in the prototype. But I don't know what kind of problems that could potentially cause in the new/real driver logic.
> Can we add push functionality using existing BackendOptions.SendEvent, so a policy would send an event to resource manager, telling it what kind of its data has changed, e.g. devices, topology zones, extended resources, etc. Resmgr then can handle it. Handling would call existing policy interfaces (DRADevices(), GetTopologyZones(), GetExtendedResources(), etc) to get the latest data from policy and do whatever is needed with it, e.g. if devices change, it would republish the resource slice(s).
@bart0sh @askervin Maybe it could be done that way. If I understand correctly your suggestion, the event would essentially be a "request to poll me for this type or these types of data", then resmgr would use the corresponding policy interfaces to poll the data and do whatever needs to be done with it. One thing that is a bit difficult on that path is propagating errors back to the policy, if there is a need.
Can we add push functionality using existing BackendOptions.SendEvent, so a policy would send an event to resource manager, telling it what kind of its data has changed...
Indeed, using SendEvent and resmgr eventProcessing looks useful.
I'd prefer a policy saying directly "these are the DRA devices I want to publish from this node from this point on", instead of two-phase "I want resmgr to ask me again what devices I want to publish in a new situation", and then share them only later when the question comes.
Even in the two-phase case, most likely the policy would write the devices it wants to publish (or it has previously published, no difference due to async publishing) to cache because otherwise it might find it difficult to match claims in cache to devices it has published.
In the direct case, when the policy writes []resourceapi.Devices to the cache, the cache could then SendEvent() to resmgr about DRA devices having changed in the cache, which would eventually trigger publishing them.
That said, I'm not sure if wiring cache to publishing DRA takes too much control from a policy.
Hmm... error propagation mentioned by @klihub would be lacking in the cache-based triggering, too.
It might actually be the reason to have explicit PublishDRADevices([]resourceapi.Device) error in resmgr API that policies would call.
Hmm... error propagation mentioned by @klihub would be lacking in the cache-based triggering, too.
> It might actually be the reason to have explicit PublishDRADevices([]resourceapi.Device) error in resmgr API that policies would call.
@askervin @bart0sh Yes, being able to propagate back an error is the pro in a direct call. A potential con would be that if there is locking on multiple layers, then this is an opposite control flow than normal event processing, so there is a danger of deadlock by inverted lock ordering.
> Hmm... error propagation mentioned by @klihub would be lacking in the cache-based triggering, too.
> It might actually be the reason to have explicit PublishDRADevices([]resourceapi.Device) error in resmgr API that policies would call.
> @askervin @bart0sh Yes, being able to propagate back an error is the pro in a direct call. A potential con would be that if there is locking on multiple layers, then this is an opposite control flow than normal event processing, so there is a danger of deadlock by inverted lock ordering.
@klihub I implemented the direct call and pushed it as a separate commit "dra: let the policy push its devices to the resource manager."
It's implemented the following way: resmgr passes itself to the policy as BackendOptions.Owner, the policy calls it whenever its devices change, and gets any error back directly. There are only two locks on this path, and they are always taken in the same order: 1. outer resmgr lock: the policy runs when it's held and doesn't take it again. 2. inner driver's lock: nnothing is called back while it is held: PublishResources just hands the devices to the kubeletplugin controller, which publishes and retries asynchronously.
I've also tested it with all related unit tests and dra e2e test for template policy from https://github.com/containers/nri-plugins/pull/817.
<!-- ccr-overview-v2 -->
Copilot review overview
🟢 Approval recommended
The policy boundary, publication lifecycle, backend stubs, and associated tests are consistent and complete.
Review effort: Balanced
Findings: None
nit: we now have two mechanisms for exposing direct callbacks to the remsgr layer: The old SendEvent and the new Owner. It would be cleaner to just have one, and Owner is a much cleaner, better and easy to extend one at that, so eventually we could/should fold SendEvent into it. But we can do that with a separate subsequent PR once this is merged.
nit: this makes it even more obvious, that we should fold SendEvent into Owner, as the latter is a much cleaner interface for exposing callbacks to policies.
LGTM.
klihub
bart0sh
Let the policy decide what the DRA driver publishes
Second PR of the DRA series, on top of #788. It gives
policy.Backendandpolicy.Policythe two claim methods of the DRA interface, gives all threebackends identical no-op implementations of them, and lets the active policy
push the devices the driver publishes, instead of the driver publishing a
fixed empty slice.
On a cluster this is still inert: no backend publishes any devices, so an
enabled driver registers and publishes an empty
ResourceSlice, exactly asafter #788. What changes is who decides that.
The interface
A policy gets two methods, called by resmgr:
and one method it can call on resmgr, through the new
BackendOptions.Owner:That is the whole extension point for DRA, and it is deliberately narrow:
Upstream types only. No
Claim,ClaimAllocationorCDIEdittype of ourown.
resourceapi.ResourceClaim,resourceapi.DeviceRequestAllocationResultand
specs.ContainerEditsalready carry everything the boundary needs,including
ShareIDandConsumedCapacityfor devices with consumablecapacity, so the interface adds no vocabulary a reader has to learn. The only
new dependency is
tags.cncf.io/container-device-interface/specs-go.ReleaseClaimtakes a UID and nothing else, because a UID is all theunprepare path has:
kubeletpluginhandsUnprepareResourceClaimsonlynamespace, name and UID, with no allocation results. So the policy has to keep
whatever it needs to undo an allocation, keyed by claim UID. It wants that
anyway, since it also has to keep that state across a restart. Unlike its
container allocations, it cannot rebuild it from the running containers: a
claim may have no container yet.
The returned edits correspond to
resultspositionally:edits[i]belongsto
results[i]. That is what lets the driver assemble a CDI spec from themwithout knowing what any single edit means.
Publishing is a push
The policy calls
PublishDRADeviceswhenever its devices change: typicallyonce from
Start, and again from wherever it learns that they changed,Reconfigurefor instance. Each call replaces what was published before.left off for lack of a node name or a kubernetes client, the call is a no-op.
starts, and devices pushed before the driver registers with the kubelet are
published when it does.
driver is alive and offers nothing right now, and a policy which stops
offering devices does not leave a stale slice behind.
over to the
kubeletplugincontroller, which does the actual publishingasynchronously and retries failures itself, so an error means we could not
even get that far. What to do about an unusable DRA configuration is up to the
policy: it can fail
StartorReconfigure, or warn and publish nothing.An earlier revision had resmgr pull the devices with a
DRADevices()method,once at start. The push replaces it, following the review discussion: it
republishes for free when the devices change, and it keeps the error with the
policy that caused it.
Locking. A policy runs with resmgr's lock held, so
PublishDRADevicesmust not and does not take it. Below that, the driver has a mutex of its own,
guarding only its registration and the devices published last. Nothing is
called back while that mutex is held, and no kubelet request takes it: those
take resmgr's lock, and nothing else. The locks are therefore always taken in
the same order, resmgr's first, and the call from the policy cannot deadlock
against event processing or a kubelet request.
Adding a device type later touches no driver code
Say topology-aware wants to publish isolated cores alongside high-priority
ones. It pushes more devices, with whatever attributes it wants them selected
by, and teaches
AllocateClaimwhat to do with a request for them.pkg/resmgr/drais untouched: it never reads a device attribute, and there isa test asserting it passes devices through unchanged. A
DeviceClassselectson
device.driverplus whatever attributes the policy chose. Balloons gainsDRA support the same way, by replacing two stubs and publishing its devices,
all in its own package.
Why the claim methods merge without a caller
The claim dispatch path that calls
AllocateClaim/ReleaseClaimis the nextPR. Leaving the two methods out here would mean touching
policy.goand allthree backends twice for one interface, and would split the subtle parts of
the contract (idempotency across repeated prepares, the positional edits, being
the last line of defense against handing the same resources to two claims)
away from the rest of the boundary. The interface is what is under review here,
so it is reviewed as one piece.
Deliberately left for later
AllocateClaim/ReleaseClaim, plus the CDI spec store that turns the returned edits intosomething kubelet can inject. Next PR (#806).
example for policy authors and as a second implementation of this interface
written before the first one is finished, then topology-aware.
allocates (#817).
Worth a reviewer's attention
follows is built on them, and this is the cheapest point at which to move
them.
pkg/resmgr/policygained onlyresourceapi,specsandtypesimports, and no dependency on
pkg/resmgr/dra. resmgr implementspolicy.Ownerand forwards to the driver, so neither package knows the other.pool named after the node, split into slices of at most
ResourceSliceMaxDevices.policy.ErrNoDRAClaims, not a "not implemented yet" placeholder. Each ofthese policies genuinely does not support DRA claims, and
errors.Isworks onthat answer. None of them publishes any devices.
Testing
go test ./...passes, and golangci-lint finds no issues. New tests cover:AllocateClaim/ReleaseClaimforwarders on thepolicystruct, withsuccess and error propagation;
pushed after it started, each ending up as exactly one published slice;
through unchanged, attributes and capacity, and chunking at, one past and
well past the per-slice limit;
PublishDRADevicesbeing a no-op when resmgr runs without a driver.The template DRA e2e test in #817 runs on top of this and passes on
Kubernetes 1.37.