Repository navigation
feat(checkpoint): versioned DRA kubelet plugin checkpoint API and store - #2
Conversation
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>
|
@fishman: The label(s) DetailsIn response to this:
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. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
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:
For more information about GitHub Code Scanning, check out the documentation. |
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:
k8s.io/kubernetesas a library: "Use of thek8s.io/kubernetesmodule ork8s.io/kubernetes/...packages as libraries is not supported." (README). checkpointmanager is not a published staging module, so it can change in any release.k8s.io/kubernetesand moved its checkpoint to a versioned API object in Align checkpoint format with Kubernetes API conventions.k8s.io/kubernetesis 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, andUpdateto write once per kubelet call instead of once per claim.api/checkpoint/v1/doc.gonotes how to add a v2.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?: