framework

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package framework provides resource lifecycle management.

Index

Constants

View Source
const (
	RegistryFile = "moley.lock"
)

Variables

This section is empty.

Functions

func AddManager added in v2.1.0

func AddManager[TConfig any, TState any](
	ro *ResourceOrchestrator,
	handler ResourceHandler[TConfig, TState],
	configs []TConfig,
)

AddManager adds a typed resource manager to the orchestrator

func RunWithDryRunGuard

func RunWithDryRunGuard[T any](config *Config, cb func() (T, error), defaultValue T) (T, error)

RunWithDryRunGuard runs cb unless in dry-run mode, in which case defaultValue is returned.

Types

type Config

type Config struct {
	DryRun bool
}

Config holds configuration for framework operations.

type PersistentResourceEntry added in v2.1.0

type PersistentResourceEntry struct {
	Data        any    `json:"data"`
	HandlerName string `json:"handler_name"`
}

PersistentResourceEntry represents a persisted resource in the registry file

type ReconcileOperation added in v2.1.0

type ReconcileOperation[TConfig any, TState any] struct {
	// contains filtered or unexported fields
}

ReconcileOperation implements ResourceOperation for typed managers

func (*ReconcileOperation[TConfig, TState]) Execute added in v2.1.0

func (tro *ReconcileOperation[TConfig, TState]) Execute(ctx context.Context) error

func (*ReconcileOperation[TConfig, TState]) Name added in v2.1.0

func (tro *ReconcileOperation[TConfig, TState]) Name() string

func (*ReconcileOperation[TConfig, TState]) Stop added in v2.1.0

func (tro *ReconcileOperation[TConfig, TState]) Stop(ctx context.Context) error

type ResourceChecker added in v2.1.0

type ResourceChecker[TConfig any, TState any] interface {
	// CheckFromState checks the resource status from its runtime state
	CheckFromState(ctx context.Context, state TState) (domain.State, error)
	// CheckFromConfig checks the resource status from its configuration
	CheckFromConfig(ctx context.Context, config TConfig) (TState, domain.State, error)
}

type ResourceCreator added in v2.1.0

type ResourceCreator[TConfig any, TState any] interface {
	// Create provisions the resource using the given configuration
	// Returns the runtime state needed to manage the resource
	Create(ctx context.Context, config TConfig) (TState, error)
}

type ResourceDestroyer added in v2.1.0

type ResourceDestroyer[TState any] interface {
	// Destroy removes the resource using its runtime state
	Destroy(ctx context.Context, state TState) error
}

type ResourceHandler

type ResourceHandler[TConfig any, TState any] interface {
	ResourceNamer
	ResourceChecker[TConfig, TState]
	ResourceCreator[TConfig, TState]
	ResourceDestroyer[TState]
	// Equals compares two configurations for equality
	// Used to detect when resources need to be updated
	Equals(a, b TConfig) bool
}

ResourceHandler provides type-safe resource lifecycle management. TConfig represents the desired configuration (immutable input) TState represents the runtime state after resource creation (mutable state)

type ResourceManager

type ResourceManager[TConfig any, TState any] struct {
	// contains filtered or unexported fields
}

ResourceManager manages resources of a specific type with full type safety

func NewResourceManager

func NewResourceManager[TConfig any, TState any](
	handler ResourceHandler[TConfig, TState],
	registry *ResourceRegistry,
) *ResourceManager[TConfig, TState]

NewResourceManager creates a type-safe resource manager for a specific handler type

func (*ResourceManager[TConfig, TState]) Reconcile added in v2.1.0

func (rm *ResourceManager[TConfig, TState]) Reconcile(
	ctx context.Context,
	desiredConfigs []TConfig,
) error

Reconcile ensures the desired resources match the actual state

func (*ResourceManager[TConfig, TState]) Stop

func (rm *ResourceManager[TConfig, TState]) Stop(ctx context.Context, configs []TConfig) error

Stop removes all resources managed by this typed manager (tracked + detected)

type ResourceNamer added in v2.1.0

type ResourceNamer interface {
	// Name returns the resource name for identification
	Name() string
}

type ResourceOperation added in v2.1.0

type ResourceOperation interface {
	Execute(ctx context.Context) error
	Name() string
	Stop(ctx context.Context) error
}

ResourceOperation represents a resource management operation

type ResourceOrchestrator added in v2.1.0

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

ResourceOrchestrator manages the lifecycle of multiple typed resource managers

func NewResourceOrchestrator added in v2.1.0

func NewResourceOrchestrator() (*ResourceOrchestrator, error)

NewResourceOrchestrator creates a new resource orchestrator

func (*ResourceOrchestrator) Start added in v2.1.0

func (ro *ResourceOrchestrator) Start(ctx context.Context) error

Start executes all resource operations to bring resources up

func (*ResourceOrchestrator) Stop added in v2.1.0

func (ro *ResourceOrchestrator) Stop(ctx context.Context) error

Stop removes all resources managed by this orchestrator

type ResourceRecord added in v2.1.0

type ResourceRecord[TConfig any, TState any] struct {
	State  TState  `json:"state"`
	Config TConfig `json:"config"`
}

ResourceRecord represents the business data for a managed resource (config + runtime state)

type ResourceRegistry added in v2.1.0

type ResourceRegistry struct {
	Entries []PersistentResourceEntry `json:"entries"`
}

ResourceRegistry manages persistent storage of resource state

func LoadResourceRegistry added in v2.1.0

func LoadResourceRegistry() (*ResourceRegistry, error)

LoadResourceRegistry loads the resource registry from persistent storage

func (*ResourceRegistry) Add added in v2.1.0

Add adds a persistent resource entry to the registry

func (*ResourceRegistry) Remove added in v2.1.0

Remove removes a persistent resource entry from the registry

func (*ResourceRegistry) Save added in v2.1.0

func (rr *ResourceRegistry) Save() error

Save persists the resource registry to storage

Jump to

Keyboard shortcuts

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