API versioning¶
Kukeon separates the on-wire API schema from its internal types. This is the pattern that lets the API evolve without every change rippling through every controller.
The layers¶
flowchart TB
yaml["YAML manifest<br/>apiVersion: v1beta1"]
external["pkg/api/model/v1beta1<br/>(versioned external types)"]
apischeme["internal/apischeme<br/>(version translation)"]
modelhub["internal/modelhub<br/>(version-agnostic internal types)"]
controller["internal/controller<br/>(reconciler)"]
yaml --> external
external --> apischeme
apischeme --> modelhub
modelhub --> controller
pkg/api/model/v1beta1 — the external types¶
Everything a manifest can say lives here:
pkg/api/version/
└── version.go (V1Beta1, Check: the one apiVersion declaration and check)
pkg/api/model/v1beta1/
├── api.go (Version, Kind)
├── consts.go (APIVersionV1Beta1, KindRealm, KindHealthDigest, ...)
├── realm.go (RealmDoc, RealmSpec, ...)
├── space.go (SpaceDoc, SpaceSpec, ...)
├── stack.go (StackDoc, ...)
├── cell.go (CellDoc, CellSpec, ContainerSpec, ...)
├── container.go (ContainerDoc, ContainerSpec, ...)
├── secret.go (SecretDoc, ...)
├── cellblueprint.go (CellBlueprintDoc, ...)
├── cellconfig.go (CellConfigDoc, ...)
├── volume.go (VolumeDoc, ...)
├── healthreport.go (HealthReport document types)
├── team.go (TeamDoc, TeamDefaultsDoc, SourceDoc)
├── serverconfiguration.go (ServerConfigurationDoc)
├── clientconfiguration.go (ClientConfigurationDoc)
├── connector.go (connector catalog types)
└── network.go (Network types)
pkg/api/version is a leaf package that imports nothing from this module, so
every reader — the apply parser, the health-report store, the team packages,
the configuration loaders — compares apiVersion through version.Check
instead of declaring the string again.
Fields, tag names, and JSON/YAML layout here are the public contract. Renames or removals are breaking changes. New versions get their own sibling package (pkg/api/model/v1/..., pkg/api/model/v1beta2/..., etc.) rather than mutating the current one.
internal/modelhub — the internal types¶
modelhub mirrors the same resources without a version tag:
These are what the controller and utility code operate on. They don't carry apiVersion. They can evolve freely with the controller — no external contract to preserve.
internal/apischeme — the translation layer¶
apischeme is the only internal/ package allowed to import pkg/api/model/*. It exposes three functions per resource:
Convert<Resource>DocToInternal(ext) → (internal, error)— external → internal.Build<Resource>ExternalFromInternal(internal, version) → (external, error)— internal → external for a given API version.Normalize<Resource>(ext) → (internal, version, error)— external → internal. An emptyapiVersionis treated asv1beta1here, but only for documents built in code (for example a probeContainerDoc). User-written YAML never reachesNormalize*without one:kuke applyand the health-report store reject a document whoseapiVersionis missing before conversion.
Every request crosses apischeme on the way in, and every response crosses it on the way out. Controllers never see v1beta1.RealmDoc.
Why this indirection?¶
- Multiple API versions coexist cheaply. When
v1ships,apischemegains a new switch arm; the controller is unchanged. - Field renames don't ripple.
SpaceSpec.RealmID(external) andSpaceSpec.RealmName(internal) can drift;apischemereconciles them. - Storage can be version-aware independently. The runner stores the external
v1beta1document (for exampleapischeme.BuildRealmExternalFromInternal(..., VersionV1Beta1)ininternal/controller/runner/metadata.go), so stored metadata is diff-able and carries its ownapiVersion; changing what is persisted is anapischemechange, not a controller change.
Unsupported versions¶
Every user-written document must carry apiVersion. kuke apply -f (and kuke run -f) rejects a document without one with apiVersion is required (expected v1beta1), and one with a version Kukeon doesn't know about with unsupported apiVersion "<value>" (expected v1beta1); both match errdefs.ErrUnsupportedAPIVersion. A missing value is not read as "latest": once a second version exists, that reading would silently change meaning. There is no silent upgrade or "closest match" behavior — a request is either in a supported version or it is rejected.
The two configuration files (kukeond --configuration, kuke --configuration) are the exception: a file without apiVersion still loads, so an existing /etc/kukeon/kukeond.yaml keeps working, but a set value must be v1beta1.
Today: one supported version¶
v1beta1 is the only version currently in the tree. v1 is planned once the resource model stabilizes. Both will live side by side when that happens; nothing about v1beta1 will be removed without a deprecation window.
Read next¶
- Manifest Reference — the
v1beta1schema in detail - Overview — where apischeme sits in the request path