operator

package
v0.0.0-...-dac86b4 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventAdded    = "ADDED"
	EventModified = "MODIFIED"
	EventDeleted  = "DELETED"
)

Event type constants.

View Source
const (
	PhasePending    = "Pending"
	PhaseRunning    = "Running"
	PhaseFailed     = "Failed"
	PhaseTerminated = "Terminated"
)

Phase constants for WorkflowDefinitionStatus.

Variables

This section is empty.

Functions

func GenerateCRD

func GenerateCRD() string

GenerateCRD returns the CRD YAML for WorkflowDefinition. This is the Kubernetes CustomResourceDefinition that should be applied to a cluster before creating WorkflowDefinition resources.

Types

type Controller

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

Controller simulates a K8s controller watch loop. In production, this would use client-go's informer framework with shared informers and work queues. This implementation provides the same logical flow for testing and local development.

func NewController

func NewController(reconciler *Reconciler, logger *slog.Logger) *Controller

NewController creates a new Controller backed by the given Reconciler.

func (*Controller) Enqueue

func (c *Controller) Enqueue(event ControllerEvent)

Enqueue adds an event to the controller's work queue. Events are processed in FIFO order by the event loop. If the queue is full the event is dropped and a warning is logged.

func (*Controller) IsRunning

func (c *Controller) IsRunning() bool

IsRunning returns whether the controller's event loop is active.

func (*Controller) Start

func (c *Controller) Start(ctx context.Context) error

Start begins the controller's event processing loop. It blocks until the context is cancelled or Stop is called. The loop drains the event queue and dispatches each event to the reconciler.

func (*Controller) Stop

func (c *Controller) Stop() error

Stop signals the controller to shut down and waits for the event loop to finish draining.

type ControllerEvent

type ControllerEvent struct {
	Type       string // "ADDED", "MODIFIED", "DELETED"
	Definition *WorkflowDefinition
}

ControllerEvent represents a watch event for a WorkflowDefinition.

type DeployedWorkflow

type DeployedWorkflow struct {
	Definition *WorkflowDefinition
	Status     string
	StartedAt  time.Time
	StoppedAt  *time.Time
	Error      string
}

DeployedWorkflow tracks runtime state for a reconciled workflow.

type ObjectMeta

type ObjectMeta 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"`
	Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
}

ObjectMeta contains standard Kubernetes object metadata.

type ReconcileResult

type ReconcileResult struct {
	Action  string // "created", "updated", "deleted", "unchanged", "error"
	Message string
}

ReconcileResult describes the outcome of a single reconciliation.

type Reconciler

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

Reconciler handles the reconciliation loop for WorkflowDefinition CRDs. It compares the desired state (spec) with the actual state (deployed) and takes corrective action to converge the two.

func NewReconciler

func NewReconciler(logger *slog.Logger) *Reconciler

NewReconciler creates a new Reconciler.

func (*Reconciler) Apply

func (r *Reconciler) Apply(ctx context.Context, def *WorkflowDefinition) error

Apply creates or updates a WorkflowDefinition. This is the public entry point for applying a definition outside the reconciliation loop.

func (*Reconciler) Delete

func (r *Reconciler) Delete(_ context.Context, name, namespace string) error

Delete removes a WorkflowDefinition and its deployed state.

func (*Reconciler) Get

func (r *Reconciler) Get(name, namespace string) (*WorkflowDefinition, error)

Get returns the current WorkflowDefinition for the given name and namespace.

func (*Reconciler) List

func (r *Reconciler) List(namespace string) []*WorkflowDefinition

List returns all WorkflowDefinitions in the given namespace. If namespace is empty, all definitions across all namespaces are returned.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, def *WorkflowDefinition) (*ReconcileResult, error)

Reconcile is the main reconciliation entry point. It compares the desired definition against the currently deployed state and takes the appropriate action: create, update, or mark unchanged.

type ResourceSpec

type ResourceSpec struct {
	CPURequest    string `json:"cpuRequest,omitempty" yaml:"cpuRequest,omitempty"`
	CPULimit      string `json:"cpuLimit,omitempty" yaml:"cpuLimit,omitempty"`
	MemoryRequest string `json:"memoryRequest,omitempty" yaml:"memoryRequest,omitempty"`
	MemoryLimit   string `json:"memoryLimit,omitempty" yaml:"memoryLimit,omitempty"`
}

ResourceSpec defines CPU and memory resource requests and limits.

type WorkflowDefinition

type WorkflowDefinition struct {
	APIVersion string                   `json:"apiVersion" yaml:"apiVersion"`
	Kind       string                   `json:"kind" yaml:"kind"`
	Metadata   ObjectMeta               `json:"metadata" yaml:"metadata"`
	Spec       WorkflowDefinitionSpec   `json:"spec" yaml:"spec"`
	Status     WorkflowDefinitionStatus `json:"status" yaml:"status"`
}

WorkflowDefinition is the CRD for a deployed workflow.

type WorkflowDefinitionSpec

type WorkflowDefinitionSpec struct {
	Name       string       `json:"name" yaml:"name"`
	Version    int          `json:"version" yaml:"version"`
	ConfigYAML string       `json:"configYAML" yaml:"configYAML"`
	Replicas   int          `json:"replicas,omitempty" yaml:"replicas,omitempty"`
	Resources  ResourceSpec `json:"resources,omitempty" yaml:"resources,omitempty"`
	Env        string       `json:"env,omitempty" yaml:"env,omitempty"` // dev/staging/prod
}

WorkflowDefinitionSpec defines a workflow to be deployed.

type WorkflowDefinitionStatus

type WorkflowDefinitionStatus struct {
	Phase           string    `json:"phase"`         // Pending, Running, Failed, Terminated
	Replicas        int       `json:"replicas"`      // desired replicas from spec
	ReadyReplicas   int       `json:"readyReplicas"` // replicas currently ready
	Message         string    `json:"message,omitempty"`
	LastTransition  time.Time `json:"lastTransition"`
	ObservedVersion int       `json:"observedVersion"` // last reconciled spec version
}

WorkflowDefinitionStatus reflects the observed state of a WorkflowDefinition.

Jump to

Keyboard shortcuts

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