Skip to content

driver: restore the allocation checkpoint on startup - #401

Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-sigs:mainfrom
AutuSnow:fix/issue-258-load-ledger
Nov 27, 2026
Merged

kubernetes-prow[bot] merged 1 commit into
kubernetes-sigs:mainfrom
AutuSnow:fix/issue-258-load-ledger

Conversation

@AutuSnow

@AutuSnow AutuSnow commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it

#367 writes the allocation checkpoint but nothing reads it. So after a driver restart the first Synchronize still rebuilds prepared claims from container env + CDI, and a claim that was unprepared before the restart can come back if the runtime still has its env and CDI spec around.

This wires the load in:

  • New loads the checkpoint right after creating the allocation state, before the DRA and NRI plugins start. If it can't be loaded (corrupt, other node, other topology) the driver fails to start instead of guessing.
  • If a checkpoint was restored, the first Synchronize uses the same rules a warm one already does: the checkpoint is the source of truth for prepared claims. Env can't re-prepare a claim that isn't in it, and prepared claims without a running container stay reserved until Unprepare.
  • No usable checkpoint (first start, upgrade, or one from a previous boot) keeps today's behavior: rebuild from env.
  • LoadState now returns whether it restored something, so the driver can tell "no checkpoint" from "empty checkpoint". An empty checkpoint means nothing is prepared, a missing one means we don't know.

Which issue(s) this PR is related to

Refs #258

Special notes for reviewers

Release note

The driver now restores its allocation state checkpoint on startup and uses it to recover prepared claims after a restart. A checkpoint that can't be loaded makes the driver fail to start.

AI usage disclosure

YES. An AI assistant helped draft the tests and this description; I reviewed and tested the changes.

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

netlify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

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

Visit the deploys page to approve it

Name Link
🔨 Latest commit acf405b

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 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

No actionable comments were generated in the recent review.

Walkthrough

The driver now loads allocation checkpoints during construction. The first synchronization uses restored prepared-claim state as trusted state. Documentation and tests describe checkpoint loading, restoration status, and synchronization behavior.

Changes: Allocation checkpoint restoration

Layer / File(s) Summary
Checkpoint restoration status
pkg/store/allocation_state_checkpoint.go, pkg/store/allocation_state_checkpoint_test.go
LoadState returns whether it restored state. Tests check this result for successful loads, missing checkpoints, and checkpoints from another boot.
Driver startup loading
pkg/driver/driver.go, pkg/driver/checkpoint_restore_test.go
New loads allocation state and returns an error if loading fails. Driver tests cover restored state and corrupted checkpoint data.
First synchronization with restored state
pkg/driver/nri_hooks.go, pkg/driver/checkpoint_restore_test.go, docs/dev/persistence.md, docs/user/configuration.md
Synchronization trusts prepared claims after restoration. Tests and documentation describe the first synchronization and checkpoint startup behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CPUDriver
  participant AllocationState
  participant Synchronize
  participant RuntimeCDIAndEnvironment
  CPUDriver->>AllocationState: LoadState from checkpoint
  AllocationState-->>CPUDriver: restored status or load error
  CPUDriver->>Synchronize: use restored status on first synchronization
  Synchronize->>RuntimeCDIAndEnvironment: inspect runtime claim data
  Synchronize-->>Synchronize: trust restored prepared claims
Loading

Possibly related issues

Possibly related PRs

  • kubernetes-sigs/dra-driver-cpu#367: This PR builds on the checkpoint format and loading logic introduced there by loading the checkpoint during driver startup and using restored state during synchronization.
Merge Risk: Minimal · previous review a78d7

The driver now restores its allocation checkpoint at startup, so a claim that was unprepared before a restart is not re-prepared from stale container state. A corrupt or mismatched checkpoint now stops startup, which is documented. No concrete defect was found, and merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the driver now loads the allocation checkpoint during startup (in New). The raw summary shows CPUDriver.New loading the checkpoint, LoadState reporting restoration, Sy…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: the driver now loads the allocation checkpoint during startup (in New). The raw summary shows CPUDriver.New loading the checkpoint, LoadState reporting restoration, Synchronize trusting restored prepared state, and tests for restart restoration. The title matches the PR objective. It is short, specific, and uses the repository's scope-prefix style ('driver:').

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3df2de3 and a78d758.

Files selected for processing: 7

  • docs/dev/persistence.md
  • docs/user/configuration.md
  • pkg/driver/checkpoint_restore_test.go
  • pkg/driver/driver.go
  • pkg/driver/nri_hooks.go
  • pkg/store/allocation_state_checkpoint.go
  • pkg/store/allocation_state_checkpoint_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/driver.go
// Fail closed: a checkpoint we cannot trust must not be replaced by guesses from the runtime env.
restored, err := plugin.allocationState.LoadState(logger, manager)
if err != nil {
return nil, fmt.Errorf("failed to load allocation state checkpoint: %w", err)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am pretending that if someone changes the reserved CPU to overlap with the prepared declaration, it will now cause the New to fail ("CPU exceeds available set"), so the pod crash loop and kubelet cannot undo any preparation on that node. Is this the expected result? Should we keep this abnormal operational behavior that leads to blocking

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a very good point. For now I'd implement the simplistic solution - crashloop and brick the node. But we should file a followup issue, discuss it deeply and reach (and document) a consensus before 0.4.0. (reaching a consensus and documenting it should be a blocker for 0.4.0).

I think an appealing alternative would be to degrade the driver state and allow only Unprepare of the conflicting allocations, until there are conflicting allocations. While this seems an interesting way forward, how would the driver advertise its degraded state? can we (ab) use the DRA health mechanism to detect and report this state? how well would this work in practice? this is why I'd defer to a targeted conversation this topic.

Comment thread pkg/driver/nri_hooks.go Outdated
envs, err := cp.cdiMgr.GetDeviceEnv(deviceName)
if err != nil {
if cp.hasSynchronized && prepared && owned {
if trustPrepared && prepared && owned {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With a restored checkpoint, a single owned claim whose CDI spec is gone now fails the first Synchronize after restart, while before it was just skipped. #258 said one bad container shouldn’t block recovery for the whole node. Do we want to keep the warm-path behavior here, or skip and report it?

@ffromani ffromani Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

log them is the bare minimum but once again we should surface this information somehow, preferably using kubernetes objects. Again unfortunately I don't have a good solution atm. Worth another separate issue.
[EDIT] I managed to answer to everything but your actual question, sorry about that. Re: I think skipping and continuing recovery is the best (less worst?) thing we can do now. THis will need tightening though, as it is likely to create an inconsistent state.

@AutuSnow AutuSnow Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!it now skips and keeps going. I applied it to the warm path too, since that hard failure came from #360 and pravk03’s concern there was the same one. A skipped container ends up treated as shared while its checkpointed CPUs stay reserved, so that’s the inconsistency you mentioned. I’ll put the tightening and the “surface it via k8s objects” part in a follow-up issue. The no-checkpoint path still fails on these, since env is the only record there.

@AutuSnow

AutuSnow commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

/cc @ffromani I think we can move on to the next step now

@ffromani

Copy link
Copy Markdown
Contributor

/cc @ffromani I think we can move on to the next step now

absolutely. Will review shortly. Thanks for taking care so quickly.

@ffromani ffromani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

overall LGTM with some minor nits and a couple more tests I'd like to add.
The points you raised are very good and I think do deserve separate and careful evaluation. Resolution (whatever it is) of them should be a blocker for 0.4.0

The loader implementation ignores checkpoints from a different boot.
**NOTE**: Checkpoint restoration is not yet wired into driver startup.
The driver loads the checkpoint on startup and ignores checkpoints from a different boot.
A checkpoint that cannot be loaded (corrupted, different node or CPU topology) makes the driver fail to start.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should document the remediation for driver failing to start for incorrect checkpoint load: just delete the checkpoint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually not. This is what we do in practice today with kubelet, and it's another bad habit leaking. We would need a more precise treatment. E.g, recommendation by failure type. Reserved CPUs for example deserves a separate treatment than generic checkpoint file corruption. Probably better to defer this elaboration to another followup

Comment thread pkg/driver/driver.go
// Fail closed: a checkpoint we cannot trust must not be replaced by guesses from the runtime env.
restored, err := plugin.allocationState.LoadState(logger, manager)
if err != nil {
return nil, fmt.Errorf("failed to load allocation state checkpoint: %w", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a very good point. For now I'd implement the simplistic solution - crashloop and brick the node. But we should file a followup issue, discuss it deeply and reach (and document) a consensus before 0.4.0. (reaching a consensus and documenting it should be a blocker for 0.4.0).

I think an appealing alternative would be to degrade the driver state and allow only Unprepare of the conflicting allocations, until there are conflicting allocations. While this seems an interesting way forward, how would the driver advertise its degraded state? can we (ab) use the DRA health mechanism to detect and report this state? how well would this work in practice? this is why I'd defer to a targeted conversation this topic.

Comment thread pkg/driver/nri_hooks.go Outdated
envs, err := cp.cdiMgr.GetDeviceEnv(deviceName)
if err != nil {
if cp.hasSynchronized && prepared && owned {
if trustPrepared && prepared && owned {

@ffromani ffromani Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

log them is the bare minimum but once again we should surface this information somehow, preferably using kubernetes objects. Again unfortunately I don't have a good solution atm. Worth another separate issue.
[EDIT] I managed to answer to everything but your actual question, sorry about that. Re: I think skipping and continuing recovery is the best (less worst?) thing we can do now. THis will need tightening though, as it is likely to create an inconsistent state.

Comment thread pkg/driver/checkpoint_restore_test.go Resolved
require.Equal(t, map[string]string{"app": "0", "stale": "1,3"}, masks)
}

func TestNewFailsOnCorruptCheckpoint(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have a test which reproduces an (hopefully) impossible scenario: runtime data (CDI, env) consistent but disagreeing with the checkpointed data? This test would also document and embody our current expectations in this case.

@ffromani

Copy link
Copy Markdown
Contributor

I'm thinking about the very important edge (as in hopefully rare) cases emerged from this PR and your self-review @AutuSnow . I think as starting point a fail-close behavior is a good step forward and it delivers incremental improvement. I'm inclined to track the hard questions emerged here into separate issues and block 0.4.0 on resolution+documentation of these.
We may decide to tolerate some risks (like the kubelet does) but we need to carefully evaluate them anyway.

kubernetes-sigs#367 writes the allocation state checkpoint but nothing reads it back,
so after a driver restart the first Synchronize rebuilds prepared claims
from container env and CDI specs. That lets stale runtime state bring
back a claim that was unprepared before the restart.

Load the checkpoint in New, before the DRA and NRI plugins start, and
fail to start if it can't be loaded. When it was restored, the first
Synchronize applies the same rules as a warm one: the checkpoint is the
source of truth for prepared claims, so runtime env can't re-prepare a
claim missing from it, and prepared claims with no running container
stay reserved. Without a usable checkpoint (first start, upgrade, or a
checkpoint from a previous boot) Synchronize keeps rebuilding from env.

When the prepared claims are known (restored checkpoint or an earlier
Synchronize), a container whose runtime state disagrees with them is
logged and skipped instead of failing the whole Synchronize: missing
CDI, env/CDI mismatch, different CPUs or a different owner. The
prepared allocation and owner win, and the container is tracked as
shared. Without a checkpoint the env is the only record, so those
errors still fail recovery there.

LoadState now reports whether a checkpoint was restored, so the driver
can tell "no checkpoint" from "empty checkpoint".

Refs kubernetes-sigs#258
@AutuSnow

Copy link
Copy Markdown
Contributor Author

Filed the follow-ups:

@ffromani

Copy link
Copy Markdown
Contributor

Filed the follow-ups:

* [Decide how the driver handles a checkpoint it can't load #402](https://github.com/kubernetes-sigs/dra-driver-cpu/issues/402): decide how the driver handles a checkpoint it can't load

* [Document remediation for checkpoint load failures, per failure type #403](https://github.com/kubernetes-sigs/dra-driver-cpu/issues/403): document remediation for each load-failure type (depends on [Decide how the driver handles a checkpoint it can't load #402](https://github.com/kubernetes-sigs/dra-driver-cpu/issues/402))

* [Surface and tighten claims skipped during Synchronize #404](https://github.com/kubernetes-sigs/dra-driver-cpu/issues/404): surface and tighten claims skipped during Synchronize

thanks, added to the 0.4.0 tracker

@ffromani ffromani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/approve
/lgtm

thanks for addressing my comments. It seems good enough to move forward and close #258. Let's move on towards the 3 thorny and interesting issues raised during the review of this PR.

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 27, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AutuSnow, ffromani

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

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 27, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 27682fa into kubernetes-sigs:main Nov 27, 2026
15 checks passed
@AutuSnow
AutuSnow deleted the fix/issue-258-load-ledger branch November 27, 2026 10:39
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants