core

package
v0.0.1-prerelease9 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a particular resource cannot be located
	ErrNotFound = errors.New("not found")
	// ErrAlreadyExists is returned when an attempt is made to create a resource
	// which already exists
	ErrAlreadyExists = errors.New("already exists")
	// ErrNoChange is returned when an update produced zero changes
	ErrNoChange = errors.New("update produced no change")
)

Functions

func HasAllLabels

func HasAllLabels(labels map[string]string) containers.Option[PhaseOptions]

HasAllLabels causes a call to Phases to list any phase which mataches all the provided labels.

func HasLabel

func HasLabel(k, v string) containers.Option[PhaseOptions]

HasLabel causes a call to Phases to list any phase with the matching label paid k and v.

func HasName

func HasName(name string) containers.Option[PhaseOptions]

HasName causes a call to Phases to list any phase with the matching name.

func IsPhase

func IsPhase(p Phase) containers.Option[PhaseOptions]

IsPhase causes a call to Phases to list specifically the provided phase p.

func WithKind

func WithKind(kind string) containers.Option[EdgeOptions]

Types

type Descriptor

type Descriptor struct {
	Kind     string   `json:"kind"`
	Pipeline string   `json:"pipeline"`
	Metadata Metadata `json:"metadata"`
}

Descriptor is a type which describes a Phase

func (Descriptor) String

func (d Descriptor) String() string

type Edge

type Edge interface {
	Kind() string
	From() Descriptor
	To() Descriptor
	Perform(context.Context) (*Result, error)
	CanPerform(context.Context) (bool, error)
}

Edge represents an edge between two phases. Edges have have their own kind which identifies their Perform behaviour.

type EdgeOptions

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

type Metadata

type Metadata struct {
	Name        string            `json:"name"`
	Labels      map[string]string `json:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

Metadata contains the unique information used to identify a named resource instance in a particular phase.

type Phase

type Phase interface {
	Descriptor() Descriptor
	Get(context.Context) (Resource, error)
	History(context.Context) ([]State, error)
}

Phase is the core interface for resource sourcing and management. These types can be registered on pipelines and can depend upon on another for promotion.

type PhaseOptions

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

PhaseOptions scopes a call to get phases from a pipeline.

func (*PhaseOptions) Matches

func (p *PhaseOptions) Matches(phase Phase) bool

Matches returns true if the provided Phase matches the phase options set of conditions. An empty set of conditions always returns true.

type Pipeline

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

Pipeline is a collection of phases for a given resource type R. It implements the core.Phase interface and is scoped to a single Resource implementation.

func NewPipeline

func NewPipeline(meta Metadata) *Pipeline

NewPipeline constructs and configures a new instance of *ResourcePipeline[R]

func (*Pipeline) AddEdge

func (p *Pipeline) AddEdge(e Edge) error

AddEdge adds an edge to a Pipeline.

func (*Pipeline) AddPhase

func (p *Pipeline) AddPhase(phase Phase) error

AddPhase will add the provided resource phase to the pipeline along with configuring any dependent promotion source phases if configured to do so.

func (*Pipeline) Edges

func (p *Pipeline) Edges(o ...containers.Option[EdgeOptions]) iter.Seq[Edge]

Edges returns all edges as a sequence

func (*Pipeline) EdgesFrom

func (p *Pipeline) EdgesFrom() map[string]map[string]Edge

EdgesFrom returns the set of edges as a map of "from" phase names to map of "to" phase names to the edge instance itself.

func (*Pipeline) Metadata

func (p *Pipeline) Metadata() Metadata

Metadata returns the metadata assocated with the Pipelines (name and labels).

func (*Pipeline) PhaseByName

func (p *Pipeline) PhaseByName(name string) (Phase, error)

PhaseByName returns the Phase (if it exists) with a matching name.

func (*Pipeline) Phases

func (p *Pipeline) Phases(opts ...containers.Option[PhaseOptions]) iter.Seq[Phase]

Phases lists all phases in the pipeline with optional predicates.

type Resource

type Resource interface {
	Digest() (string, error)
}

Resource is an instance of a resource in a phase. Primarilly, it exposes a Digest method used to produce a hash digest of the resource instances current state.

type ResourceWithAnnotations

type ResourceWithAnnotations interface {
	Resource
	Annotations() map[string]string
}

ResourceWithAnnotations is a resource with additional annotations

type Result

type Result struct {
	Annotations map[string]string `json:"annotations"`
}

Result is a type that carries annotations relating to the result of calling Perform on an edge.

type RollbackPhase

type RollbackPhase interface {
	Phase
	// Rollback performs a rollback operation to a previous state identified
	// by a version uuid.
	Rollback(context.Context, uuid.UUID) (*Result, error)
}

RollbackPhase is a phase which can be rolled back to a previous version.

type State

type State struct {
	Version     uuid.UUID         `json:"version,omitempty"`
	Resource    Resource          `json:"resource,omitempty"`
	Digest      string            `json:"digest,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
	RecordedAt  time.Time         `json:"recorded_at,omitempty"`
}

State contains a snapshot of a resource version at a point in history

type TriggerableEdge

type TriggerableEdge interface {
	Edge
	RunTriggers(context.Context) error
}

TriggerableEdge is an edge that has an additional method RunTriggers. This method should schedule any necessary dependencies needed to automate calling perform on the respectibe edge (e.g. start background schedules).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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