blueprint

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 31 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package blueprint provides blueprint loading, facet processing, composition, and writing for the Windsor CLI.

The YAMLNodeResolver provides YAML AST utilities for resolving line numbers from facet files. It navigates goccy/go-yaml parsed trees to locate specific nodes by structural path (map key, named sequence item, sequence index, or entry value match), enabling precise provenance line number resolution during blueprint composition and explain.

Index

Constants

View Source
const MaxDisplayLines = 20

MaxDisplayLines is the longest string, in lines, that YAML display output prints in full.

Variables

View Source
var DefaultBlueprint = blueprintv1alpha1.Blueprint{
	Kind:       "Blueprint",
	ApiVersion: "blueprints.windsorcli.dev/v1alpha1",
	Metadata: blueprintv1alpha1.Metadata{
		Name:        "default",
		Description: "A default blueprint",
	},
	Sources:             []blueprintv1alpha1.Source{},
	TerraformComponents: []blueprintv1alpha1.TerraformComponent{},
	Kustomizations:      []blueprintv1alpha1.Kustomization{},
}

DefaultBlueprint is the blueprint that Windsor composes when no blueprint exists.

View Source
var ErrBlueprintInvalid = errors.New("invalid blueprint")

ErrBlueprintInvalid is the sentinel that wraps a structural error in a composed blueprint.

Functions

func CollapseLongStrings added in v0.10.0

func CollapseLongStrings(resource any) any

CollapseLongStrings replaces every string value in resource that has more than MaxDisplayLines lines with a placeholder that names the line count and the --full flag. It walks structs, maps, slices, pointers and interfaces, and it edits resource in place. Pass a copy that RenderForDisplay returned, never the composed blueprint. A resource that is not a pointer passes through unchanged.

func EvaluateWithOrigins added in v0.9.0

func EvaluateWithOrigins(eval evaluator.ExpressionEvaluator, keyPath string, value any, origins map[string]string, scope map[string]any, evaluateDeferred bool) (any, error)

EvaluateWithOrigins evaluates a single input value using per-sub-key origin paths stored in origins (dot-separated keys such as "config.db.host"). When a direct origin exists for keyPath the entire value is evaluated against that path. When sub-key origins exist the value is walked recursively so each leaf resolves against its originating facet.

func IsDowngrade added in v0.9.0

func IsDowngrade(previousURL, targetURL string) bool

IsDowngrade reports whether targetURL pins an older stable semver than previousURL for the same OCI repository. It returns false when either URL is not a parseable OCI reference, when the two reference different repositories (a re-source is not an ordered version change), or when either tag is not a semver (a branch, mutable tag, or commit is not ordered) — in those cases a regression cannot be asserted, so the caller must not treat the change as a downgrade.

func MergeScopeMaps added in v0.9.0

func MergeScopeMaps(globalScope map[string]any, overlay map[string]any) map[string]any

MergeScopeMaps deep-merges two scope maps (e.g. from multiple loaders or scope plus context values). When the same block name exists in both, block bodies are deep-merged recursively (maps by key, lists/scalars replaced at that path). Returns a new map; does not mutate inputs.

func OrdinalFromBasename added in v0.9.0

func OrdinalFromBasename(basename string) int

OrdinalFromBasename returns the default ordinal for a facet file given only its basename (e.g. "config-cluster.yaml", "provider-base.yaml"). Used by OrdinalFromFacetPath and by tests.

func OrdinalFromFacetPath added in v0.9.0

func OrdinalFromFacetPath(path string) int

OrdinalFromFacetPath returns the default ordinal for a facet from the basename of its path. A higher ordinal wins in a merge. Rules: config-* 100; provider-* or platform-* with "-base" 199; provider-* or platform-* 200; option-* or options-* 300; addon-*, addons-*, app-*, or apps-* 400; no match 0.

func RenderForDisplay added in v0.9.0

func RenderForDisplay(resource any, raw bool, deferredPaths map[string]bool) any

RenderForDisplay returns a copy of resource ready for CLI output: composed-blueprint fields not meant for display (Messages, resolved separately by GenerateResolved for bootstrap/up to print) are cleared, and unless raw is true, deferred values named in deferredPaths are rewritten to a placeholder. Unsupported resource types pass through unchanged.

func ValidateComposedBlueprint added in v0.9.0

func ValidateComposedBlueprint(blueprint *blueprintv1alpha1.Blueprint) error

ValidateComposedBlueprint returns an error if the backend field names a terraform component that does not exist, or if a kubernetes.io/tls secret does not have both the tls.crt and tls.key data keys. It accepts a nil blueprint and an empty backend field. The error has a remediation hint and wraps ErrBlueprintInvalid.

Types

type BaseBlueprintComposer added in v0.9.0

type BaseBlueprintComposer struct {
	// contains filtered or unexported fields
}

BaseBlueprintComposer provides the default implementation of the BlueprintComposer interface.

func NewBlueprintComposer added in v0.9.0

func NewBlueprintComposer(rt *runtime.Runtime) *BaseBlueprintComposer

NewBlueprintComposer creates a new BlueprintComposer that merges multiple blueprints into one. The runtime provides access to configuration and context.

func (*BaseBlueprintComposer) Compose added in v0.9.0

func (c *BaseBlueprintComposer) Compose(loaders []BlueprintLoader, initLoaderNames []string, userBlueprintPath string, configScope map[string]any) (*blueprintv1alpha1.Blueprint, error)

Compose merges the blueprints of the loaders into one blueprint. It merges the install sources in the order of the user Sources list, then applies the user blueprint last, through StrategicMerge. It adds each loader's source to Sources, so a component can name its source. It adds the "template" source only when the local template directory exists. When configScope is not nil, config-block references in user blueprint terraform inputs resolve against it.

func (*BaseBlueprintComposer) SetExcludedFacets added in v0.9.0

func (c *BaseBlueprintComposer) SetExcludedFacets(excluded []ExcludedFacet)

SetExcludedFacets provides the facets dropped by a false when: during facet processing, so validateDependencies can attribute a dangling dependency to the excluded facet that would have provided it and name the condition that excluded it.

type BaseBlueprintHandler

type BaseBlueprintHandler struct {
	// contains filtered or unexported fields
}

BaseBlueprintHandler provides the default implementation of the BlueprintHandler interface. It orchestrates the pipeline: Load → Process → Compose → Write.

func NewBlueprintHandler

func NewBlueprintHandler(rt *runtime.Runtime, artifactBuilder artifact.Artifact, opts ...*BaseBlueprintHandler) *BaseBlueprintHandler

NewBlueprintHandler creates a new BlueprintHandler with the provided runtime and artifact builder. It initializes the internal processor, composer, and writer components with sensible defaults. Optional overrides can be passed to replace any of the internal components for testing or custom behavior. Panics if runtime or artifactBuilder are nil.

func (*BaseBlueprintHandler) AddChangelogUrls added in v0.10.0

func (h *BaseBlueprintHandler) AddChangelogUrls(changes []SourceUpgrade) []SourceUpgrade

AddChangelogUrls returns changes with ChangelogUrl set from the metadata.yaml of each To version. It reads only the artifact cache, so call it after LoadBlueprint pulls the new versions. A change keeps an empty ChangelogUrl when its source is not OCI, is not in the cache, or sets no changelogUrl.

func (*BaseBlueprintHandler) DeferredSubstitutionsInScope added in v0.9.1

func (h *BaseBlueprintHandler) DeferredSubstitutionsInScope(scope map[string]bool) bool

DeferredSubstitutionsInScope reports whether a deferred substitution is about to be written by `apply kustomize`. A blueprint-level ConfigMap or global substitution is always in scope. A per-kustomization substitution is in scope only when its kustomization name is in scope. A plain kustomize: entry names that kustomization directly, as "kustomize.<name>.substitutions.<key>". A flux: system tier names it indirectly. fluxTierScopeName maps the tier path to its compiled Kustomization name first.

func (*BaseBlueprintHandler) Explain added in v0.9.0

func (h *BaseBlueprintHandler) Explain(pathStr string) (*ExplainTrace, error)

Explain delegates to the trace collector if set, otherwise returns an error. The handler method exists only to satisfy the BlueprintHandler interface.

func (*BaseBlueprintHandler) Generate

Generate returns the fully composed blueprint after all sources and user blueprint have been merged. This is a simple accessor method that returns the composedBlueprint field. The blueprint is already fully processed and composed by LoadBlueprint(). Input expressions and substitutions remain in their raw form and are evaluated later by their respective consumers.

func (*BaseBlueprintHandler) GenerateResolved added in v0.9.0

func (h *BaseBlueprintHandler) GenerateResolved() (*blueprintv1alpha1.Blueprint, error)

GenerateResolved returns a deep copy of the composed blueprint with deferred substitutions resolved, for consumers that need final values, such as the ConfigMaps the provisioner writes. The composed blueprint does not change, so later calls start from the deferred expressions. Display callers use Generate. A substitution that does not resolve is an error that names its path, such as "kustomize.dns.substitutions.external_dns_tenant_id", so no raw ${...} text reaches a ConfigMap.

func (*BaseBlueprintHandler) GetConfigScope added in v0.9.1

func (h *BaseBlueprintHandler) GetConfigScope() map[string]any

GetConfigScope returns the composed config scope: facet config: block names mapped to their fully evaluated values, merged with context values. Populated by LoadBlueprint(); nil before the first successful load.

func (*BaseBlueprintHandler) GetDeclaredSources added in v0.9.0

func (h *BaseBlueprintHandler) GetDeclaredSources() ([]blueprintv1alpha1.Source, error)

GetDeclaredSources loads only the context's blueprint.yaml (the user blueprint) and returns its declared sources, without loading remote source content or composing. It is the cheap pre-flight read upgrade uses to evaluate a --source change before pulling or composing anything, so a refused downgrade never triggers a registry round-trip. Returns an empty slice when no blueprint.yaml or no sources are declared.

func (*BaseBlueprintHandler) GetDeferredPaths added in v0.9.0

func (h *BaseBlueprintHandler) GetDeferredPaths() map[string]bool

GetDeferredPaths returns composed paths whose values were deferred during expression evaluation.

func (*BaseBlueprintHandler) GetTerraformComponents

func (h *BaseBlueprintHandler) GetTerraformComponents() []blueprintv1alpha1.TerraformComponent

GetTerraformComponents returns a copy of the composed blueprint's terraform components with Source and FullPath resolved for each component. Source names are expanded to full OCI or Git URLs based on the Sources array. Components with a Name or Source are placed in the Windsor scratch path (contexts/<context>/terraform/), while local components without a source are placed in the project's terraform directory.

func (*BaseBlueprintHandler) LoadBlueprint

func (h *BaseBlueprintHandler) LoadBlueprint(blueprintURL ...string) error

LoadBlueprint runs the full pipeline: it loads the init blueprints from blueprintURL, the user blueprint, and all sources, nested sources included. It then processes the facets of each source and composes one blueprint, with the user blueprint applied last. Each call clears the loaded sources first, so a call after RetargetSource pulls every source again. It returns an error for a context that init did not finish, unless SetAllowUninitialized is set.

func (*BaseBlueprintHandler) RetargetSource added in v0.9.0

func (h *BaseBlueprintHandler) RetargetSource(name, url string) (string, error)

RetargetSource repoints an already-declared source to a new tagged OCI URL and returns the source's previous URL for diff reporting. The new URL must include a version tag, validated via OCI parsing; the tag is carried in the URL (the canonical source form), so any prior ref fields are cleared. It errors when the source name is not declared, since adding or removing a source is a structural edit to blueprint.yaml rather than a retarget. RetargetSource mutates the composed blueprint in memory only; call Write to persist.

func (*BaseBlueprintHandler) SetAllowUninitialized added in v0.10.0

func (h *BaseBlueprintHandler) SetAllowUninitialized(allow bool)

SetAllowUninitialized lets LoadBlueprint compose a context that has no blueprint source when allow is true. The default is false. Init sets it, because init composes a context before it writes blueprint.yaml. LoadBlueprintIfTerraformProject sets it, because env and exec need only the env vars of a context.

func (*BaseBlueprintHandler) SetSkipValidation added in v0.9.0

func (h *BaseBlueprintHandler) SetSkipValidation(skip bool)

SetSkipValidation turns off structural validation and the uninitialized-context check in LoadBlueprint when skip is true. The default is false. Teardown commands (destroy, down, env) set it, so an operator can still tear down or inspect a blueprint that fails validation. Deploy commands keep validation, so a structural mistake shows when it is made. Destroy order does not depend on validation, because the destroy paths do not use blueprint position.

func (*BaseBlueprintHandler) SetTraceCollector added in v0.9.0

func (h *BaseBlueprintHandler) SetTraceCollector(tc TraceCollector)

SetTraceCollector enables opt-in trace collection for windsor explain and windsor show artifacts. When set, the collector is propagated to the processor at the start of composition so expression scope references and nested paths are recorded during facet processing. Pass nil to disable.

func (*BaseBlueprintHandler) UpgradeSourcesToLatest added in v0.9.0

func (h *BaseBlueprintHandler) UpgradeSourcesToLatest() ([]SourceUpgrade, error)

UpgradeSourcesToLatest moves each remote OCI source pinned to a semver to the highest stable tag this CLI is compatible with (see artifact.ResolveCompatibleTag), mutating the composed blueprint in memory (call Write to persist) and returning the changes for reporting. Sources that are not OCI, not semver-pinned, or already at the latest compatible tag are left untouched. All tags are resolved before any source is mutated, so a registry failure mid-resolution leaves the in-memory blueprint untouched.

func (*BaseBlueprintHandler) Write

func (h *BaseBlueprintHandler) Write(overwrite ...bool) error

Write persists the blueprint to blueprint.yaml in the config root directory. It always writes the referential form (metadata, repository, sources only). If overwrite is true, an existing file is replaced; if false or omitted, the file is only written if it does not already exist, preserving user modifications. It leaves out a repository that holds only dev-mode defaults, because Windsor derives those from the project directory name on every run.

type BaseBlueprintLoader added in v0.9.0

type BaseBlueprintLoader struct {
	// contains filtered or unexported fields
}

BaseBlueprintLoader provides the default implementation of the BlueprintLoader interface.

func NewBlueprintLoader added in v0.9.0

func NewBlueprintLoader(rt *runtime.Runtime, artifactBuilder artifact.Artifact) *BaseBlueprintLoader

NewBlueprintLoader creates a new BlueprintLoader. The sourceName and sourceURL are provided when calling Load(), not during construction. The artifactBuilder is required for OCI sources but may be nil for local sources.

func (*BaseBlueprintLoader) GetBlueprint added in v0.9.0

func (l *BaseBlueprintLoader) GetBlueprint() *blueprintv1alpha1.Blueprint

GetBlueprint returns the loaded blueprint, which may be nil if loading failed or the source does not contain a blueprint. The blueprint is modified during facet processing as components from evaluated facets are appended to it.

func (*BaseBlueprintLoader) GetBlueprintPath added in v0.9.0

func (l *BaseBlueprintLoader) GetBlueprintPath() string

GetBlueprintPath returns the absolute path to the main blueprint file (e.g. blueprint.yaml) for this source. For the user blueprint this is the config root blueprint; for template/OCI sources it is empty. Used when resolving relative paths in expressions (e.g. yaml(), file()).

func (*BaseBlueprintLoader) GetFacets added in v0.9.0

func (l *BaseBlueprintLoader) GetFacets() []blueprintv1alpha1.Facet

GetFacets returns all Facet definitions loaded from this source's facets directory. Facets are YAML files in the facets/ subdirectory that define conditional terraform components and kustomizations. Returns an empty slice if no facets were found.

func (*BaseBlueprintLoader) GetSourceName added in v0.9.0

func (l *BaseBlueprintLoader) GetSourceName() string

GetSourceName returns the identifier for this loader, used in error messages and to track which source a blueprint came from during composition. Common values are "primary", "user", or the name specified in a blueprint's sources array.

func (*BaseBlueprintLoader) GetTemplateData added in v0.9.0

func (l *BaseBlueprintLoader) GetTemplateData() map[string][]byte

GetTemplateData returns a map of relative file paths to their contents for all files collected from this source. This data is used when building OCI artifacts from local templates, allowing the complete template to be pushed to a registry.

func (*BaseBlueprintLoader) Load added in v0.9.0

func (l *BaseBlueprintLoader) Load(sourceName, sourceURL string) error

Load loads the blueprint from the specified source. The sourceName identifies this loader (e.g., "user", "template", or a source name from the sources array). The sourceURL specifies an OCI artifact URL to pull; if empty, the loader will use local filesystem paths based on sourceName. For "user", it loads from config root. For other names, it loads from _template.

type BaseBlueprintProcessor added in v0.9.0

type BaseBlueprintProcessor struct {
	// contains filtered or unexported fields
}

BaseBlueprintProcessor provides the default implementation of the BlueprintProcessor interface.

func NewBlueprintProcessor added in v0.9.0

func NewBlueprintProcessor(rt *runtime.Runtime) *BaseBlueprintProcessor

NewBlueprintProcessor creates a new BlueprintProcessor using the runtime's expression evaluator. The evaluator evaluates the when: conditions on facets and components. The processor can be shared across concurrent facet processing operations. It panics if the runtime or its evaluator is nil.

func (*BaseBlueprintProcessor) GetDeferredPaths added in v0.9.0

func (p *BaseBlueprintProcessor) GetDeferredPaths() map[string]bool

GetDeferredPaths returns a copy of deferred composed paths discovered during the last ProcessGlobally call.

func (*BaseBlueprintProcessor) GetExcludedFacets added in v0.9.0

func (p *BaseBlueprintProcessor) GetExcludedFacets() []ExcludedFacet

GetExcludedFacets returns a copy of the facets excluded by a false when: across every ProcessGlobally call since the last reset. Read it after composition completes so the set is stable.

func (*BaseBlueprintProcessor) ProcessGlobally added in v0.9.0

func (p *BaseBlueprintProcessor) ProcessGlobally(sources []SourceFacetSet) (map[string]any, error)

ProcessGlobally resolves config and facet inclusion once across all sources, then emits each source's included components into its own target. A depth-adjusted ordinal ranks the facets, so a deeper source's config wins for the same key. Derivations resolve against the final merged scope. An operator's explicit raw value always wins over a facet's computed value (resolveConfigAndInclusion). Each source's removals also apply to shallower sources (applyRemovalsToShallowerSources). The per-entry ordinals get the same depth offset as the facet ordinals (shiftEntryOrdinals). Before resolution, it checks that no facet reads or writes a config block that another source owns (checkSourceScopes). It returns the resolved global scope.

func (*BaseBlueprintProcessor) ResetExcludedFacets added in v0.9.0

func (p *BaseBlueprintProcessor) ResetExcludedFacets()

ResetExcludedFacets clears the accumulated excluded-facet record. Callers invoke it once before a composition, so the set reflects only that composition. ProcessGlobally appends to the record and does not reset it.

func (*BaseBlueprintProcessor) SetExtraScope added in v0.9.0

func (p *BaseBlueprintProcessor) SetExtraScope(scope map[string]any)

SetExtraScope sets additional scope values that are merged over context values during facet processing.

func (*BaseBlueprintProcessor) SetTraceCollector added in v0.9.0

func (p *BaseBlueprintProcessor) SetTraceCollector(tc TraceCollector)

SetTraceCollector sets the trace collector for recording per-key contributions and config blocks during composition. When non-nil, all contributions are recorded into the collector. Set to nil to disable trace collection.

type BaseBlueprintWriter added in v0.9.0

type BaseBlueprintWriter struct {
	// contains filtered or unexported fields
}

BaseBlueprintWriter provides the default implementation of the BlueprintWriter interface.

func NewBlueprintWriter added in v0.9.0

func NewBlueprintWriter(rt *runtime.Runtime) *BaseBlueprintWriter

NewBlueprintWriter creates a new BlueprintWriter that persists blueprints to the filesystem. The runtime provides the config root path where blueprint.yaml will be written. Optional overrides allow replacing the shims for testing file system operations.

func (*BaseBlueprintWriter) Write added in v0.9.0

func (w *BaseBlueprintWriter) Write(blueprint *blueprintv1alpha1.Blueprint, overwrite bool, initBlueprintURLs ...string) error

Write saves the blueprint to blueprint.yaml in the config root, in its referential form: metadata, repository, and sources, with no components. Components come from the sources; "windsor show blueprint" shows the full blueprint. When overwrite is false and the file exists, Write does nothing. initBlueprintURLs become sources, and only oci:// sources get install: true.

type BlueprintComposer added in v0.9.0

type BlueprintComposer interface {
	Compose(loaders []BlueprintLoader, initLoaderNames []string, userBlueprintPath string, configScope map[string]any) (*blueprintv1alpha1.Blueprint, error)
}

BlueprintComposer combines processed blueprints from multiple loaders into a final composed blueprint. It applies the composition algorithm: Sources (in order) → Template (if not in sources) → User overlay.

type BlueprintHandler

type BlueprintHandler interface {
	LoadBlueprint(blueprintURL ...string) error
	SetSkipValidation(skip bool)
	SetAllowUninitialized(allow bool)
	Write(overwrite ...bool) error
	RetargetSource(name, url string) (string, error)
	UpgradeSourcesToLatest() ([]SourceUpgrade, error)
	AddChangelogUrls(changes []SourceUpgrade) []SourceUpgrade
	GetDeclaredSources() ([]blueprintv1alpha1.Source, error)
	GetTerraformComponents() []blueprintv1alpha1.TerraformComponent
	Generate() *blueprintv1alpha1.Blueprint
	GenerateResolved() (*blueprintv1alpha1.Blueprint, error)
	Explain(path string) (*ExplainTrace, error)
	GetDeferredPaths() map[string]bool
	DeferredSubstitutionsInScope(scope map[string]bool) bool
	GetConfigScope() map[string]any
}

BlueprintHandler manages the lifecycle of infrastructure blueprints. It orchestrates loading, processing, composing, and writing blueprints.

type BlueprintLoader added in v0.9.0

type BlueprintLoader interface {
	Load(sourceName, sourceURL string) error
	GetBlueprint() *blueprintv1alpha1.Blueprint
	GetFacets() []blueprintv1alpha1.Facet
	GetTemplateData() map[string][]byte
	GetSourceName() string
}

BlueprintLoader holds individual blueprint state in-memory through the processing lifecycle. One BlueprintLoader is created per blueprint source (primary, each OCI source, user).

type BlueprintProcessor added in v0.9.0

type BlueprintProcessor interface {
	ProcessGlobally(sources []SourceFacetSet) (map[string]any, error)
}

BlueprintProcessor evaluates when: conditions on facets, terraform components, and kustomizations. It determines inclusion/exclusion based on boolean condition results. All loaders share one processor. ProcessGlobally returns the evaluated config scope, which callers use for the user overlay and for the final terraform input evaluation.

type BlueprintWriter added in v0.9.0

type BlueprintWriter interface {
	Write(blueprint *blueprintv1alpha1.Blueprint, overwrite bool, initBlueprintURLs ...string) error
}

BlueprintWriter writes the final composed blueprint to contexts/<context>/blueprint.yaml.

type ConfigBlockRecord added in v0.9.0

type ConfigBlockRecord struct {
	FacetPath   string
	Line        int
	RawValue    any
	ScopeRefs   []string
	NestedPaths []string
	NestedRefs  map[string][]string
}

ConfigBlockRecord records a config block value for scope reference resolution. ScopeRefs and NestedPaths are pre-extracted during recording so query-time AST parsing is not needed. NestedRefs maps each nested expression path to its pre-extracted scope variable references.

type CrdInstallLayer added in v0.9.0

type CrdInstallLayer struct {
	Source string
	Refs   []string
}

CrdInstallLayer is a CRD kustomization the provisioner will synthesize: a source (empty for the default/project source) and the references it owns. Derived from the composed blueprint by CrdLayers.

func CrdLayers added in v0.9.0

CrdLayers returns the CRD kustomization layers a composed blueprint implies: the default/project layer (empty source) from bp.Crds, then one per install source that vendors CRDs, alphabetically by name. The composer wires the stack to these names and the provisioner materializes them, so both must agree on the set — they share this single derivation.

type DefaultTraceCollector added in v0.9.0

type DefaultTraceCollector struct {
	// contains filtered or unexported fields
}

DefaultTraceCollector is the standard TraceCollector implementation backed by in-memory maps. It records contributions and config blocks during composition. After composition, Finalize stores the composed blueprint, scope, and template root. GetTrace performs lazy resolution on demand.

func NewTraceCollector added in v0.9.0

func NewTraceCollector() *DefaultTraceCollector

NewTraceCollector creates a new DefaultTraceCollector with initialized storage.

func (*DefaultTraceCollector) Finalize added in v0.9.0

func (c *DefaultTraceCollector) Finalize(bp *blueprintv1alpha1.Blueprint, scope map[string]any, templateRoot string)

Finalize stores the composed blueprint, scope, and template root for lazy trace resolution. Called once after all facet processing and scope merging completes.

func (*DefaultTraceCollector) GetTrace added in v0.9.0

func (c *DefaultTraceCollector) GetTrace(pathStr string) (*ExplainTrace, error)

GetTrace resolves a dotted blueprint path and returns a trace with the composed value, contributions sorted by ordinal, effective marking, and scope reference resolution.

func (*DefaultTraceCollector) RecordBlueprintValue added in v0.10.0

func (c *DefaultTraceCollector) RecordBlueprintValue(value any)

RecordBlueprintValue stores a raw value of a blueprint file. A blueprint file is not a facet, so it has no contribution, but its expressions can read config blocks. Thread-safe.

func (*DefaultTraceCollector) RecordConfigBlock added in v0.9.0

func (c *DefaultTraceCollector) RecordConfigBlock(configPath string, record ConfigBlockRecord)

RecordConfigBlock stores a config block value and pre-extracts scope references, nested expression paths, and per-path refs from the raw value. No child entries are created; getConfigBlockWithRecord's fallback logic resolves lines via YAML AST. Thread-safe.

func (*DefaultTraceCollector) RecordContribution added in v0.9.0

func (c *DefaultTraceCollector) RecordContribution(composedPath string, tc TraceContribution)

RecordContribution stores a per-key contribution from a facet and pre-extracts scope references from the raw value expression. Called from the processor during composition for each terraform input, kustomize substitution, and kustomize components list. Thread-safe.

func (*DefaultTraceCollector) RecordFacet added in v0.10.0

func (c *DefaultTraceCollector) RecordFacet(facetPath string)

RecordFacet stores the path of a facet that composition loaded, also when its when is false. Thread-safe.

func (*DefaultTraceCollector) ResetConfigBlocks added in v0.10.0

func (c *DefaultTraceCollector) ResetConfigBlocks(facetPaths []string)

ResetConfigBlocks removes the config block records of the facets at facetPaths. Composition calls it before each config round, because a block that is active in an early round can be inactive in the last round. Thread-safe.

func (*DefaultTraceCollector) SettleEntry added in v0.10.0

func (c *DefaultTraceCollector) SettleEntry(entry string, keepExisting, keepNew bool)

SettleEntry applies the result of one merge to the contributions of entry. New contributions are those recorded since the last call for entry, and existing contributions are all the others. It discards each group that the merge did not keep. Thread-safe.

func (*DefaultTraceCollector) UnusedFacetValue added in v0.10.0

func (c *DefaultTraceCollector) UnusedFacetValue(facetPath string, line int) (bool, string)

UnusedFacetValue reports whether the composed blueprint does not use the value on line of the facet at facetPath. It returns false for a file that composition did not load as a facet. A value is unused when no active config block or contribution holds it, or when no composed value reaches its config key. When the trace cannot resolve the value, it returns false and a note.

type ExcludedFacet added in v0.9.0

type ExcludedFacet struct {
	Name     string   // facet metadata name
	When     string   // the when: expression that evaluated false
	Provides []string // terraform component IDs and kustomization names (including flux tiers) it declares
}

ExcludedFacet records a facet dropped from composition by a false when: condition, along with the component and kustomization names it would have contributed. Dependency validation joins a dangling dependency name against these so it can name the excluded facet and the condition that excluded it, rather than only reporting the unresolvable edge.

type ExplainContribution added in v0.9.0

type ExplainContribution struct {
	SourceName    string
	FacetPath     string
	AbsFacetPath  string
	Line          int
	Ordinal       int
	Strategy      string
	Expression    string
	HasValue      bool
	Effective     bool
	Discarded     bool
	ScopeRefs     []ExplainScopeRef
	RawComponents []string
	// contains filtered or unexported fields
}

ExplainContribution describes one source that contributed to the value (facet file, source name, etc.). AbsFacetPath is the absolute filesystem path for clickable terminal references; FacetPath is the shortened display form. Line is the 1-based line number of the specific key (or the component definition if the key is not locatable). Effective is true when this contribution produced the final composed value; false means it was overridden by a higher-ordinal facet. Discarded is true when the merge dropped the entry of this contribution, so it cannot be effective.

type ExplainPath added in v0.9.0

type ExplainPath struct {
	Kind    ExplainPathKind
	Segment string
	Key     string
}

ExplainPath is a parsed explain path identifying a single value in the composed blueprint.

func ParseExplainPath added in v0.9.0

func ParseExplainPath(path string) (ExplainPath, error)

ParseExplainPath parses a path into an ExplainPath. The forms are terraform.<componentID>.inputs.<key>, kustomize.<name>.substitutions.<key>, kustomize.<name>.components, configMaps.<name>.<key>, and substitutions.<key>. A kustomize <name> can be a plain kustomization or a compiled flux tier. It returns an error if the path is empty. A path with an unknown root or a wrong form returns an error with a remediation hint that shows the correct form.

func (ExplainPath) String added in v0.9.0

func (p ExplainPath) String() string

String returns the canonical path string (e.g. terraform.cluster.inputs.domain_name).

type ExplainPathKind added in v0.9.0

type ExplainPathKind int

ExplainPathKind identifies the type of blueprint path being explained.

const (
	ExplainPathKindTerraformInput ExplainPathKind = iota
	ExplainPathKindKustomizeSubstitution
	ExplainPathKindKustomizeComponents
	ExplainPathKindConfigMap
	ExplainPathKindSubstitution
)

type ExplainScopeRef added in v0.9.0

type ExplainScopeRef struct {
	Name   string
	Status string
	Source string
	Line   int
	Nested []ExplainScopeRef
}

ExplainScopeRef describes a scope variable referenced in an expression, its resolution status, and the source location of the config block that defines it (if applicable). Nested holds refs for expressions or map keys that contain expressions, recursively until origins.

type ExplainTrace added in v0.9.0

type ExplainTrace struct {
	Path          string
	Value         string
	Contributions []ExplainContribution
}

ExplainTrace holds the result of explaining a path: the value and its contributions.

type MockBlueprintHandler

type MockBlueprintHandler struct {
	LoadBlueprintFunc                func(...string) error
	SetSkipValidationFunc            func(skip bool)
	SetAllowUninitializedFunc        func(allow bool)
	WriteFunc                        func(overwrite ...bool) error
	RetargetSourceFunc               func(name, url string) (string, error)
	UpgradeSourcesToLatestFunc       func() ([]SourceUpgrade, error)
	AddChangelogUrlsFunc             func(changes []SourceUpgrade) []SourceUpgrade
	GetDeclaredSourcesFunc           func() ([]blueprintv1alpha1.Source, error)
	GetTerraformComponentsFunc       func() []blueprintv1alpha1.TerraformComponent
	GenerateFunc                     func() *blueprintv1alpha1.Blueprint
	GenerateResolvedFunc             func() (*blueprintv1alpha1.Blueprint, error)
	ExplainFunc                      func(string) (*ExplainTrace, error)
	GetDeferredPathsFunc             func() map[string]bool
	DeferredSubstitutionsInScopeFunc func(scope map[string]bool) bool
	GetConfigScopeFunc               func() map[string]any
	// contains filtered or unexported fields
}

MockBlueprintHandler is a mock implementation of BlueprintHandler interface for testing.

func NewMockBlueprintHandler

func NewMockBlueprintHandler() *MockBlueprintHandler

NewMockBlueprintHandler creates a new instance of MockBlueprintHandler.

func (*MockBlueprintHandler) AddChangelogUrls added in v0.10.0

func (m *MockBlueprintHandler) AddChangelogUrls(changes []SourceUpgrade) []SourceUpgrade

AddChangelogUrls calls the mock AddChangelogUrlsFunc if set, otherwise returns changes unchanged.

func (*MockBlueprintHandler) DeferredSubstitutionsInScope added in v0.9.1

func (m *MockBlueprintHandler) DeferredSubstitutionsInScope(scope map[string]bool) bool

DeferredSubstitutionsInScope calls the mock DeferredSubstitutionsInScopeFunc if set, otherwise returns false.

func (*MockBlueprintHandler) Explain added in v0.9.0

func (m *MockBlueprintHandler) Explain(path string) (*ExplainTrace, error)

Explain calls the mock ExplainFunc if set, otherwise returns nil.

func (*MockBlueprintHandler) Generate

Generate calls the mock GenerateFunc if set, otherwise returns nil.

func (*MockBlueprintHandler) GenerateResolved added in v0.9.0

func (m *MockBlueprintHandler) GenerateResolved() (*blueprintv1alpha1.Blueprint, error)

GenerateResolved calls the mock GenerateResolvedFunc if set, otherwise falls back to Generate.

func (*MockBlueprintHandler) GetConfigScope added in v0.9.1

func (m *MockBlueprintHandler) GetConfigScope() map[string]any

GetConfigScope calls the mock GetConfigScopeFunc if set, otherwise returns nil.

func (*MockBlueprintHandler) GetDeclaredSources added in v0.9.0

func (m *MockBlueprintHandler) GetDeclaredSources() ([]blueprintv1alpha1.Source, error)

GetDeclaredSources calls the mock GetDeclaredSourcesFunc if set, otherwise returns nil.

func (*MockBlueprintHandler) GetDeferredPaths added in v0.9.0

func (m *MockBlueprintHandler) GetDeferredPaths() map[string]bool

GetDeferredPaths calls the mock GetDeferredPathsFunc if set, otherwise returns nil.

func (*MockBlueprintHandler) GetTerraformComponents

func (m *MockBlueprintHandler) GetTerraformComponents() []blueprintv1alpha1.TerraformComponent

GetTerraformComponents calls the mock GetTerraformComponentsFunc if set, otherwise returns empty slice.

func (*MockBlueprintHandler) LoadBlueprint

func (m *MockBlueprintHandler) LoadBlueprint(blueprintURL ...string) error

LoadBlueprint calls the mock LoadBlueprintFunc if set, otherwise returns nil.

func (*MockBlueprintHandler) RetargetSource added in v0.9.0

func (m *MockBlueprintHandler) RetargetSource(name, url string) (string, error)

RetargetSource calls the mock RetargetSourceFunc if set, otherwise returns an empty previous URL.

func (*MockBlueprintHandler) SetAllowUninitialized added in v0.10.0

func (m *MockBlueprintHandler) SetAllowUninitialized(allow bool)

SetAllowUninitialized calls the mock SetAllowUninitializedFunc if set.

func (*MockBlueprintHandler) SetSkipValidation added in v0.9.0

func (m *MockBlueprintHandler) SetSkipValidation(skip bool)

SetSkipValidation calls the mock SetSkipValidationFunc if set, otherwise records the flag on the mock so tests can assert prepareProject toggled it.

func (*MockBlueprintHandler) SkipValidation added in v0.9.0

func (m *MockBlueprintHandler) SkipValidation() bool

SkipValidation reports the recorded skip flag (only meaningful when SetSkipValidationFunc is not set). Test-only accessor.

func (*MockBlueprintHandler) UpgradeSourcesToLatest added in v0.9.0

func (m *MockBlueprintHandler) UpgradeSourcesToLatest() ([]SourceUpgrade, error)

UpgradeSourcesToLatest calls the mock UpgradeSourcesToLatestFunc if set, otherwise returns nil.

func (*MockBlueprintHandler) Write

func (m *MockBlueprintHandler) Write(overwrite ...bool) error

Write calls the mock WriteFunc if set, otherwise returns nil.

type RequirementsError added in v0.9.0

type RequirementsError struct {
	Message string
}

RequirementsError is the error for required facet inputs that are not set. Callers that wrap blueprint errors detect it with errors.As and return it unwrapped, so the operator sees only the message that formatRequirementsError builds.

func (*RequirementsError) Error added in v0.9.0

func (e *RequirementsError) Error() string

Error returns the operator-facing message.

type Shims

type Shims struct {
	shims.Shims
	Walk func(string, filepath.WalkFunc) error
}

Shims holds the shared system call primitives and the blueprint-specific directory walk.

func NewShims

func NewShims() *Shims

NewShims returns a Shims with every field set to its standard library implementation.

type SourceFacetSet added in v0.9.0

type SourceFacetSet struct {
	Name    string
	Depth   int
	Target  *blueprintv1alpha1.Blueprint
	Facets  []blueprintv1alpha1.Facet
	Exports []string
}

SourceFacetSet is one source's contribution to global composition: its name, its dependency depth (deeper/referencing sources override shallower ones), the blueprint to emit its components into, its facets, and the config block names it exports to other sources.

type SourceUpgrade added in v0.9.0

type SourceUpgrade struct {
	Name         string
	From         string
	To           string
	ChangelogUrl string
}

SourceUpgrade records one source moved to a newer version by UpgradeSourcesToLatest. ChangelogUrl comes from the metadata.yaml of the To version, and is empty when that file sets none.

type TraceCollector added in v0.9.0

type TraceCollector interface {
	RecordContribution(composedPath string, tc TraceContribution)
	RecordConfigBlock(configPath string, record ConfigBlockRecord)
	ResetConfigBlocks(facetPaths []string)
	RecordFacet(facetPath string)
	RecordBlueprintValue(value any)
	SettleEntry(entry string, keepExisting, keepNew bool)
	Finalize(bp *blueprintv1alpha1.Blueprint, scope map[string]any, templateRoot string)
	GetTrace(pathStr string) (*ExplainTrace, error)
}

TraceCollector records per-key contributions and config blocks during blueprint composition, then provides trace queries after finalization. Implementations are set on the processor before composition begins. They are active only for windsor explain and windsor show artifacts.

type TraceContribution added in v0.9.0

type TraceContribution struct {
	FacetPath      string
	SourceName     string
	Ordinal        int
	Strategy       string
	Line           int
	RawValue       any
	RawComponents  []string
	ComponentLines map[string]int
	ScopeRefs      []string
	Entry          string
	// contains filtered or unexported fields
}

TraceContribution records a single per-key contribution from a facet during composition. Recorded at the per-key level (e.g. "terraform.networking.inputs.domain_name") with all metadata resolved at record time so no retroactive YAML reparsing is needed. ScopeRefs are pre-extracted from expressions during recording. Entry names the merged entry that holds the key, so SettleEntry can discard the contribution when the merge drops that entry.

Jump to

Keyboard shortcuts

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