Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [FuzzDecodeV1, FuzzLegacy, FuzzRoundTrip]
include:
- {target: FuzzDecode, package: ./checkpoint/}
- {target: FuzzLegacy, package: ./checkpoint/}
- {target: FuzzRoundTrip, package: ./checkpoint/}
- {target: FuzzTestExtension, package: ./checkpoint/checkpointtest/}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -65,4 +69,4 @@ jobs:
go-version: '1.26'
check-latest: true
- name: Run ${{ matrix.target }} for 60s
run: go test ./checkpoint/ -run '^$' -fuzz '^${{ matrix.target }}$' -fuzztime 60s
run: go test ${{ matrix.package }} -run '^$' -fuzz '^${{ matrix.target }}$' -fuzztime 60s
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,50 @@ needs a new checkpoint API version (with conversion), not just a new release.

## [Unreleased]

### Changed

- **Breaking:** the store writes `api/checkpoint/v2` and is generic over a
driver extension: `NewStore[N, C, D]`, `Options[N, C, D]`,
`Checkpoint[N, C, D]`. The core is the KEP set v2 (4381, 4817, 5075, 5304):
claims with status and lifecycle, the kubelet device reference with
`shareID` and `metadata`, CDI edits. Driver-only state is the typed payload
of the driver's extension at node, claim and device level, with its own
name, schema version, codecs, forward-only migrations and legacy readers.
A store without an extension (`None`) keeps only the core.
- v1 files are read and converted to v2 (`v2.ConvertFromV1`): the vendor
sections become payloads of extension version 1, keeping their v1 JSON.
Nothing writes v1 again. A newer core or extension version, another
extension, or payloads the store cannot decode are refused and the file is
left alone.
- `FuzzDecodeV1` is `FuzzDecode` and reads v1 and v2.

### Added

- `api/checkpoint/v2`: the v2 types and `ConvertFromV1`.
- `checkpoint`: `Extension`, `Codec`, `JSONCodec`, `RawPayloads`, `None`,
`ErrNotThisLayout`.
- `checkpoint.VerifyLegacyChecksums`, for a driver's `Extension.Legacy`
readers to check a checkpointmanager file before reading it.
- `checkpoint/checkpointtest`: `FuzzExtension`, for drivers to fuzz their
extension's codecs, migrations and legacy readers from their fixtures.

### Open questions

- Strict decoding: the core decoder and `JSONCodec` still ignore unknown
fields (`Strict: false`), as in v0.1.0. Version checks refuse newer schemas;
whether unknown fields within a known version should also be refused is
undecided.

- `api/checkpoint/v1`: the state of the NVIDIA GPU and ComputeDomain kubelet
plugins of dra-driver-nvidia-gpu that v1 could not hold: `Device.ShareID` and
`Device.Metadata`; per NVIDIA device group `timeSliceApplied`, `mpsApplied`,
`computeDomain` and `type`; `pciBusID` and `id` of NVIDIA devices and
`parentPCIBusID` of MIG partitions; `PrepareAborted` claims with `abortedAt`.
All optional, so existing v1 files stay valid.
- `checkpoint`: the legacy reader reads the checkpointmanager layouts of both
NVIDIA plugins, including the ComputeDomain V1+V2, V1 only and 25.3.0-rc.2
layouts.

## [0.1.0] - 2026-12-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CONTROLLER_GEN_VERSION ?= v0.17.0
GOBIN ?= $(shell go env GOPATH)/bin

CHECKPOINT_APIS := $(CURDIR)/api/checkpoint/v1
CHECKPOINT_APIS := $(CURDIR)/api/checkpoint/v1 $(CURDIR)/api/checkpoint/v2
HEADER := $(CURDIR)/.license-header.txt

.PHONY: build vet test fmt-check tools generate generate-deepcopy verify-generate
Expand Down
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@

Shared Go library for Kubernetes DRA (Dynamic Resource Allocation) drivers.

- `api/checkpoint`: versioned kubelet plugin checkpoint API: kind `Checkpoint`,
version `v1`, in an API group the driver chooses (for example
`checkpoint.internal.example.com`). A common core (claims, prepared devices,
CDI container edits, soft/hard partitions, node partition modes) plus
optional vendor sections.
- `api/checkpoint`: versioned kubelet plugin checkpoint API: kind `Checkpoint`
in an API group the driver chooses (for example
`checkpoint.internal.example.com`). `v2` is written: a vendor-neutral core
whose fields map to the DRA KEPs 4381, 4817, 5075 and 5304, plus opaque
driver payloads per node, claim and device. `v1` is read and converted.
- `checkpoint`: `Store` reads and atomically writes the checkpoint, refuses a
checkpoint owned by another driver, and migrates the legacy kubelet
checkpointmanager format (deprecated, will be removed in a future version).
checkpoint owned by another driver or written in a newer schema, decodes
the driver's payloads with its `Extension`, migrates them forward, and
migrates the legacy kubelet checkpointmanager format (deprecated, will be
removed in a future version).
- `checkpoint/checkpointtest`: `FuzzExtension` for a driver's extension.

```go
store, err := checkpoint.NewStore(path, checkpoint.Options{
type node struct{ Modes []string `json:"modes,omitempty"` }
type device struct{ Slot *int32 `json:"slot,omitempty"` }

store, err := checkpoint.NewStore(path, checkpoint.Options[node, checkpoint.None, device]{
Group: "checkpoint.internal.example.com",
DriverName: "gpu.example.com",
Extension: &checkpoint.Extension[node, checkpoint.None, device]{
Name: "gpu.example.com", Version: 1,
Node: checkpoint.JSONCodec[node]{}, Device: checkpoint.JSONCodec[device]{},
},
})
err = store.Update(func(cp *checkpoint.Checkpoint[node, checkpoint.None, device]) error {
// cp.Core holds the claims; cp.Node, cp.Claims, cp.Devices the driver state.
return nil
})
cp, err := store.Read()
err = store.Write(cp)
```

Depends on k8s.io/apimachinery, k8s.io/api and the CDI spec only, so drivers
Expand Down
2 changes: 2 additions & 0 deletions api/checkpoint/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

v1 "github.com/Project-HAMi/dra-lib/api/checkpoint/v1"
v2 "github.com/Project-HAMi/dra-lib/api/checkpoint/v2"
)

// Install registers all checkpoint versions under group.
func Install(scheme *runtime.Scheme, group string) {
utilruntime.Must(v1.AddToScheme(scheme, group))
utilruntime.Must(v2.AddToScheme(scheme, group))
}

// NewScheme returns a scheme that decodes any supported checkpoint version
Expand Down
6 changes: 3 additions & 3 deletions api/checkpoint/install/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer"
)

// TestRoundTrip fuzz-tests the v1 types through the scheme. v1 is the only
// version, so the external-types variant is needed: the API group variant
// only covers internal types.
// TestRoundTrip fuzz-tests the v1 and v2 types through the scheme. There is
// no internal version, so the external-types variant is needed: the API group
// variant only covers internal types.
func TestRoundTrip(t *testing.T) {
scheme := NewScheme("checkpoint.internal.example.com")
codecs := serializer.NewCodecFactory(scheme)
Expand Down
17 changes: 5 additions & 12 deletions api/checkpoint/v1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ limitations under the License.

// +k8s:deepcopy-gen=package

// Package v1 is the checkpoint API: kind Checkpoint, version v1, in an API
// group the caller chooses. Changes follow the Kubernetes [API changes]
// guidelines.
//
// v1 is the only version on purpose, so the store reads and writes v1 directly
// with no internal version or conversion. When a v2 is needed, add the v2
// types with generated conversion to and from v1, register both in
// install.NewScheme, and have the store decode either version into the newest
// one, so existing v1 files keep reading. If more than two versions have to
// coexist, reintroduce an internal hub version then (the Kubernetes
// internal+versioned pattern). A driver-visible type change is a minor
// version bump while dra-lib is v0. There is no type-alias package.
// Package v1 is version v1 of the checkpoint API, kind Checkpoint, in an API
// group the caller chooses, as dra-lib v0.1.0 wrote it. It is decode-only:
// the store reads v1 files and converts them with v2.ConvertFromV1; nothing
// writes v1 again. The types are frozen and stay so v1 files keep reading.
// Changes followed the Kubernetes [API changes] guidelines.
//
// [API changes]: https://github.com/kubernetes/community/blob/047598ce8b0932b9be921471dd301b6a82db210f/contributors/devel/sig-architecture/api_changes.md
package v1
47 changes: 47 additions & 0 deletions api/checkpoint/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ type PreparedClaim struct {
Devices []PreparedDevice `json:"devices,omitempty"`
// +optional
NVIDIA *NVIDIAClaim `json:"nvidia,omitempty"`
// AbortedAt is when the claim entered PrepareStateAborted.
// +optional
AbortedAt *metav1.Time `json:"abortedAt,omitempty"`
}

type PrepareState string

const (
PrepareStateStarted PrepareState = "PrepareStarted"
PrepareStateCompleted PrepareState = "PrepareCompleted"
// PrepareStateAborted marks a claim whose prepare was undone; the entry
// stays until AbortedAt plus a driver-defined TTL so that stale retries of
// the prepare can be recognised.
PrepareStateAborted PrepareState = "PrepareAborted"
)

type PreparedDevice struct {
Expand All @@ -92,6 +99,20 @@ type Device struct {
// +optional
// +listType=atomic
CDIDeviceIDs []string `json:"cdiDeviceIDs,omitempty"`
// ShareID identifies the share of a device that several claims share.
// +optional
ShareID *types.UID `json:"shareID,omitempty"`
// Metadata is the device metadata the driver returned to the kubelet.
// +optional
Metadata *DeviceMetadata `json:"metadata,omitempty"`
}

// DeviceMetadata mirrors the kubelet DRA API's device metadata.
type DeviceMetadata struct {
// +optional
Attributes map[string]resourcev1.DeviceAttribute `json:"attributes,omitempty"`
// +optional
NetworkData *resourcev1.NetworkDeviceData `json:"networkData,omitempty"`
}

// +k8s:deepcopy-gen=false
Expand Down Expand Up @@ -202,6 +223,20 @@ type NVIDIAClaim struct {
type NVIDIADeviceGroup struct {
// +optional
MPSControlDaemonID string `json:"mpsControlDaemonID,omitempty"`
// MPSApplied records whether MPS was applied to the group. Unset in
// checkpoints that predate it.
// +optional
MPSApplied *bool `json:"mpsApplied,omitempty"`
// TimeSliceApplied records whether time-slicing was applied to the group.
// Unset in checkpoints that predate it, which implied time-slicing.
// +optional
TimeSliceApplied *bool `json:"timeSliceApplied,omitempty"`
// Type is the device type of the group's ComputeDomain config.
// +optional
Type NVIDIADeviceType `json:"type,omitempty"`
// ComputeDomain is the ID of the ComputeDomain the group belongs to.
// +optional
ComputeDomain string `json:"computeDomain,omitempty"`
}

type NVIDIADeviceType string
Expand All @@ -210,6 +245,9 @@ const (
NVIDIADeviceTypeGPU NVIDIADeviceType = "gpu"
NVIDIADeviceTypeMIG NVIDIADeviceType = "mig"
NVIDIADeviceTypeVFIO NVIDIADeviceType = "vfio"
// ComputeDomain devices: an IMEX channel or the daemon of a domain.
NVIDIADeviceTypeChannel NVIDIADeviceType = "channel"
NVIDIADeviceTypeDaemon NVIDIADeviceType = "daemon"
)

type NVIDIADevice struct {
Expand All @@ -219,6 +257,12 @@ type NVIDIADevice struct {
// UUID is the GPU UUID of gpu and vfio devices.
// +optional
UUID string `json:"uuid,omitempty"`
// PCIBusID is the PCI bus ID of vfio devices.
// +optional
PCIBusID string `json:"pciBusID,omitempty"`
// ID is the IMEX channel or daemon ID of channel and daemon devices.
// +optional
ID *int32 `json:"id,omitempty"`
}

// NVIDIAPartition holds the MIG device identity of a hard partition.
Expand All @@ -227,4 +271,7 @@ type NVIDIAPartition struct {
GIID int32 `json:"giID"`
CIID int32 `json:"ciID"`
MIGUUID string `json:"migUUID"`
// ParentPCIBusID is the PCI bus ID of the parent GPU.
// +optional
ParentPCIBusID string `json:"parentPCIBusID,omitempty"`
}
63 changes: 61 additions & 2 deletions api/checkpoint/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading