runtime

package
v0.0.0-...-f6f694c Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package runtime contains the logic for reconciling a directory of manifests with a store and status.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeSpec

func DecodeSpec[T any](m map[string]any) (T, error)

DecodeSpec decodes a map to a struct of type T. It uses the mapstructure library.

func HashSpec

func HashSpec(m map[string]any) string

HashSpec hashes the spec of a resource.

func NewCondition

func NewCondition(t, status, reason, msg string) map[string]any

NewCondition creates a new condition map.

func ParseYAML

func ParseYAML(data []byte) ([]api.Unstructured, error)

ParseYAML parses YAML data into a slice of api.Unstructured objects. It uses the yaml library.

func ReconcileDirAndPersist

func ReconcileDirAndPersist(ctx context.Context, scheme *Scheme, dir string, store *Store, status *StatusStore) error

ReconcileDirAndPersist applies manifests AND persists canonical manifests and status. It also prunes resources that are tracked in the Store but no longer present in `dir`.

func Register

func Register[T api.Spec](s *Scheme, kind string, bind func(api.Unstructured) (T, error), ctrl api.Controller[T])

Register registers a controller and binder for a given kind, where the spec is of type T.

func ShortSummary

func ShortSummary(phase string, drifted, outOfSync bool) string

ShortSummary returns a short summary of the status phase, considering drift and out-of-sync status.

Types

type ListItem

type ListItem struct{ Kind, Name, Path string }

ListItem lists all resources in the store.

type Plan

type Plan struct {
	Order []api.Unstructured // topo-ordered resources
}

Plan constructs a DAG using explicit dependsOn edges plus implicit waves.

func BuildPlan

func BuildPlan(objs []api.Unstructured) (Plan, error)

BuildPlan constructs a DAG using explicit dependsOn edges plus implicit waves. Returns a topologically-sorted order (stable per-kind within same wave when possible).

type Scheme

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

Scheme is a registry of controllers and binders.

func NewScheme

func NewScheme() *Scheme

NewScheme creates a new Scheme with no registered controllers or binders.

func (*Scheme) Delete

func (s *Scheme) Delete(ctx context.Context, kind string, meta api.ResourceMeta) (map[string]any, error)

Delete deletes a resource using the registered controller and binder.

func (*Scheme) Diff

func (s *Scheme) Diff(ctx context.Context, u api.Unstructured, observed map[string]any) (bool, map[string]any, error)

Diff diffs a resource using the registered controller and binder.

func (*Scheme) Observe

func (s *Scheme) Observe(ctx context.Context, kind string, meta api.ResourceMeta) (map[string]any, error)

Observe observes a resource using the registered controller and binder.

func (*Scheme) Reconcile

func (s *Scheme) Reconcile(ctx context.Context, u api.Unstructured) (map[string]any, error)

Reconcile reconciles a resource using the registered controller and binder.

func (*Scheme) Register

func (s *Scheme) Register(kind string, bind binder, ctrl controllerAny)

Register registers a controller and binder for a given kind.

func (*Scheme) SupportedKinds

func (s *Scheme) SupportedKinds() []string

SupportedKinds returns a list of all supported kinds.

type Status

type Status struct {
	ObservedGeneration int64            `json:"observedGeneration"`
	LastReconciled     time.Time        `json:"lastReconciled,omitempty"`
	Phase              string           `json:"phase,omitempty"` // Ready|Reconciling|Degraded|Error|Deleted|Unknown
	Conditions         []map[string]any `json:"conditions,omitempty"`
	Summary            string           `json:"summary,omitempty"`
	Sync               struct {
		DesiredHash     string `json:"desiredHash,omitempty"`
		LastAppliedHash string `json:"lastAppliedHash,omitempty"`
		OutOfSync       bool   `json:"outOfSync"`
	} `json:"sync"`
	Drift struct {
		Drifted bool           `json:"drifted"`
		Details map[string]any `json:"details,omitempty"`
	} `json:"drift"`
	Extra map[string]any `json:"extra,omitempty"`
}

Status is a representation of the status of a resource.

type StatusStore

type StatusStore struct {
	Root string
}

StatusStore is a store for resource statuses.

func NewStatusStore

func NewStatusStore(root string) *StatusStore

NewStatusStore creates a new StatusStore with the specified root directory.

func (*StatusStore) Delete

func (s *StatusStore) Delete(kind, name string) error

Delete deletes the status of a resource from the store.

func (*StatusStore) Ensure

func (s *StatusStore) Ensure(kind string) error

Ensure ensures that the directory for the given kind exists.

func (*StatusStore) Load

func (s *StatusStore) Load(kind, name string) (Status, error)

Load loads the status of a resource from the store.

func (*StatusStore) Save

func (s *StatusStore) Save(kind, name string, st Status) error

Save saves the status of a resource to the store.

type Store

type Store struct{ Root string }

Store is a store for resource manifests.

func NewStore

func NewStore(root string) *Store

NewStore creates a new Store with the specified root directory.

func (*Store) Delete

func (s *Store) Delete(kind, name string) (string, error)

Delete deletes a resource manifest from the store.

func (*Store) EnsureKindDir

func (s *Store) EnsureKindDir(kind string) error

EnsureKindDir ensures that the directory for the given kind exists.

func (*Store) List

func (s *Store) List(kindOpt string) ([]ListItem, error)

List lists all resources in the store.

func (*Store) Load

func (s *Store) Load(kind, name string) (api.Unstructured, string, error)

Load loads a resource manifest from the store.

func (*Store) Save

func (s *Store) Save(u api.Unstructured) (string, error)

Save saves a resource manifest to the store.

Jump to

Keyboard shortcuts

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