Skip to content

Support per-request CPU allocation in multi-request ResourceClaims - #407

Open
pravk03 wants to merge 5 commits into
kubernetes-sigs:mainfrom
pravk03:handle-requests-in-claims
Open

pravk03 wants to merge 5 commits into
kubernetes-sigs:mainfrom
pravk03:handle-requests-in-claims

Conversation

@pravk03

@pravk03 pravk03 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it

Today the driver writes one CDI device per claim (DRA_CPUSET_=) and binds one container to the entire claim. If a ResourceClaim has two requests (a, b) and two containers in the same pod reference request: a and request: b, the first container gets CPUs for both requests and the second fails with CreateContainerError.

This PR splits claim allocations, CDI devices, and container bindings per request so each container in a pod gets only the CPUs for the request it references.

Which issue(s) this PR is related to

Fixes #389

Special notes for reviewers

Release note

Support per-request CPU allocation for multi-request ResourceClaims so different containers in the same pod can bind distinct requests of one claim and receive only their own request's CPUs.

AI usage disclosure

YES — used an AI coding assistant to help draft, refactor, and review the implementation, unit/E2E tests, and documentation. All changes were reviewed and verified by the author.

Summary by CodeRabbit

  • New Features
    • Multi-request CPU claims can now assign separate requests to different containers within the same pod, with request-specific CPU allocations and metadata.
    • Added an example showing how to configure a pod with multiple requests in one claim.
  • Bug Fixes
    • Claims cannot be shared across pods, and the same request cannot be assigned to multiple containers. Invalid assignments leave the pod pending with an error.
  • Documentation
    • Updated guidance on claim sharing, CPU requests and limits, and per-request CDI behavior.
    • Added upgrade and rollback guidance for the new per-request behavior.

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 28, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kubernetes-prow kubernetes-prow Bot added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 28, 2026
@netlify

netlify Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

👷 Deploy request for dra-driver-cpu pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit e0b258e

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pravk03

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

The driver now allocates and tracks CPU sets by ResourceClaim request, emits request-specific CDI devices and environment variables, and binds requests to containers within one pod. Tests, examples, and documentation cover multi-request claims, ownership, synchronization, and upgrade or rollback behavior.

Changes: Request-scoped allocation state

Layer / File(s) Summary
Request-level binding and ownership
pkg/store/allocation_state.go, pkg/store/allocation_state_test.go
Allocation state now binds containers to specific claim requests, validates request CPU sets, and tracks claim ownership by pod.
Request ownership checkpoints
pkg/store/allocation_state_checkpoint.go, pkg/store/allocation_state_checkpoint_test.go
Checkpoints now store claim-level pod ownership and request-level container names. Loading validates the ownership and container-name fields.

Per-request CDI and driver flow

Layer / File(s) Summary
Per-request CDI preparation
pkg/driver/cdi.go, pkg/driver/driver.go, pkg/driver/cdi_test.go, pkg/driver/dra_hooks.go, pkg/driver/dra_hooks_test.go
The CDI manager stores multiple request-specific devices in one claim spec. DRA preparation builds and reserves per-request CPU mappings.
NRI synchronization and container binding
pkg/driver/nri_hooks.go, pkg/driver/nri_hooks_test.go, pkg/driver/nri_reconnect_test.go, pkg/driver/startup_test.go, pkg/driver/synchronization_test.go
NRI synchronization parses and validates request-specific CDI allocations. Container creation binds the corresponding claim requests.

Validation and guidance

Layer / File(s) Summary
Multi-request tests and workload guidance
test/e2e/cpu_assignment_test.go, test/e2e/e2e_suite_test.go, test/e2e/metadata_test.go, hack/examples/pod_with_multi_request_claim.yaml, docs/user/feature-support.md, docs/user/how-it-works.md, docs/user/upgrade.md, docs/user/workload-requirements.md
End-to-end tests and the example cover per-request allocation and container mapping. The documentation describes claim ownership, CDI entries, workload requirements, and upgrade or rollback behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Synchronize
  participant CdiManager
  participant AllocationState
  participant CreateContainer
  Synchronize->>CdiManager: GetDeviceEnv(specKey)
  CdiManager-->>Synchronize: Request-specific environment edits
  Synchronize->>AllocationState: Reserve per-request CPU sets
  CreateContainer->>AllocationState: Bind ClaimRequest CPU sets
Loading

Possibly related issues

  • #390: This change allows containers in one pod to bind different requests from the same ResourceClaim, addressing the issue’s one-container-per-claim restriction.

Possibly related PRs

Merge Risk: Moderate · previous review 9a6f3

The new per-request claim handling looks sound for the main scenario in the linked issue. Upgrading a node in place can lose recorded pod/container ownership of already-prepared claims, because the checkpoint format changed without a version bump or migration. Fix that, resolve the merge conflict, and tighten a few store consistency checks before merging.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #389 has one direct link and no closed or contextual status. Its coding requirement is inferred from the reported symptoms. The PR changes ownership from one owner per claim to one owner per req… Clarify the expected behavior in #389 when two containers in one pod reference the same request of a multi-request claim. Specify whether the second container must start with the same CPUs, must start with no CPUs, or must be rejected with …
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: per-request CPU allocation for ResourceClaims that contain multiple requests. The changeset splits claim allocations, CDI specs, and container bindings by request, whi…
Out of Scope Changes check Passed The changes address per-request allocation, which #389 requires. The changed areas are:
- pkg/store/allocation_state*.go: per-request ownership and checkpoint format.
- pkg/driver/cdi.go, `dra_hoo…
Full details: Title check

Explanation

The title names the main change: per-request CPU allocation for ResourceClaims that contain multiple requests. The changeset splits claim allocations, CDI specs, and container bindings by request, which matches the title. The title is specific and does not cover every detail, which is expected.

Full details: Out of Scope Changes check

Explanation

The changes address per-request allocation, which #389 requires. The changed areas are:

  • pkg/store/allocation_state*.go: per-request ownership and checkpoint format.
  • pkg/driver/cdi.go, dra_hooks.go, nri_hooks.go: per-request CDI devices and env vars, with request-keyed binding.
  • Matching unit tests and mocks.
  • E2E helpers and tests for per-request and multi-request claims.
  • Docs and an example YAML that describe the new model.

The FirstAvailable subrequest handling and the legacy DRA_CPUSET_<uid> compatibility support the per-request split. They are not separate features. The upgrade and rollback documentation describes behavior that this PR changes, so it is related. No change was found that is unconnected to the request-scoped allocation.

Full details: Linked Issues check

Explanation

Issue #389 has one direct link and no closed or contextual status. Its coding requirement is inferred from the reported symptoms. The PR changes ownership from one owner per claim to one owner per request. The summary and docs state that a container can map to a request and that a container without request maps to all requests. Two sub-cases follow from this design:

  1. Containers that reference different requests of one claim (for example c1->a, c2->b): The summary shows that Bind and CreateContainer bind per-request CPUs. The new tests in nri_hooks_test.go (TestCreateContainerMultiRequest) and allocation_state_test.go cover this case. The E2E test verifyPerRequestClaim checks distinct CPUs per container. This sub-case is implemented.

  2. Two containers that both reference request a (the exact scenario in #389): The docs and allocation_state.go still reject this. Bind rejects "binding a request to another container", and docs state that violations cause CreateContainerError. The issue text does not state the expected result for this case. It lists only the failures. It is therefore unclear whether the still-present rejection satisfies #389, or whether the issue requires c2 to start.

The repository was not inspected for the issue's intended outcome. The issue body contains no acceptance criteria.

Resolution

Clarify the expected behavior in #389 when two containers in one pod reference the same request of a multi-request claim. Specify whether the second container must start with the same CPUs, must start with no CPUs, or must be rejected with a specific error. Then reassess the same-request case against that behavior. Use the code paths (*AllocationState).Bind and IsOwner in pkg/store/allocation_state.go for that check.

@kubernetes-prow
kubernetes-prow Bot requested review from ffromani and pohly November 28, 2026 13:28
@kubernetes-prow kubernetes-prow Bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 28, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Check request CPU assignments on repeat reservation. · allocation_state.go:348-350

pkg/store/allocation_state.go:348-350
Minor · Data Integrity & Integration · Quick win

Check request CPU assignments on repeat reservation.

If the store has x={2}, y={3}, Reserve also accepts x={3}, y={2} because the claim CPU set is unchanged. It keeps the first split. A subsequent Bind for x={3} then fails. Synchronize passes the CDI request map to Reserve and then passes the request CPU set to Bind, so this mismatch can surface after reservation reports success. Compare named assignments before returning success. Preserve the aggregate-only legacy repeat against the same claim CPU set. (raw.githubusercontent.com)

Additional comments: 1

pkg/store/allocation_state.go: 1

164-164: Minor · Data Integrity & Integration · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Reject an empty request key mixed with named requests.

The shared validator accepts ""={2}, y={3}. If a prepare retry needs x, it falls back to "" and emits a legacy CDI device for CPU 2. Bind interprets that key as the whole claim and rejects it because the claim has CPUs 2 and 3. Reject mixed maps in the shared validator so both reservation and checkpoint restore enforce the same rule. Keep the singleton empty-key format described in docs/user/upgrade.md. (raw.githubusercontent.com)

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 27682fa and 9a6f321.

Files selected for processing: 22

  • docs/user/feature-support.md
  • docs/user/how-it-works.md
  • docs/user/upgrade.md
  • docs/user/workload-requirements.md
  • hack/examples/pod_with_multi_request_claim.yaml
  • pkg/driver/cdi.go
  • pkg/driver/cdi_test.go
  • pkg/driver/dra_hooks.go
  • pkg/driver/dra_hooks_test.go
  • pkg/driver/driver.go
  • pkg/driver/nri_hooks.go
  • pkg/driver/nri_hooks_test.go
  • pkg/driver/nri_reconnect_test.go
  • pkg/driver/startup_test.go
  • pkg/driver/synchronization_test.go
  • pkg/store/allocation_state.go
  • pkg/store/allocation_state_checkpoint.go
  • pkg/store/allocation_state_checkpoint_test.go
  • pkg/store/allocation_state_test.go
  • test/e2e/cpu_assignment_test.go
  • test/e2e/e2e_suite_test.go
  • test/e2e/metadata_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread pkg/driver/cdi.go Resolved
Comment thread pkg/driver/cdi.go Resolved
Comment thread pkg/driver/dra_hooks_test.go Resolved
Comment thread pkg/store/allocation_state_test.go Resolved
Comment thread pkg/store/allocation_state.go Resolved
@pravk03
pravk03 force-pushed the handle-requests-in-claims branch from 9a6f321 to 8e6df2b Compare November 28, 2026 17:37
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 28, 2026
…ner bindings

Currently we track ownership per container using {PodUID, ContainerName}, and Bind/Unbind/IsOwner operate on the whole claim UID.
That prevents containers in the same pod from binding different requests of a multi-request claim, and doesn't cleanly
enforce that a claim belongs to a single pod across sibling requests.

This commit splits ownership into a single ownerPod on the claim and a list of bound container names per request.
Containers in the same pod can now bind separate requests. The v1 checkpoint schema and existing callers are updated to match.
CDI specs are not updated yet, this prepares for follow up commit that split CDI and DRA/NRI hooks per request.
Currently each claim CDI spec file holds a single device (claim-<uid>) with one
env var (DRA_CPUSET_<uid>=<cpus>), so kubelet cannot filter CDI devices per
request.
This commit updates CdiManager to store multiple devices in the claim's single
spec file (so follow-up commits can write per-request entries like
claim-<uid>_<request> with DRA_CPUSET_<uid>_<request>=<cpus>) and read env vars
across all devices in that spec.
Split prepared CPU allocations and CDI devices by base request name so
containers referencing a single request of a multi-request ResourceClaim
receive only that request's CPUs.
Update NRI CreateContainer and Synchronize to parse, validate, and
bind per-request allocations while keeping compatibility with legacy whole-claim DRA_CPUSET_<uid> entries.
@pravk03
pravk03 force-pushed the handle-requests-in-claims branch from 8e6df2b to e0b258e Compare November 28, 2026 18:01
@pravk03
pravk03 marked this pull request as ready for review November 28, 2026 18:03
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Containers that reference a single request of a multi-request claim are not handled

1 participant