store

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package store persists the control plane's durable state: the jobs a user submitted and the container runs launched for them. The store is the source of truth — on a controller restart the reconciler rebuilds its view from here, so a crash never loses track of a running job.

Secrets are never stored. A job's spec is persisted with its ${VAR} placeholders intact; resolved secret values live only in process memory (see the controller) and in the launched container's environment.

Index

Constants

View Source
const (
	KindYAML = "yaml"
	KindSDK  = "sdk"
)

KindSDK / KindYAML are the Job.Kind values.

Variables

This section is empty.

Functions

This section is empty.

Types

type DesiredState

type DesiredState string

DesiredState is the operator's intent for a job, independent of what any individual container is doing right now. The reconciler drives the actual runs toward this.

const (
	// DesiredRunning: the job should have a live container.
	DesiredRunning DesiredState = "running"
	// DesiredStopped: the job should be stopped and stay stopped.
	DesiredStopped DesiredState = "stopped"
)

type Job

type Job struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	// Kind is "yaml" (a declarative workflow) or "sdk" (a prebuilt Go
	// pipeline image). Empty is treated as "yaml".
	Kind string `json:"kind,omitempty"`
	Spec string `json:"spec"` // workflow doc (yaml) or manifest (sdk), secrets unresolved
	// Image is the container image to run. Empty for yaml jobs (the
	// controller's generic runner image is used); set for sdk jobs.
	Image    string                     `json:"image,omitempty"`
	Delivery compiler.DeliveryGuarantee `json:"delivery"`
	Graph    compiler.PipelineGraph     `json:"graph"`
	Desired  DesiredState               `json:"desiredState"`
	Created  time.Time                  `json:"createdAt"`
	Updated  time.Time                  `json:"updatedAt"`
}

Job is a submitted workflow and the operator's intent for it.

type Run

type Run struct {
	ID          string     `json:"id"`
	JobID       string     `json:"jobId"`
	ContainerID string     `json:"containerId,omitempty"`
	HostPort    int        `json:"hostPort,omitempty"` // mapped control-surface port
	Phase       string     `json:"phase"`
	Attempt     int        `json:"attempt"`
	Error       string     `json:"error,omitempty"`
	Started     time.Time  `json:"startedAt"`
	Stopped     *time.Time `json:"stoppedAt,omitempty"`
}

Run is one container launched for a job. A job accumulates runs across restarts; at most one is non-terminal at a time.

type SQLite

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

SQLite is a Store backed by a single SQLite database file (or ":memory:"). modernc's driver is pure Go, so the controller image needs no CGO.

func OpenSQLite

func OpenSQLite(path string) (*SQLite, error)

OpenSQLite opens (creating if needed) the database at path and applies the schema. Use ":memory:" for tests.

func (*SQLite) ActiveRuns

func (s *SQLite) ActiveRuns() ([]*Run, error)

func (*SQLite) AppendTransition

func (s *SQLite) AppendTransition(t *Transition) error

func (*SQLite) Close

func (s *SQLite) Close() error

func (*SQLite) CreateJob

func (s *SQLite) CreateJob(j *Job) error

func (*SQLite) CreateRun

func (s *SQLite) CreateRun(r *Run) error

func (*SQLite) DeleteJob

func (s *SQLite) DeleteJob(id string) error

func (*SQLite) GetJob

func (s *SQLite) GetJob(id string) (*Job, error)

func (*SQLite) GetRun

func (s *SQLite) GetRun(id string) (*Run, error)

func (*SQLite) LatestRun

func (s *SQLite) LatestRun(jobID string) (*Run, error)

func (*SQLite) ListJobs

func (s *SQLite) ListJobs() ([]*Job, error)

func (*SQLite) ListRuns

func (s *SQLite) ListRuns(jobID string) ([]*Run, error)

func (*SQLite) ListTransitions

func (s *SQLite) ListTransitions(jobID string) ([]*Transition, error)

func (*SQLite) SetDesired

func (s *SQLite) SetDesired(jobID string, d DesiredState) error

func (*SQLite) UpdateRun

func (s *SQLite) UpdateRun(r *Run) error

type Store

type Store interface {
	CreateJob(j *Job) error
	GetJob(id string) (*Job, error)
	ListJobs() ([]*Job, error)
	SetDesired(jobID string, d DesiredState) error
	DeleteJob(id string) error

	CreateRun(r *Run) error
	UpdateRun(r *Run) error
	GetRun(id string) (*Run, error)
	// LatestRun returns the most recent run for a job, or (nil, nil) if
	// the job has never been launched.
	LatestRun(jobID string) (*Run, error)
	ListRuns(jobID string) ([]*Run, error)
	// ActiveRuns returns every non-terminal run across all jobs — the set
	// the reconciler must watch.
	ActiveRuns() ([]*Run, error)

	AppendTransition(t *Transition) error
	ListTransitions(jobID string) ([]*Transition, error)

	Close() error
}

Store is the persistence contract. Implementations must be safe for concurrent use (the API server and reconciler share one).

type Transition

type Transition struct {
	ID     int64     `json:"id"`
	JobID  string    `json:"jobId"`
	RunID  string    `json:"runId,omitempty"`
	From   string    `json:"from"`
	To     string    `json:"to"`
	Reason string    `json:"reason,omitempty"`
	At     time.Time `json:"at"`
}

Transition is an append-only lifecycle audit record.

Jump to

Keyboard shortcuts

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