Skip to content

Commit b93bb1a

Browse files
authored
Merge pull request #1 from kai-scheduler/siormeir/reseed-from-main
feat: seed standalone API module from KAI-Scheduler main
2 parents 7f6408d + 32a5d07 commit b93bb1a

66 files changed

Lines changed: 1785 additions & 416 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,41 @@ All notable changes to api will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [v0.1.0] - 2026-04-13
8+
## [v0.1.0]
99

10-
Initial release of api as a standalone repository extracted from KAI-Scheduler.
10+
Initial release of the standalone `github.com/kai-scheduler/api` module, seeded from KAI-Scheduler `main`.
1111

1212
### Added
1313

14-
- **API Types** with full git history preserved:
15-
- Queue (v2) - Hierarchical queue resource
16-
- PodGroup (v2alpha2) - Gang scheduling with subgroups
17-
- BindRequest (v1alpha2) - Pod binding coordination
14+
- **API types** (client-backed CRD contracts):
15+
- Queue (`scheduling.run.ai/v2`) — hierarchical queue resource
16+
- PodGroup (`scheduling.run.ai/v2alpha2`) — gang scheduling with subgroups, plus validating webhook
17+
- BindRequest, NumaPlacementRequest (`scheduling.run.ai/v1alpha2`) — pod binding coordination
18+
- Topology (`kai.scheduler/v1alpha1`) — topology-aware scheduling input
1819

19-
- **Generated Clients**:
20-
- Clientset for all API versions
21-
- Informers for watch/cache patterns
22-
- Listers for indexed queries
20+
- **Generated clients** — single clientset, informer factory, and listers spanning both the
21+
`scheduling.run.ai` and `kai.scheduler/v1alpha1` groups.
2322

24-
- **CRD Manifests**:
25-
- `config/crd/scheduling.run.ai_queues.yaml`
26-
- `config/crd/scheduling.run.ai_podgroups.yaml`
27-
- `config/crd/scheduling.run.ai_bindrequests.yaml`
23+
- **CRD manifests** (`config/crd/`):
24+
- `scheduling.run.ai_queues.yaml`
25+
- `scheduling.run.ai_podgroups.yaml`
26+
- `scheduling.run.ai_bindrequests.yaml`
27+
- `kai.scheduler_topologies.yaml`
2828

2929
- **Utilities**:
30-
- `utilities/resources/` - GPU sharing utilities:
31-
- GPU fraction/memory extraction from pod annotations
32-
- DRA (Dynamic Resource Allocation) support
33-
- Resource list operations
34-
- `utilities/podgroup/` - PodGroup business logic:
35-
- `CalculatePreemptibility()` - Priority-based preemptibility
30+
- `utilities/resources/` — GPU fraction/memory extraction, DRA support, resource list operations
31+
- `utilities/podgroup/``CalculatePreemptibility()`
3632

37-
- **Constants**:
38-
- GPU annotation keys (GpuFraction, GpuMemory, etc.)
39-
- Common labels and selectors
33+
- **Constants** — GPU annotation keys, labels, and priority constants.
34+
35+
- **Code generation**`make generate` (deepcopy), `make manifests` (CRDs), `make clients`
36+
(clientset/informers/listers) reproduce all generated artifacts.
4037

4138
### Notes
4239

43-
- Extracted from kai-scheduler v0.14.0 with full commit history (696+ commits)
44-
- Clean separation: Only client-facing API contracts included
45-
- Scheduler-specific utilities (framework handles, webhook wiring) remain in kai-scheduler
46-
- Dependencies: Kubernetes v0.35.3, controller-runtime v0.23.3
40+
- Seeded fresh from `main` (no git history preserved); Apache 2.0 / NVIDIA attribution retained via per-file headers.
41+
- Scheduler-internal code stays in kai-scheduler: `kai.scheduler/v1` config types (Config, SchedulingShard),
42+
scheduler-framework glue (`k8s_utils`), and feature gates.
43+
- Dependencies: Kubernetes v0.35.4, controller-runtime v0.23.3, Go 1.26.3.
4744

4845
[v0.1.0]: https://github.com/kai-scheduler/api/releases/tag/v0.1.0

CLAUDE.md

Lines changed: 47 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
# api Development Guide
22

3-
api is a standalone Go module providing Kubernetes API types, generated clients, and utilities for GPU-aware batch scheduling with KAI Scheduler.
3+
`github.com/kai-scheduler/api` is a standalone Go module providing Kubernetes API types, generated clients, and utilities for GPU-aware batch scheduling with KAI Scheduler.
44

55
## Repository Structure
66

77
```
88
api/
9-
├── api/scheduling/ # API type definitions (Queue, PodGroup, BindRequest)
10-
├── client/ # Generated clientset, informers, listers
11-
├── config/crd/ # CRD YAML manifests
12-
├── constants/ # Public API constants (GPU annotations, labels)
9+
├── scheduling/ # scheduling.run.ai types
10+
│ ├── v1alpha2/ # BindRequest, NumaPlacementRequest
11+
│ ├── v2/ # Queue
12+
│ └── v2alpha2/ # PodGroup (+ validating webhook)
13+
├── kai/
14+
│ └── v1alpha1/ # Topology
15+
├── client/ # Generated clientset, informers, listers (both groups)
16+
├── config/crd/ # Generated CRD YAML manifests
17+
├── constants/ # Public API constants (GPU annotations, labels, priorities)
1318
├── utilities/ # Client-facing utilities
1419
│ ├── resources/ # GPU sharing, DRA extraction, resource helpers
1520
│ └── podgroup/ # PodGroup business logic (preemptibility)
21+
├── hack/ # Codegen boilerplate + update-client.sh
22+
├── Makefile
1623
├── go.mod
1724
├── README.md
1825
├── CHANGELOG.md
@@ -21,138 +28,61 @@ api/
2128

2229
## What Belongs in This Repository
2330

24-
**Include (Client-Facing API Contracts):**
25-
- API type definitions (Queue, PodGroup, BindRequest)
31+
**Include (client-facing API contracts):**
32+
- CRD type definitions with a generated client — the `scheduling.run.ai` group and `kai.scheduler/v1alpha1` Topology
2633
- Generated Kubernetes clients (clientset, informers, listers)
27-
- CRD manifests (YAML definitions)
28-
- Constants that are part of the public API (annotations, labels)
29-
- Utilities for working with API types (GPU request inspection, DRA support)
30-
- Business logic directly referenced in API documentation (preemptibility calculation)
31-
32-
**Exclude (Scheduler Implementation Details):**
33-
- Scheduler plugin implementations
34-
- Framework handles and infrastructure
35-
- Webhook wiring code (operator-specific)
36-
- Feature gates (runtime behavior, not API contracts)
37-
- Scheduler-specific internal utilities
34+
- CRD manifests (YAML)
35+
- Public-API constants (annotations, labels, priorities)
36+
- Utilities for working with API types (GPU request inspection, DRA support, preemptibility)
37+
- The PodGroup validating webhook (ships with its `v2alpha2` type)
3838

39-
## Building and Testing
40-
41-
### Build
42-
```bash
43-
go build ./...
44-
```
39+
**Exclude (stays in kai-scheduler):**
40+
- `kai.scheduler/v1` config types (Config, SchedulingShard) — operator-internal, controller-runtime only
41+
- Scheduler-framework glue (`k8s_utils`) — pulls `k8s.io/kubernetes`; imports feature gates (would cycle)
42+
- Feature gates and flags (runtime behavior, not API contract)
43+
- Scheduler plugins and infrastructure
4544

46-
### Run Tests
47-
```bash
48-
go test ./...
49-
```
45+
## Building and Testing
5046

51-
### Linting
52-
Use the same linter configuration as kai-scheduler:
5347
```bash
54-
golangci-lint run
48+
make build # go build ./...
49+
make test # go test ./...
50+
make lint # gofmt + go vet
5551
```
5652

5753
## Code Generation
5854

59-
Generated clients are created from API types using kubernetes code-generator tools.
60-
61-
**When to regenerate:**
62-
- API types are modified (new fields, new versions)
63-
- After bumping Kubernetes dependencies
64-
65-
**How to regenerate:**
6655
```bash
67-
# TODO: Add code generation scripts when SDK CI/CD is set up
56+
make generate # DeepCopy methods (controller-gen object)
57+
make manifests # CRD manifests into config/crd/ (controller-gen crd)
58+
make clients # clientset, informers, listers (k8s.io/code-generator)
6859
```
6960

70-
## Versioning
71-
72-
This SDK follows [Semantic Versioning](https://semver.org/):
61+
Regenerate when API types change or after bumping Kubernetes dependencies. `make manifests` prepends the
62+
Kubernetes copyright header to `kai.scheduler_topologies.yaml` (derived from Kubernetes projects).
7363

74-
- **MAJOR** (v1.x.x → v2.x.x): Breaking API changes
75-
- Field removals
76-
- Type changes
77-
- Renamed resources
64+
## Versioning & Release
7865

79-
- **MINOR** (v1.0.x → v1.1.x): Backward-compatible additions
80-
- New API fields (with defaults)
81-
- New utility functions
82-
- New CRD versions (with conversion)
66+
Semantic Versioning; `v0.x` until the contract is declared stable.
8367

84-
- **PATCH** (v1.0.0 → v1.0.1): Bug fixes and documentation
85-
- Bug fixes in utilities
86-
- Documentation improvements
87-
- Non-breaking dependency updates
88-
89-
## Release Process
90-
91-
1. Update API types/utilities as needed
92-
2. Update `CHANGELOG.md` with changes
93-
3. Run tests: `go test ./...`
94-
4. Run build: `go build ./...`
95-
5. Commit changes
96-
6. Tag release: `git tag v0.x.y`
97-
7. Push tag: `git push origin v0.x.y`
68+
1. Update API types/utilities
69+
2. Regenerate (`make generate manifests clients`)
70+
3. Update `CHANGELOG.md`
71+
4. `make build && make test`
72+
5. Commit, tag `vX.Y.Z`, push the tag
9873

9974
## Local Development with kai-scheduler
10075

101-
When making changes to both SDK and kai-scheduler simultaneously:
102-
103-
1. **Make SDK changes first** in this repository
104-
2. **Test locally** using replace directive in kai-scheduler:
105-
```go
106-
// kai-scheduler/go.mod
107-
replace github.com/kai-scheduler/api => ../api
108-
```
109-
3. **Run kai-scheduler tests** with local SDK
110-
4. **Release SDK** when ready (tag version)
111-
5. **Update kai-scheduler** to use released SDK version:
112-
```bash
113-
cd kai-scheduler
114-
go get github.com/kai-scheduler/api@v0.x.y
115-
# Remove replace directive
116-
```
117-
118-
## Code Style
119-
120-
Follow the same conventions as kai-scheduler:
121-
122-
**Imports**: Three groups (stdlib, external, internal)
12376
```go
124-
import (
125-
"context"
126-
"fmt"
127-
128-
v1 "k8s.io/api/core/v1"
129-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
130-
131-
"github.com/kai-scheduler/api/constants"
132-
)
77+
// kai-scheduler/go.mod (local only — not committed to release branches)
78+
replace github.com/kai-scheduler/api => ../api
13379
```
13480

135-
**Naming**:
136-
- Files: snake_case (`gpu_sharing.go`, `podgroup.go`)
137-
- Types: PascalCase (`Queue`, `PodGroup`)
138-
- Functions: PascalCase exported, camelCase unexported
139-
- Boolean functions: `Is`/`Has`/`Should` prefix
140-
141-
**Comments**:
142-
- Apache 2.0 + NVIDIA copyright headers on all files
143-
- GoDoc-style for exported functions/types
144-
- Avoid obvious comments; explain "why" not "what"
81+
Make API changes here first, test against kai-scheduler via the `replace` directive, then release and bump
82+
kai-scheduler with `go get github.com/kai-scheduler/api@vX.Y.Z`.
14583

146-
## Contributing
147-
148-
Changes to API types should be made in this repository first, then consumed by kai-scheduler.
149-
150-
For questions or contributions to the main scheduler, see [kai-scheduler repository](https://github.com/kai-scheduler/KAI-Scheduler).
151-
152-
## Known Issues
153-
154-
### Operator API in Generated Clients
155-
156-
Generated clients currently include references to `kai/v1alpha1` (Topology CRD), which is operator-specific and should remain in kai-scheduler. This creates a dependency on the kai-scheduler module.
84+
## Code Style
15785

158-
**Resolution**: Will be addressed when SDK client generation is set up independently. For now, the dependency exists but doesn't affect SDK users who only work with scheduling APIs.
86+
Follow kai-scheduler conventions: three import groups (stdlib, external, internal); snake_case files;
87+
PascalCase exported / camelCase unexported; `Is`/`Has`/`Should` boolean prefixes; Apache 2.0 + NVIDIA
88+
copyright headers on all files; GoDoc on exported symbols; explain "why" not "what".

Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2025 NVIDIA CORPORATION
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONTROLLER_TOOLS_VERSION ?= v0.20.1
5+
6+
LOCALBIN ?= $(shell pwd)/bin
7+
$(LOCALBIN):
8+
mkdir -p $(LOCALBIN)
9+
10+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
11+
12+
# CRDs derived from Kubernetes projects that require the Kubernetes copyright header.
13+
K8S_COPYRIGHTED_MANIFEST_FILES := config/crd/kai.scheduler_topologies.yaml
14+
15+
.PHONY: all
16+
all: generate manifests clients
17+
18+
.PHONY: build
19+
build: ## Build all packages.
20+
go build ./...
21+
22+
.PHONY: test
23+
test: ## Run all tests.
24+
go test ./...
25+
26+
.PHONY: lint
27+
lint: ## Format and vet.
28+
gofmt -l -w .
29+
go vet ./...
30+
31+
.PHONY: generate
32+
generate: controller-gen ## Generate DeepCopy method implementations.
33+
$(CONTROLLER_GEN) object:headerFile="./hack/boilerplate.go.txt" paths="./scheduling/..." paths="./kai/..."
34+
35+
.PHONY: manifests
36+
manifests: controller-gen ## Generate CustomResourceDefinition objects.
37+
$(CONTROLLER_GEN) crd:allowDangerousTypes=true,generateEmbeddedObjectMeta=true,headerFile="./hack/boilerplate.yaml.txt" paths="./scheduling/..." paths="./kai/..." output:crd:artifacts:config=config/crd
38+
39+
# Prepend Kubernetes copyright to CRDs derived from Kubernetes projects.
40+
@for f in $(K8S_COPYRIGHTED_MANIFEST_FILES); do \
41+
cat ./hack/boilerplate.yaml.kb.txt $$f > $$f.tmp && mv $$f.tmp $$f; \
42+
done
43+
44+
.PHONY: clients
45+
clients: ## Generate clientset, listers, and informers.
46+
hack/update-client.sh
47+
48+
.PHONY: controller-gen
49+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
50+
$(CONTROLLER_GEN): $(LOCALBIN)
51+
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

0 commit comments

Comments
 (0)