Skip to content

feat(checkpoint): versioned DRA kubelet plugin checkpoint API and store - #2

Merged
fishman merged 16 commits into
Project-HAMi:masterfrom
fishing-agents:checkpoint
Dec 1, 2026
Merged

fishman merged 16 commits into
Project-HAMi:masterfrom
fishing-agents:checkpoint

Conversation

@fishman

@fishman fishman commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Shared checkpoint code for the HAMi DRA drivers (amd, ascend, nvidia), replacing k8s.io/kubernetes/pkg/kubelet/checkpointmanager.

Why move off checkpointmanager:

  • Kubernetes doesn't support importing k8s.io/kubernetes as a library: "Use of the k8s.io/kubernetes module or k8s.io/kubernetes/... packages as libraries is not supported." (README). checkpointmanager is not a published staging module, so it can change in any release.
  • The upstream reference driver did the same: dra-example-driver dropped k8s.io/kubernetes and moved its checkpoint to a versioned API object in Align checkpoint format with Kubernetes API conventions.
  • govulncheck stays red while k8s.io/kubernetes is imported: GO-2025-3547 and GO-2025-3521 are filed against the whole module with no fixed version, so no bump clears them.

What's in it:

  • api/checkpoint/v1: the checkpoint as a versioned API object (Checkpoint, v1, API group set by the driver). It has a common core (claims, prepared devices, CDI edits, soft/hard partitions, node partition modes) and optional amd/nvidia sections.
  • checkpoint.Store: atomic write (temp file, fsync, rename, fsync of the directory), compact JSON, a driverName check, and Update to write once per kubelet call instead of once per claim.
  • Migrates the old checkpointmanager format on first read and verifies its checksums. Deprecated, will be removed in a future version.
  • v1 is the only version for now. api/checkpoint/v1/doc.go notes how to add a v2.
  • Tests, fuzz targets (one real bug found and fixed), and benchmarks against the old code.
  • CI: build/vet/test, a generated-code check, govulncheck, fuzzing, CodeQL and Scorecard, plus a release workflow that publishes the CHANGELOG section on a tag.

Which issue(s) this PR fixes:

Benchmarks: #1. A Prepare call adding 10 claims is 40 to 55x faster from 100 claims on the node upward. Reads are 2.6 to 3.9x faster, mostly from dropping the reflection-based checksum.

Special notes for your reviewer:

Developed in fishing-agents/dra-lib, where the history before this PR lives. One commit per concern. The driver PRs follow after this merges and v0.1.0 is tagged.

Does this PR introduce a user-facing change?:

NONE

DRA kubelet plugins persisted their prepared claims through kubelet's
checkpointmanager: checksum-wrapped JSON of ad-hoc structs, imported from
k8s.io/kubernetes. That module is not meant to be used as a library, and
govulncheck reports module-wide advisories (GO-2025-3547, GO-2025-3521)
for every version of it.

This adds the checkpoint as a Kubernetes API object instead, following the
API conventions like kubernetes-sigs/dra-example-driver:

- api/checkpoint: internal and v1 types (kind Checkpoint), registered in an
  apimachinery scheme under an API group the caller chooses, with generated
  deepcopy and conversion. A common core (claims keyed by UID, prepared
  devices with their kubelet device reference, CDI container edits,
  soft/hard partitions, node partition modes, prepare state, claim status,
  node boot ID) and optional typed AMD and NVIDIA sections.
- checkpoint.Store: Read (missing file is an empty checkpoint) and Write
  (temp file in the same directory, fsync, atomic rename, temp file removed
  on failure). Every checkpoint carries a required driverName and the store
  refuses one written for another driver.
- Legacy migration: a checkpoint in the kubelet checkpointmanager format is
  checksum-verified the way checkpointmanager/checksum does, converted,
  written back in the new format and logged once as deprecated. That
  support is deprecated and will be removed in a future version.

Depends only on k8s.io/apimachinery, k8s.io/api, k8s.io/utils and the CDI
spec. Adds CI (build, vet, test, generated code check, govulncheck),
CodeQL, Scorecard and a tag-triggered release workflow, and renames the
project references to dra-lib.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
Write the checkpoint without pretty printing, like the legacy kubelet
checkpointmanager format; use jq to read it. A test checks the file is a
single line.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
Update reads the checkpoint from disk, applies all changes of one
NodePrepareResources or NodeUnprepareResources call and writes once (one
encode, one fsync) instead of once per claim. Nothing is written if the
mutation fails. The store keeps no cache: every Read and Update reads the
file, so the caller only needs to hold its own lock.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
After renaming the temp file over the checkpoint, fsync the parent
directory so the rename survives a power loss. A failure is returned; the
new content is already visible at that point.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
Compare the legacy kubelet checkpointmanager format (checksum over the
marshalled struct, temp file, fsync, rename) with the v1 format through
the Store: write, read and a Prepare-style read+modify+write cycle at 1,
10, 100, 1000 and 10000 claims with one device each and at 100 claims with
8 devices each, with realistic CDI container edits per device. Each case
reports the checkpoint file size. Run with TMPDIR on a real filesystem so
fsync is measured.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
golang.org/x/net v0.38.0 (indirect, via k8s.io/apimachinery) has
GO-2026-6617, GO-2026-6612, GO-2026-6611 and GO-2026-6603, fixed in
v0.60.0. golang.org/x/text moves to v0.42.0 with it. x/net v0.60.0
requires Go 1.26.0, so the go directive moves from 1.25.0 to 1.26.0;
k8s.io/apimachinery stays at v0.34.0.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
…e round trip

Go native fuzz targets: FuzzDecodeV1 decodes arbitrary bytes as a v1
checkpoint and checks that a decoded checkpoint survives encode+decode;
FuzzLegacy reads arbitrary bytes as a legacy checkpointmanager file and
checks that bad checksums or JSON are rejected without touching the file
and valid input migrates; FuzzRoundTrip writes a checkpoint built from
fuzzed fields, reads it back and checks another driver is refused. Seeds
come from the legacy fixtures. FuzzRoundTrip builds the partition memory
from a byte count: quantities parsed from arbitrary strings can have
exponents for which Quantity.Cmp does not finish.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
The decoder defaulted a missing apiVersion to the internal version, so
such a file skipped conversion and was decoded into the internal types,
which have no JSON tags, keeping its kind in TypeMeta. Default to the
on-disk v1 version instead. Found by FuzzDecodeV1; the input is kept as
a regression case under testdata/fuzz.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
Run FuzzDecodeV1, FuzzLegacy and FuzzRoundTrip for 60s each, one go
test -fuzz invocation per target, on pull requests and pushes to master.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
Remove the internal checkpoint types and the generated conversion: the
store reads and writes *v1.Checkpoint directly with the v1 scheme, and the
legacy migration builds v1 objects. install.NewScheme, the API group and
driverName checks and the on-disk format stay the same; a checkpoint
written before this change (testdata/v1-checkpoint.json) decodes unchanged
and is written back byte for byte. Codegen is deepcopy only. The v1
package documents how a v2 would be added.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
… format

Replace the benchmark's own legacy encoder with a test-only helper that
writes and verifies the kubelet checkpointmanager format (checksum:
FNV-32a over the spew dump), written independently of legacy.go. The
benchmarks, store tests and fuzz seeds use it, and tests check that
legacy.go migrates what the helper writes and rejects a tampered
checksum.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
Replace the Deprecated comment repeated on every symbol of legacy.go with
a single file header: the whole file reads the deprecated kubelet
checkpointmanager format and is removed together.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
The repository moves to Project-HAMi. Update the module path, all
imports and the CHANGELOG link to the benchmark issue, now
Project-HAMi#1.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
RoundTripTestForAPIGroup only covers internal types, of which there are
none since v1 became the only version, so TestRoundTrip passed without
testing Checkpoint. Use RoundTripExternalTypesWithoutProtobuf, which
fuzzes v1.Checkpoint through the scheme.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
FuzzDecodeV1 and FuzzLegacy compared decoded checkpoints with
equality.Semantic, which calls Quantity.Cmp; it does not finish for
quantities with huge exponents, so workers stalled. Compare encoded bytes
instead (a seed covers it). Also skip inputs with a large negative
exponent: resource.ParseQuantity in k8s.io/apimachinery does not finish
on "1e-2100000000", so decoding such a checkpoint stalls the worker.

Signed-off-by: Reza Jelveh <fishmangit@dynamia.ai>
@hami-robot

hami-robot Bot commented Dec 1, 2026

Copy link
Copy Markdown

@fishman: The label(s) kind/feature cannot be applied, because the repository doesn't have them.

Details

In response to this:

What type of PR is this?

/kind feature

What this PR does / why we need it:

Shared checkpoint code for the HAMi DRA drivers (amd, ascend, nvidia), replacing k8s.io/kubernetes/pkg/kubelet/checkpointmanager.

Why move off checkpointmanager:

  • Kubernetes doesn't support importing k8s.io/kubernetes as a library: "Use of the k8s.io/kubernetes module or k8s.io/kubernetes/... packages as libraries is not supported." (README). checkpointmanager is not a published staging module, so it can change in any release.
  • The upstream reference driver did the same: dra-example-driver dropped k8s.io/kubernetes and moved its checkpoint to a versioned API object in Align checkpoint format with Kubernetes API conventions.
  • govulncheck stays red while k8s.io/kubernetes is imported: GO-2025-3547 and GO-2025-3521 are filed against the whole module with no fixed version, so no bump clears them.

What's in it:

  • api/checkpoint/v1: the checkpoint as a versioned API object (Checkpoint, v1, API group set by the driver). It has a common core (claims, prepared devices, CDI edits, soft/hard partitions, node partition modes) and optional amd/nvidia sections.
  • checkpoint.Store: atomic write (temp file, fsync, rename, fsync of the directory), compact JSON, a driverName check, and Update to write once per kubelet call instead of once per claim.
  • Migrates the old checkpointmanager format on first read and verifies its checksums. Deprecated, will be removed in a future version.
  • v1 is the only version for now. api/checkpoint/v1/doc.go notes how to add a v2.
  • Tests, fuzz targets (one real bug found and fixed), and benchmarks against the old code.
  • CI: build/vet/test, a generated-code check, govulncheck, fuzzing, CodeQL and Scorecard, plus a release workflow that publishes the CHANGELOG section on a tag.

Which issue(s) this PR fixes:

Benchmarks: #1. A Prepare call adding 10 claims is 40 to 55x faster from 100 claims on the node upward. Reads are 2.6 to 3.9x faster, mostly from dropping the reflection-based checksum.

Special notes for your reviewer:

Developed in fishing-agents/dra-lib, where the history before this PR lives. One commit per concern. The driver PRs follow after this merges and v0.1.0 is tagged.

Does this PR introduce a user-facing change?:

NONE

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cb549522-459a-4fb5-960a-69a1f67e3f09
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@hami-robot

hami-robot Bot commented Dec 1, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fishman

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

@hami-robot hami-robot Bot added the approved label Dec 1, 2026
@fishman
fishman merged commit 72fcebe into Project-HAMi:master Dec 1, 2026
10 of 11 checks passed
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants