Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Bug Report
about: Report a problem encountered while using hami-dra-lib
about: Report a problem encountered while using dra-lib
labels: bug
---

Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Enhancement Request
about: Suggest an improvement to hami-dra-lib
about: Suggest an improvement to dra-lib
labels: enhancement
---

Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Question
about: Ask a question about hami-dra-lib
about: Ask a question about dra-lib
labels: question
---

Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:
test:
name: Build, vet and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version: '1.26'
check-latest: true
- run: make fmt-check build vet test

generate:
name: Generated code is up to date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version: '1.26'
check-latest: true
- run: make tools verify-generate

govulncheck:
name: govulncheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version: '1.26'
check-latest: true
- run: go run golang.org/x/vuln/cmd/govulncheck@v1.10.0 ./...

fuzz:
name: Fuzz (${{ matrix.target }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [FuzzDecodeV1, FuzzLegacy, FuzzRoundTrip]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version: '1.26'
check-latest: true
- name: Run ${{ matrix.target }} for 60s
run: go test ./checkpoint/ -run '^$' -fuzz '^${{ matrix.target }}$' -fuzztime 60s
44 changes: 44 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CodeQL

on:
push:
branches: [master]
pull_request:
branches: [master]
schedule:
- cron: '30 3 * * 1'

permissions:
contents: read

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
include:
- language: go
build-mode: autobuild
- language: actions
build-mode: none
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Initialize CodeQL
uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4
with:
category: "/language:${{ matrix.language }}"
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release

on:
push:
tags: ['v*.*.*']

permissions:
contents: read

jobs:
release:
name: GitHub release
runs-on: ubuntu-latest
permissions:
contents: write # to create the release
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Create release with the CHANGELOG section as notes
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
awk -v tag="## [${TAG#v}]" 'index($0, tag) == 1 {found=1; next} found && /^## /{exit} found' CHANGELOG.md > notes.md
test -s notes.md || { echo "CHANGELOG.md has no section for ${TAG}" >&2; exit 1; }
gh release create "$TAG" --verify-tag --title "$TAG" --notes-file notes.md
34 changes: 34 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: OpenSSF Scorecard

on:
branch_protection_rule:
schedule:
- cron: '30 2 * * 1'
push:
branches: [master]

permissions: read-all

jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write # to upload SARIF results
id-token: write # to publish results to the OpenSSF REST API
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Run analysis
uses: ossf/scorecard-action@23f22cd43608bae7a1f1fa2603d7314dee9538a5 # v2.6.0
with:
results_file: results.sarif
results_format: sarif
publish_results: true
- name: Upload SARIF results
uses: github/codeql-action/upload-sarif@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4
with:
sarif_file: results.sarif
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ coverage.*
# editors
.idea/
.vscode/
go.work
go.work.sum
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Changelog

All notable changes to this module are documented here. Versions follow
[semantic versioning](https://semver.org); while the module is v0, breaking Go
API changes bump the minor version. A change to the on-disk checkpoint format
needs a new checkpoint API version (with conversion), not just a new release.

## [Unreleased]

## [0.1.0] - 2026-12-01

### Added

- `api/checkpoint/v1`: DRA kubelet plugin checkpoint API (kind `Checkpoint`,
version `v1`, API group chosen by the caller), the only version: the store
reads and writes it directly, without an internal version, with a common
core (claims, prepared devices, CDI container edits, soft/hard partitions,
node partition modes) and optional AMD and NVIDIA sections.
- `checkpoint`: `Store` with atomic writes, a `driverName` ownership check, and
migration from the legacy kubelet checkpointmanager format (deprecated, will
be removed in a future version).
- `Store.Update`: apply all claim changes of one kubelet call and write once
(one encode, one fsync) instead of once per claim.
- Compact JSON on disk, and an fsync of the parent directory after the rename so
the rename survives a power loss.
- Benchmarks for the legacy and v1 formats. Against the kubelet
checkpointmanager, a Prepare call adding 10 claims is 40x to 55x faster from
100 claims on the node upward; see
[#1](https://github.com/Project-HAMi/dra-lib/issues/1).
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CONTROLLER_GEN_VERSION ?= v0.17.0
GOBIN ?= $(shell go env GOPATH)/bin

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

.PHONY: build vet test fmt-check tools generate generate-deepcopy verify-generate

build:
go build ./...

vet:
go vet ./...

test:
go test ./...

fmt-check:
@test -z "$$(gofmt -s -l .)" || { gofmt -s -l .; exit 1; }

tools:
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)

generate: generate-deepcopy

generate-deepcopy:
for api in $(CHECKPOINT_APIS); do \
rm -f $${api}/zz_generated.deepcopy.go; \
$(GOBIN)/controller-gen object:headerFile=$(HEADER) paths=$${api}/ output:object:dir=$${api}; \
done

verify-generate: generate
git diff --exit-code -- api
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
# hami-dra-lib
# dra-lib

Shared Go library for the [HAMi](https://project-hami.io) DRA drivers
(amd-dra-driver, ascend-dra-driver, k8s-dra-driver).
Shared Go library for Kubernetes DRA (Dynamic Resource Allocation) drivers.

- `checkpoint`: versioned kubelet plugin checkpoint API
(`checkpoint.internal.project-hami.io/v1`), atomic read/write, and migration
from the legacy kubelet checkpointmanager format (removed in HAMi 2.13).
- Common partition model (soft and hard partitions, vendor details per vendor).
- `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.
- `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).

Depends only on k8s.io/apimachinery and the CDI spec, so drivers don't pull in
k8s.io/kubernetes.
```go
store, err := checkpoint.NewStore(path, checkpoint.Options{
Group: "checkpoint.internal.example.com",
DriverName: "gpu.example.com",
})
cp, err := store.Read()
err = store.Write(cp)
```

Depends on k8s.io/apimachinery, k8s.io/api and the CDI spec only, so drivers
don't need k8s.io/kubernetes.

Releases are semver tags; see [CHANGELOG.md](CHANGELOG.md). `make generate`
regenerates the deepcopy code (`make tools` installs the generator).

## Contributing

Expand Down
26 changes: 13 additions & 13 deletions SECURITY-INSIGHTS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ header:
schema-version: 2.0.0
last-updated: '2026-12-01'
last-reviewed: '2026-12-01'
url: https://github.com/Project-HAMi/hami-dra-lib/blob/master/SECURITY-INSIGHTS.yml
url: https://github.com/Project-HAMi/dra-lib/blob/master/SECURITY-INSIGHTS.yml
comment: |
Security metadata for hami-dra-lib, following the OpenSSF
Security metadata for dra-lib, following the OpenSSF
Security Insights specification.

project:
name: hami-dra-lib
name: dra-lib
homepage: https://project-hami.io
documentation:
code-of-conduct: https://github.com/Project-HAMi/hami-dra-lib/blob/master/CODE_OF_CONDUCT.md
code-of-conduct: https://github.com/Project-HAMi/dra-lib/blob/master/CODE_OF_CONDUCT.md
administrators:
- name: Reza Jelveh
affiliation: dynamia.ai
email: reza@dynamia.ai
primary: true
repositories:
- name: hami-dra-lib
url: https://github.com/Project-HAMi/hami-dra-lib
- name: dra-lib
url: https://github.com/Project-HAMi/dra-lib
comment: |
Shared Go library for the HAMi DRA drivers: versioned checkpoint
API and common partition model, subproject of HAMi.
vulnerability-reporting:
reports-accepted: true
bug-bounty-available: false
contact:
name: hami-dra-lib maintainers
name: dra-lib maintainers
primary: true
security-policy: https://github.com/Project-HAMi/hami-dra-lib/blob/master/SECURITY.md
security-policy: https://github.com/Project-HAMi/dra-lib/blob/master/SECURITY.md
comment: |
Report vulnerabilities privately via GitHub Security Advisories:
https://github.com/Project-HAMi/hami-dra-lib/security/advisories/new
https://github.com/Project-HAMi/dra-lib/security/advisories/new
See SECURITY.md for the full policy and response process.

repository:
url: https://github.com/Project-HAMi/hami-dra-lib
url: https://github.com/Project-HAMi/dra-lib
status: active
accepts-change-request: true
accepts-automated-change-request: true
Expand All @@ -48,11 +48,11 @@ repository:
email: reza@dynamia.ai
primary: true
documentation:
contributing-guide: https://github.com/Project-HAMi/hami-dra-lib/blob/master/CONTRIBUTING.md
security-policy: https://github.com/Project-HAMi/hami-dra-lib/blob/master/SECURITY.md
contributing-guide: https://github.com/Project-HAMi/dra-lib/blob/master/CONTRIBUTING.md
security-policy: https://github.com/Project-HAMi/dra-lib/blob/master/SECURITY.md
governance: https://github.com/Project-HAMi/community/blob/master/governance.md
license:
url: https://github.com/Project-HAMi/hami-dra-lib/blob/master/LICENSE
url: https://github.com/Project-HAMi/dra-lib/blob/master/LICENSE
expression: Apache-2.0
security:
assessments:
Expand Down
Loading