lifecycle

package
v1.234.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package lifecycle plans and executes component operations across stack kinds.

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry contains handlers registered by the component command packages.

Functions

func Execute

func Execute(ctx context.Context, plan *Plan, opts *ExecutionOptions) *scheduler.AggregateResult

Execute runs a prevalidated plan with the shared ready-queue scheduler.

func Label

func Label(n *dependency.Node) string

Label returns a readable fully qualified component identity.

func MustRegister

func MustRegister(kind string, event Event, handler *Handler)

MustRegister registers a built-in handler during package initialization.

func NodeID

func NodeID(kind, stack, name string) string

NodeID identifies a component without collisions across kinds or stack names.

Types

type Event

type Event string

Event is one of the supported stack lifecycle events. A component type opts in to an event by registering its handler; other command names imply no support.

const (
	PlanEvent Event = "plan"
	Build     Event = "build"
	Test      Event = "test"
	Deploy    Event = "deploy"
	Destroy   Event = "destroy"
	Validate  Event = "validate"
)

type ExecutionOptions

type ExecutionOptions struct {
	Executable     string
	Directory      string
	GlobalArgs     []string
	Environment    []string
	Streams        process.Streams
	Runner         process.Runner
	Concurrency    int
	KeepGoing      bool
	Grouped        bool
	ResourceGuards map[string]func(*dependency.Node) func()
	// NodeEnvironment optionally returns KEY=VALUE entries applied on top of the
	// child environment for one node. It runs on scheduler workers, so it must be
	// safe for concurrent use.
	NodeEnvironment func(node *dependency.Node) []string
	// OnStart and OnComplete report live progress separately from child logs.
	// Calls are serialized. Start occurs only after acquiring the resource guard.
	OnStart    func(*dependency.Node)
	OnComplete func(*dependency.Node, error)
}

ExecutionOptions supplies dependencies and streams without mutating process state.

type Filter

type Filter struct {
	Tags   []string
	Labels map[string]string
}

Filter selects components by their metadata. A component matches when its metadata.tags include any of Tags and its metadata.labels contain every pair in Labels. An empty filter matches every component.

type Handler

type Handler struct {
	Path  []string
	Args  []schema.CommandArgument
	Flags []schema.CommandFlag
	Err   error
	// HookEvents are the actual per-component hook events fired by this command.
	HookEvents []string
	// ApprovalArgs opt into the component's own non-interactive approval behavior.
	ApprovalArgs []string
	// NewResourceGuard creates one shared lock domain for this invocation.
	NewResourceGuard func(*schema.AtmosConfiguration) func(*dependency.Node) func()
	// WorkerEnvironment supplies execution policy owned by this component type.
	WorkerEnvironment func(int) []string
}

Handler binds a component kind's lifecycle event to an existing command. Invalid declarations retain their error so an unrelated kind does not fail selection.

func NativeHandler

func NativeHandler(path ...string) *Handler

NativeHandler describes the standard component positional and stack flag.

func (*Handler) Arguments

func (c *Handler) Arguments(node *dependency.Node) ([]string, error)

Arguments resolves a concrete invocation without shell interpolation.

type Notice

type Notice struct {
	Kind, Stack, Component, Reason string
}

Notice explains a component excluded from execution.

type Plan

type Plan struct {
	Graph    *dependency.Graph
	Commands map[string][]string
	Notices  []Notice
	Handlers map[string]*Handler
	// Deleted counts notices for selected definitions removed from configuration.
	Deleted int
}

Plan is an immutable scheduling graph with resolved command arguments.

func BuildPlan

func BuildPlan(stacks map[string]any, commands map[string]*Handler, selection *Selection, leftDelim string) (*Plan, error)

BuildPlan resolves selection, capability, and ordering before any operation runs.

Required prerequisites of a kind that cannot run the operation fail a deploy plan, while a destroy plan fails when components outside the selection still require something it would destroy. Other forward operations require handler support for prerequisites only when dependency expansion requests them. Locked components are never operated on.

type Registry

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

Registry associates a component type and a fixed lifecycle event with an isolated-command handler. Custom configuration is merged into a per-invocation snapshot, so loading one project's commands cannot affect another project.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an independent registry, useful for hosts and tests.

func (*Registry) Handlers

func (r *Registry) Handlers(event Event) map[string]*Handler

Handlers returns an independent snapshot of types supporting the given event.

func (*Registry) Lookup

func (r *Registry) Lookup(kind string, event Event) (*Handler, bool)

Lookup reports whether a component type supports an event and returns its handler.

func (*Registry) Register

func (r *Registry) Register(kind string, event Event, handler *Handler) error

Register opts a component type into an event. Duplicate handlers are rejected rather than allowing package initialization order to choose an implementation.

type Selection

type Selection struct {
	// Operation determines preflight and deletion notices; empty preserves deploy semantics.
	Operation Event
	Stack     string
	// Components selects exact names across kinds before expansion; empty selects every name.
	Components []string
	// A nil Affected selects all nodes; a non-nil empty slice selects none.
	Affected []schema.Affected
	// Zero disables expansion, -1 expands without a depth limit.
	Dependencies int
	Dependents   int
	Reverse      bool
	// Filter narrows the initial selection by component tags and labels.
	Filter *Filter
}

Selection selects seeds before expanding dependencies in the original graph.

Jump to

Keyboard shortcuts

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