model

package
v0.0.0-...-32bb601 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package model defines the core data types shared across the engine and providers: the declarative Object, references between objects, and observed Status.

Index

Constants

View Source
const (
	PhaseReady       = "Ready"
	PhaseReconciling = "Reconciling"
	PhaseBlocked     = "Blocked"
	PhaseError       = "Error"
	PhaseDeleted     = "Deleted"
	PhaseUnknown     = "Unknown"
)

Phase constants describe the high-level lifecycle state of an object.

Variables

This section is empty.

Functions

func HashSpec

func HashSpec(m map[string]any) string

HashSpec returns a stable sha256 of a spec map. Marshalling via encoding/json with sorted map keys gives a deterministic representation.

func Marshal

func Marshal(o Object) ([]byte, error)

Marshal renders an Object back to canonical YAML.

func ShortHash

func ShortHash(m map[string]any) string

ShortHash returns the first 8 hex chars of HashSpec, suitable for content-addressed resource names (e.g. immutable Swarm secrets/configs).

func ShortSummary

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

ShortSummary returns a compact human summary considering phase, drift and sync.

Types

type Condition

type Condition struct {
	Type               string `json:"type"`
	Status             string `json:"status"` // True|False|Unknown
	Reason             string `json:"reason,omitempty"`
	Message            string `json:"message,omitempty"`
	LastTransitionTime string `json:"lastTransitionTime,omitempty"`
}

Condition is a single status condition, keyed by Type and updated in place.

type DriftStatus

type DriftStatus struct {
	Drifted bool           `json:"drifted"`
	Details map[string]any `json:"details,omitempty"`
}

DriftStatus tracks observed-vs-desired divergence.

type Metadata

type Metadata struct {
	Name      string            `json:"name" yaml:"name"`
	Namespace string            `json:"namespace,omitempty" yaml:"namespace,omitempty"`
	Labels    map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
}

Metadata holds the manifest metadata block.

type Object

type Object struct {
	APIVersion string            `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
	Kind       string            `json:"kind" yaml:"kind"`
	Name       string            `json:"-" yaml:"-"`
	Namespace  string            `json:"-" yaml:"-"`
	Labels     map[string]string `json:"-" yaml:"-"`
	Provider   string            `json:"provider,omitempty" yaml:"provider,omitempty"`
	Target     string            `json:"target,omitempty" yaml:"target,omitempty"`
	DependsOn  []Ref             `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`
	Spec       map[string]any    `json:"spec,omitempty" yaml:"spec,omitempty"`
	Source     string            `json:"-" yaml:"-"`

	// Metadata is the raw metadata block; Name/Namespace/Labels are hoisted from it.
	Metadata Metadata `json:"metadata" yaml:"metadata"`
}

Object is a single declarative resource parsed from a manifest. The Spec is left unstructured; each provider decodes it into a typed spec.

func ParseYAML

func ParseYAML(data []byte) ([]Object, error)

ParseYAML parses a (possibly multi-document) YAML stream into Objects. Documents with no Kind are skipped (e.g. empty docs from "---" separators).

func (Object) Key

func (o Object) Key() string

Key returns the canonical "kind/name" key for this object.

func (Object) Ref

func (o Object) Ref() Ref

Ref returns a Ref pointing at this object.

type Ref

type Ref struct {
	Kind     string `json:"kind" yaml:"kind"`
	Name     string `json:"name" yaml:"name"`
	Optional bool   `json:"optional,omitempty" yaml:"optional,omitempty"`
}

Ref identifies another object by kind and name.

func (Ref) Key

func (r Ref) Key() string

Key returns the canonical "kind/name" key (kind lower-cased) for a Ref.

type Status

type Status struct {
	ObservedGeneration int64          `json:"observedGeneration"`
	LastReconciled     time.Time      `json:"lastReconciled,omitempty"`
	LastChange         time.Time      `json:"lastChange,omitempty"`
	Phase              string         `json:"phase,omitempty"`
	Summary            string         `json:"summary,omitempty"`
	Conditions         []Condition    `json:"conditions,omitempty"`
	Sync               SyncStatus     `json:"sync"`
	Drift              DriftStatus    `json:"drift"`
	Extra              map[string]any `json:"extra,omitempty"`
}

Status is the operator-observed state of an object, persisted for the API/CLI.

func (*Status) SetCondition

func (s *Status) SetCondition(c Condition)

SetCondition inserts or updates a condition keyed by Type. LastTransitionTime is only refreshed when the Status value actually changes, matching Kubernetes semantics and keeping the slice bounded.

type SyncStatus

type SyncStatus struct {
	DesiredHash     string `json:"desiredHash,omitempty"`
	LastAppliedHash string `json:"lastAppliedHash,omitempty"`
	OutOfSync       bool   `json:"outOfSync"`
}

SyncStatus tracks desired-vs-applied hashes.

Jump to

Keyboard shortcuts

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