Documentation
¶
Overview ¶
Package schema is the kernel's single source of truth for OPM schema-side knowledge: CUE paths, metadata types, and the OCI-backed schema loader.
Schema is unversioned at the package level. The library consumes exactly one OPM CUE schema package, opmodel.dev/core at the release DefaultSchemaModule pins, resolved through CUE's module system against CUE_REGISTRY. There is no in-tree schema mirror.
Path inventory ¶
CUE paths are exported as package-level cue.Path variables (Metadata, Components, Values, Config, Module, DebugValues). Callers use schema.X verbatim — there is no Paths() accessor, no struct, no lookup. The inventory is exactly what Go code reads: matching and execution happen inside the render build, in CUE, and read nothing by path from Go.
Metadata types ¶
ModuleMetadata, InstanceMetadata and PlatformMetadata — one per artifact the kernel accepts — are the canonical decoded metadata records. They are decoded from the artifact's metadata field by the artifact constructors (module.NewModuleFromValue, platform.NewPlatformFromValue) and by the kernel's instance processing; missing metadata is fatal there. Consumers read them through Module.Metadata, Instance.Metadata and Platform.Metadata.
Schema loader and cache ¶
Loader is the strategy interface for resolving the schema; OCILoader is the sole public implementation, fetching DefaultSchemaModule through CUE's module system. Cache memoizes a single Loader.Load per instance (sync.Once-guarded) and exposes ResolvedVersion for diagnostics.
Long-running consumers attach the Cache to a Kernel (via kernel.WithSchemaLoader) and reuse the kernel-owned cache via kernel.SchemaCache(). The library auto-applies no CUE_REGISTRY default; callers opt in by setting CUE_REGISTRY to schema.PublicRegistry (or to a private mirror) before the first Cache.Get.
Index ¶
Constants ¶
const DefaultSchemaModule = "opmodel.dev/core@v2.0.0-alpha.7"
DefaultSchemaModule is the module identifier used by OCILoader.Load when OCILoader.Module is empty.
It names an exact core release, never the floating "opmodel.dev/core@v2" major: the release the kernel's render glue, fixtures and parity oracle were verified against. 2.0.0-alpha.7 is the first release carrying the D5 registry shape (a #Platform.#registry entry embeds its catalog by import and derives `version` from it) and the D12 transformer-context projection (enhancement 0019). The constant advances only by a deliberate change that re-verifies the glue and the fixtures against the new release; a default that floats ahead of the glue breaks every synthesized artifact on a cold cache.
const PublicRegistry = "opmodel.dev=ghcr.io/open-platform-model,registry.cue.works"
PublicRegistry is the documented CUE_REGISTRY mapping for resolving the OPM core schema from its canonical GHCR location with a fallback to registry.cue.works. The library does NOT auto-apply this value as a default; callers opt in by setting CUE_REGISTRY=schema.PublicRegistry (or by passing it via OCILoader.Registry).
Operators in restricted environments may set CUE_REGISTRY to a mirror or to an inline configuration without touching this constant.
Variables ¶
var ( // Artifact root. Metadata = cue.ParsePath("metadata") // Module instance. Components = cue.ParsePath("components") Values = cue.ParsePath("values") Config = cue.MakePath(cue.Def("config")) Module = cue.MakePath(cue.Def("module")) // instance's reference to its source #Module // Module-internal field. DebugValues is a Module field — NOT a separate // kernel artifact. Frontends that want a debug overlay read it from // Module.Package and decide whether to layer it into the values stack; // the kernel never receives debugValues as a parameter. DebugValues = cue.ParsePath("debugValues") )
CUE paths the kernel's Go code reads or writes on an OPM artifact: metadata decoding, instance processing, the loaders' identity reads and the instance's components and #config accessors. This is the whole inventory. Matching and execution read nothing by path from Go: the render build imports the instance and the platform as packages and the generated glue reads `components` and `#composedTransformers` in CUE (enhancement 0019 D9/D10). A path with no reader is removed, not kept for a possible consumer.
Definition fields (those starting with "#" in CUE) use cue.MakePath with cue.Def selectors; concrete fields use cue.ParsePath. The two forms are not interchangeable — definition paths constructed with ParsePath do not resolve on closed structs.
Functions ¶
func DefaultSchemaVersion ¶
func DefaultSchemaVersion() string
DefaultSchemaVersion returns the exact core release DefaultSchemaModule pins, in the canonical "v"-prefixed form a cue.mod dependency carries ("v2.0.0-alpha.7"). It is the version a generated platform module pins core at by default (opm/helper/platformmodule): the release the render glue was verified against is the release a generated platform must embed.
Types ¶
type Cache ¶
type Cache struct {
// Loader is the strategy used to resolve and build the schema value.
// Required.
Loader Loader
// contains filtered or unexported fields
}
Cache memoizes a single Loader.Load invocation per instance and exposes the resolved schema module version for diagnostics. It owns no goroutines and no I/O of its own; the Loader carries those concerns.
The first Cache.Get invocation runs Loader.Load through sync.Once; every subsequent Get (including the one that loses the race) returns the same cached value or the same cached error. Errors are cached too — the load is never retried. To force a re-fetch, construct a fresh Cache with a fresh Loader.
Each Cache instance owns its own memoization. The library MUST NOT expose a package-level Cache singleton; long-running consumers attach the Cache to a Kernel (or equivalent lifetime anchor) and keep that anchor alive across operations.
func (*Cache) Get ¶
Get returns the schema cue.Value, invoking the underlying Loader at most once per Cache instance. Concurrent first-call invocations are serialized via sync.Once; the call that wins runs Loader.Load and the rest observe the cached result.
Returns the zero cue.Value and a non-nil error if Loader.Load fails; the error is cached and subsequent calls return it without re-invoking the Loader.
func (*Cache) ResolvedVersion ¶
ResolvedVersion returns the schema module version that the underlying Loader resolved during the first successful Cache.Get (e.g. "v2.0.0-alpha.4" when the default identifier resolved to that instance).
Returns the empty string before the first successful Get, after a failed Get, or when the Loader does not surface a resolved version. The value is diagnostic-only: callers SHOULD log it but MUST NOT branch behavior on it.
type InstanceMetadata ¶
type InstanceMetadata struct {
// Name is the instance name (from --name or module.metadata.name).
Name string `json:"name"`
// Namespace is the target namespace.
Namespace string `json:"namespace"`
// FQN is the instance's OWN fully qualified name
// (registryPath:name:namespace), defined by core v2 on
// #ModuleInstance.metadata and decoded with the rest of the metadata.
// Distinct from the source module's FQN, which lives on the instance's
// Package at the module-metadata path.
FQN string `json:"fqn,omitempty"`
// UUID is the instance identity UUID.
// Computed by CUE as SHA1(OPMNamespace, moduleUUID:name:namespace).
UUID string `json:"uuid"`
// Labels are the merged instance labels (module labels + standard opm labels).
Labels map[string]string `json:"labels,omitempty"`
// Annotations are the merged instance annotations.
Annotations map[string]string `json:"annotations,omitempty"`
}
InstanceMetadata contains instance-level identity information. Used for inventory tracking, resource labeling, and CLI output.
Was: ReleaseMetadata
type Loader ¶
Loader resolves the OPM core CUE schema and returns it as a built cue.Value. Implementations MUST return a value whose definitions (#Module, #ModuleInstance, #Platform, #Resource, #Trait, #ComponentTransformer, …) are reachable via LookupPath.
The library exposes exactly one Loader implementation: OCILoader. Any other Loader satisfying the interface is internal-only and MUST NOT appear in the public API surface.
type ModuleMetadata ¶
type ModuleMetadata struct {
// Name is the canonical module name from module.metadata.name (kebab-case).
Name string `json:"name"`
// Description is a brief description of the module.
Description string `json:"description,omitempty"`
// ModulePath is the CUE registry module path from metadata.modulePath.
// This is the registry path (e.g., "opmodel.dev/modules"), NOT a filesystem path.
ModulePath string `json:"modulePath"`
// Version is the module version (semver).
Version string `json:"version"`
// FQN is the fully qualified module name (modulePath/name:version).
// Example: "opmodel.dev/modules/my-app:1.0.0"
FQN string `json:"fqn"`
// UUID is the module identity UUID (from #Module.metadata.identity).
UUID string `json:"uuid"`
// Labels from the module definition (pre-build, author-declared).
Labels map[string]string `json:"labels,omitempty"`
// Annotations from the module definition.
Annotations map[string]string `json:"annotations,omitempty"`
}
ModuleMetadata contains module-level identity and version information. This is the module's canonical metadata, distinct from the instance it is deployed as. Populated by module.NewModuleFromValue.
type OCILoader ¶
type OCILoader struct {
// Module is the schema module identifier. Empty means
// [DefaultSchemaModule], the pinned core release.
//
// A bare major form ("…@v0") is automatically expanded to "…@v0.latest"
// before calling [load.Instances]; CUE's standalone-package loader
// requires either a fully qualified version, "@latest", or
// "<major>.latest" outside a module context.
Module string
// Registry overrides CUE_REGISTRY for this load. Empty inherits from
// the process environment.
Registry string
// CacheDir overrides CUE_CACHE_DIR for this load. Empty inherits from
// the process environment (or CUE's default ~/.cache/cuelang/).
CacheDir string
}
OCILoader resolves the OPM core schema through CUE's module system. It is the canonical and only public Loader implementation.
The zero value is a valid Loader: empty fields resolve via process environment (CUE_REGISTRY, CUE_CACHE_DIR) and the DefaultSchemaModule identifier. Explicit field values override environment values.
OCILoader.Load does not mutate process state (no os.Setenv); env overrides are plumbed into load.Config.Env for the single load call.
type PlatformMetadata ¶
type PlatformMetadata struct {
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}
PlatformMetadata is the canonical decoded platform-level metadata. Type is the top-level #Platform.type field hoisted into the metadata projection so callers see one Go-level identity record per Platform artifact.