synth

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package synth builds OPM artifact CUE values from in-memory typed inputs by unifying caller-supplied identity (name, namespace, module reference, values, subscriptions, labels, annotations) against the schema definition resolved through the caller-supplied *schema.Cache.

It covers two of the three OPM artifacts:

  • synth.Release builds a #ModuleRelease from a *module.Module plus typed identity and values.
  • synth.Platform builds a #Platform from typed identity and subscription inputs.

Synth is a peer of opm/helper/loader, not a subpackage of it. The loader tree (opm/helper/loader/file, opm/helper/loader/bytes) reads existing artifact bytes from a source — filesystem or byte buffer. Synthesis is creation from typed inputs: there is no file to parse, no bytes to decode. Co-locating synth under loader would conflate verbs and force every reader to ignore the package doc when interpreting the package path. Keeping them as peers makes each verb legible at a glance.

Recommended entry points: (*kernel.Kernel).SynthesizeRelease and (*kernel.Kernel).SynthesizePlatform. SynthesizeRelease chains synth.Release into Kernel.ProcessModuleRelease so a caller building a release from typed inputs gets a fully validated, concrete *module.Release in one call. SynthesizePlatform chains synth.Platform into platform.NewPlatformFromValue and returns a typed pre-materialize *platform.Platform; it does NOT call Materialize (registry I/O stays an explicit, separate, caller-driven step). Call synth.Release / synth.Platform directly only when there is no *Kernel on hand (rare; mostly unit-testing in tight loops).

Schema source of truth: the synth helpers never reimplement derivations the CUE schema already owns (release UUID stamping, components fan-out from #components, auto-secrets injection, standard label stamping, the #Subscription enable default). Every derived field flows through unification with the artifact definition obtained from in.SchemaCache.Get(ctx); the schema package itself is resolved by the Cache's underlying Loader (typically schema.OCILoader against CUE_REGISTRY).

Boundary scope: synth helpers live under opm/helper/ because they are opinionated frontend conveniences. Frontends MAY bypass them and unify against the schema themselves; nothing in synth is part of the kernel contract.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingType is returned when PlatformInput.Type is empty. It has no
	// Release counterpart (only #Platform carries a required type).
	ErrMissingType = errors.New("synth.Platform: Type is required")

	// ErrPlatformMissingName is returned when PlatformInput.Name is empty.
	ErrPlatformMissingName = errors.New("synth.Platform: Name is required")

	// ErrPlatformMissingSchemaCache is returned when PlatformInput.SchemaCache
	// is nil. Callers typically pass kernel.SchemaCache() from their Kernel.
	ErrPlatformMissingSchemaCache = errors.New("synth.Platform: SchemaCache is required")

	// ErrPlatformSchemaUnavailable is returned when the caller-supplied
	// SchemaCache resolves but does not expose #Platform.
	ErrPlatformSchemaUnavailable = errors.New("synth.Platform: schema unavailable")
)

Platform sentinel errors. These mirror the Release set but carry synth.Platform: wording so error messages name the failing artifact. They are distinct package-level vars from the Release sentinels (D4) — the release sentinels stay untouched to avoid churn on synth.Release callers.

View Source
var (
	// ErrMissingModule is returned when ReleaseInput.Module is nil.
	ErrMissingModule = errors.New("synth.Release: Module is required")

	// ErrMissingName is returned when ReleaseInput.Name is empty.
	ErrMissingName = errors.New("synth.Release: Name is required")

	// ErrMissingNamespace is returned when ReleaseInput.Namespace is empty.
	ErrMissingNamespace = errors.New("synth.Release: Namespace is required")

	// ErrMissingSchemaCache is returned when ReleaseInput.SchemaCache is
	// nil. Callers typically pass kernel.SchemaCache() from their Kernel.
	ErrMissingSchemaCache = errors.New("synth.Release: SchemaCache is required")

	// ErrSchemaUnavailable is returned when the caller-supplied
	// SchemaCache resolves but does not expose #ModuleRelease.
	ErrSchemaUnavailable = errors.New("synth.Release: schema unavailable")
)

Sentinel errors. Frontends inspecting the failure surface match on these via errors.Is. Synthesis-time errors all wrap one of these so callers can distinguish "you forgot a required field" from "the schema is broken."

Functions

func Platform added in v0.3.0

func Platform(ctx *cue.Context, in PlatformInput) (cue.Value, error)

Platform builds a #Platform CUE value by unifying PlatformInput against the #Platform definition obtained from the caller-supplied SchemaCache. It is a peer of Release.

Unlike Release, Platform needs no userModule scope dance: #Platform has no nested closed-artifact input — all inputs are plain scalars, maps, and lists — so Platform renders a CUE source string and CompileStrings it with the resolved schema package as cue.Scope (to resolve #Platform / #Subscription references). See design D2.

The returned cue.Value carries the caller-supplied identity and subscription fields and leaves the kernel-filled materialization slots (#composedTransformers, #matchers) unset — those are populated later by Materialize, not by synthesis.

func Release

func Release(ctx *cue.Context, in ReleaseInput) (cue.Value, error)

Release builds a #ModuleRelease CUE value by unifying ReleaseInput against the #ModuleRelease definition obtained from the caller-supplied SchemaCache.

The function does NOT validate values against #config and does NOT enforce concreteness. Both responsibilities live downstream in Kernel.ProcessModuleRelease, which the Kernel.SynthesizeRelease wrapper chains onto this call. See package doc for the recommended entry point.

The returned cue.Value carries every schema-derived field automatically: metadata.uuid is computed by uuid.SHA1, components is fanned from the unified module, opm-secrets is added when #Secret instances are present, and the standard module-release.opmodel.dev/{name,uuid} labels are stamped. Release stamps only the caller-supplied fields and lets CUE derive the rest.

Types

type FilterSpec added in v0.3.0

type FilterSpec struct {
	// Range is the SemVer constraint expression (filter.range). Omitted when "".
	Range string

	// Allow force-includes specific versions (filter.allow). Omitted when empty.
	Allow []string

	// Deny force-excludes specific versions (filter.deny). Omitted when empty.
	Deny []string
}

FilterSpec is the typed form of #SubscriptionFilter. Each field is rendered only when non-empty, mirroring writeStringMap in release.go.

type PlatformInput added in v0.3.0

type PlatformInput struct {
	// Name is the platform name (metadata.name). Required. Must satisfy the
	// schema's #NameType regex; violations surface as a CUE unification error
	// from Platform.
	Name string

	// Type is the platform type discriminator (the top-level #Platform.type
	// field). Required by the schema. Today it is an informational
	// discriminator the matcher does not consult.
	Type string

	// SchemaCache supplies the OPM core schema used to unify against
	// #Platform. REQUIRED. Typically the value of kernel.SchemaCache() from
	// the caller's Kernel — passing the kernel's cache preserves the
	// one-Cache-per-process invariant and avoids a duplicate schema fetch.
	// Platform returns an error when this field is nil.
	SchemaCache *schema.Cache

	// Description, Labels, and Annotations layer onto metadata. Each is
	// rendered only when non-empty.
	Description string
	Labels      map[string]string
	Annotations map[string]string

	// Subscriptions is the optional typed registry of catalog subscriptions.
	// The map key is the catalog's CUE module path (e.g.
	// "opmodel.dev/catalogs/opm"); a key that violates #ModulePathType
	// surfaces as a CUE unification error from Platform. An empty/nil map
	// leaves #registry empty.
	Subscriptions map[string]SubscriptionSpec
}

PlatformInput is the typed input carried into Platform. Required fields: Name, Type, SchemaCache. Optional fields are rendered into the platform only when present (non-nil / non-empty); empty values do not displace schema-derived fields. It is the #Platform peer of ReleaseInput.

type ReleaseInput

type ReleaseInput struct {
	// Module is the source #Module the release deploys. Required.
	Module *module.Module

	// Name is the release name (metadata.name). Required. Must satisfy the
	// schema's #NameType regex; violations surface as a CUE unification error
	// from Release.
	Name string

	// Namespace is the target namespace (metadata.namespace). Required.
	Namespace string

	// SchemaCache supplies the OPM core schema used to unify against
	// #ModuleRelease. REQUIRED. Typically the value of
	// kernel.SchemaCache() from the caller's Kernel — passing the
	// kernel's cache preserves the one-Cache-per-process invariant and
	// avoids a duplicate schema fetch. Release returns an error when
	// this field is nil.
	SchemaCache *schema.Cache

	// Values is the caller-supplied configuration value unified against the
	// module's #config. The zero cue.Value signals "no values supplied" — the
	// schema's values path is left unfilled and concreteness is enforced
	// downstream by Kernel.ProcessModuleRelease. Release NEVER falls back to
	// Module.debugValues; that is a frontend policy concern.
	Values cue.Value

	// Labels and Annotations layer over the schema's stamped
	// module-release.opmodel.dev/{name,uuid} labels. CUE unification merges
	// caller-supplied entries with schema-stamped ones; caller-supplied keys
	// MUST NOT collide with the schema's reserved keys.
	Labels      map[string]string
	Annotations map[string]string
}

ReleaseInput is the typed input carried into Release. Required fields: Module, Name, Namespace, SchemaCache. Optional fields are filled into the release only when present (non-nil / non-empty / non-zero); empty values do not displace schema-derived fields.

type SubscriptionSpec added in v0.3.0

type SubscriptionSpec struct {
	// Enable maps onto #Subscription.enable. It is a pointer so an omitted
	// value (nil) DEFERS to the schema's `*true` default rather than forcing
	// `false`: nil → schema default, non-nil → the explicit bool. This mirrors
	// the unset-vs-supplied distinction synth.Release draws for its inputs.
	Enable *bool

	// Filter maps onto #Subscription.filter. nil → no filter rendered.
	Filter *FilterSpec
}

SubscriptionSpec is the typed form of a single #registry subscription.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL