renderer

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package renderer handles ResourceTemplate orchestration for ComponentTypes.

The renderer evaluates ResourceTemplate control flow (includeWhen, forEach) and uses the template engine to render Kubernetes resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalForEach added in v0.9.0

func EvalForEach(
	engine *template.Engine,
	forEach string,
	varName string,
	context map[string]any,
) ([]map[string]any, error)

EvalForEach evaluates a forEach CEL expression and returns contexts for each item.

The forEach expression must evaluate to an array or map:

  • Arrays: each element becomes an item
  • Maps: converted to sorted slice of {key, value} entries for deterministic order

For each item, a shallow clone of the context is created with the loop variable added. Shallow cloning is safe because the template engine only reads from the context.

If varName is empty, "item" is used as the default variable name. Returns error if forEach evaluation fails or conversion fails.

func EvaluateValidationRules added in v0.15.0

func EvaluateValidationRules(engine *template.Engine, rules []v1alpha1.ValidationRule, context map[string]any) error

EvaluateValidationRules evaluates a list of CEL-based validation rules against the given context. All rules are evaluated (no short-circuiting) and all failures are collected into a single error. Returns nil if there are no rules or all rules pass.

Error messages include rule index and rule text for easy identification. The returned error does not include a "validation failed:" prefix — callers add their own context.

func ShouldInclude added in v0.9.0

func ShouldInclude(engine *template.Engine, includeWhen string, context map[string]any) (bool, error)

ShouldInclude evaluates an includeWhen CEL expression to determine if a resource should be created.

Returns:

  • true if includeWhen is empty (default behavior - resource is always created)
  • true if includeWhen evaluates to true
  • false if includeWhen evaluates to false
  • error for evaluation failures (including missing data)

func ToIterableItems added in v0.9.0

func ToIterableItems(result any) ([]any, error)

ToIterableItems converts a forEach evaluation result to a slice of items. Arrays are returned as-is. Maps are converted to sorted slice of {key, value} entries.

Supported input types:

  • []any - returned as-is
  • []map[string]any - converted to []any
  • map[string]any - converted to sorted slice of {"key": k, "value": v} entries

For maps, the keys are sorted alphabetically to ensure deterministic iteration order. This is important for:

  • Consistent resource generation across runs
  • Predictable test results
  • Reproducible deployments

Types

type RenderedResource added in v0.8.0

type RenderedResource struct {
	// Resource is the fully rendered Kubernetes resource manifest.
	Resource map[string]any

	// TargetPlane indicates which plane this resource should be deployed to.
	TargetPlane string
}

RenderedResource wraps a rendered Kubernetes resource with metadata about its target plane.

type Renderer

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

Renderer orchestrates the rendering of ResourceTemplates from ComponentTypes.

func NewRenderer

func NewRenderer(templateEngine *template.Engine) *Renderer

NewRenderer creates a new ResourceTemplate renderer.

func (*Renderer) RenderResources

func (r *Renderer) RenderResources(
	templates []v1alpha1.ResourceTemplate,
	context map[string]any,
) ([]RenderedResource, error)

RenderResources renders all resources from a ComponentType.

The process:

  • Iterate through ComponentType.Spec.Resources
  • For each ResourceTemplate:
  • Evaluate includeWhen (skip if false)
  • Check forEach (render multiple times if present, supports arrays and maps)
  • Render template field using template engine
  • Return all rendered resources with their target planes

For forEach with maps, keys are iterated in sorted order with each item having .key and .value fields.

Returns an error if any template fails to render.

Jump to

Keyboard shortcuts

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