motif

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

pkg/motif

The motif package loads, validates, and expands Motif YAML files. A Motif is a reusable infrastructure template — a named set of Kubernetes resources (StatefulSets, Services, PVCs, etc.) with declared inputs that callers bind when importing.

A Katalog imports a Motif instead of writing all stateful resource declarations by hand:

operatorBox:
  imports:
    - motif: postgres       # load from registry or local file
      with:
        image: "{{ .data.postgresImage }}"
        volumeSize: "{{ .data.postgresVolumeSize }}"

What lives here

File Role
loader.go Load, LoadImport — read a Motif YAML from disk or registry; strict structural validation via utils.StrictUnmarshal
expander.go Expand — bind inputs and render the Motif's resource templates into a HookTemplates value; MergeHookTemplates — merge expanded resources into an existing block

Validation model

Motif YAML passes through two validation layers before any expansion runs:

  1. Structural (loader.go) — utils.StrictUnmarshal rejects unknown fields. kind: Motif and metadata.name are required.
  2. Semantic (pkg/katalog/motif_validate.go) — duplicate input names, required + default conflict, missing resources block, and unknown {{ inputs.* }} references are all errors.

See pkg/katalog/docs/06-motif-validation.md for the full validation pipeline.

Developer documentation

I want to… Go to
Understand the Motif YAML format and input system docs/01-structure.md
Understand how Motifs are loaded and validated docs/02-loading.md
Understand input binding and resource expansion docs/03-expansion.md

Documentation

Overview

pkg/motif/expander.go

Expander instantiates a Motif by binding its inputs and expanding its resource blocks into a concrete HookTemplates value.

Two modes:

Static (ork doctor init): inputs resolved from explicit with: bindings at generation time. The expanded resources are inlined into the generated Katalog. No runtime dependency on the Motif.

Dynamic (Katalog runtime): inputs resolved at Katalog startup, before any reconcile. The Motif is loaded once and its templates compiled with the input bindings.

pkg/motif/loader.go

Loads a Motif from a file path or registry reference. Resolution follows the same semantics as RegistrySource in a Komposer — if you know how to pull a pattern, you already know how to pull a Motif.

The Orkestra registry houses both patterns and motifs. Each Motif is a standalone OCI artifact or Git repo with motif.yaml at its root.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(path string) (*orktypes.Motif, error)

Load loads a Motif from a local file path. For full import resolution (registry, OCI, auth), use LoadImport.

func LoadImport

func LoadImport(imp *orktypes.MotifImport) (*orktypes.Motif, error)

LoadImport resolves and loads a Motif from a MotifImport declaration. Supports file paths, OCI artifacts, and Git registries — the same resolution semantics as RegistrySource in a Komposer.

File path (developer path):

imp.Motif = "./postgres/motif.yaml"

OCI artifact — motif.yaml at artifact root:

imp.Motif = "ghcr.io/orkspace/orkestra-registry/postgres@v16"
imp.OCI   = true

Git registry — motif.yaml at repo root (standalone Motif repo):

imp.Motif = "https://github.com/myorg/postgres-motif@main"

Pattern with bundled Motif (pattern includes both katalog.yaml and motif.yaml):

imp.Motif = "ghcr.io/orkspace/orkestra-registry/postgres@v16"
imp.OCI   = true

func MergeHookTemplates

func MergeHookTemplates(dst, src *orktypes.HookTemplates)

MergeHookTemplates appends resources from src into dst.

func ValidateMotifTemplates

func ValidateMotifTemplates(m *orktypes.Motif) []string

ValidateMotifTemplates checks that all inputs.X references in the resource YAML correspond to declared input names. Returns a list of error strings.

Types

type ExpandedMotif

type ExpandedMotif struct {
	Resources *orktypes.HookTemplates
	Status    *orktypes.StatusConfig
	Admission *orktypes.Admission
}

ExpandedMotif holds the result of expanding a motif.

func Expand

func Expand(m *orktypes.Motif, bindings map[string]string) (*ExpandedMotif, error)

Expand instantiates a Motif with the given input bindings and returns the expanded resources, status, and admission configuration.

bindings maps input name → resolved value. Required inputs missing from bindings are a validation error. Unknown inputs in bindings are also an error. Optional inputs not in bindings use their Motif-declared defaults.

Expand replaces all `{{ .inputs.Name }}` and `{{ inputs.Name }}` expressions in the YAML of resources, status, and admission with the resolved binding values. Other template expressions (e.g., `{{ .children.* }}`) are left untouched and will be evaluated at runtime by the reconciler.

Jump to

Keyboard shortcuts

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