pipeline

package
v1.9.6 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelOwnedByCapsule = "rig.dev/owned-by-capsule"

	AnnotationOverrideOwnership = "rig.dev/override-ownership"
	AnnotationPullSecret        = "rig.dev/pull-secret"

	LabelSharedConfig = "rig.dev/shared-config"
	LabelCapsule      = "rig.dev/capsule"
	LabelCron         = "batch.kubernets.io/cronjob"

	RigDevRolloutLabel   = "rig.dev/rollout"
	RigDevInterfaceLabel = "rig.dev/interface"

	AnnotationChecksumFiles     = "rig.dev/config-checksum-files"
	AnnotationChecksumAutoEnv   = "rig.dev/config-checksum-auto-env"
	AnnotationChecksumEnv       = "rig.dev/config-checksum-env"
	AnnotationChecksumSharedEnv = "rig.dev/config-checksum-shared-env"
)
View Source
const (
	LabelOwnedByProject = "rig.dev/owned-by-project"
)

Variables

View Source
var AppsDeploymentGVK = appsv1.SchemeGroupVersion.WithKind("Deployment")

Functions

func CreatePodAnnotations

func CreatePodAnnotations(req CapsuleRequest) map[string]string

func EnvSources

func EnvSources(refs []v1alpha2.EnvReference) []v1.EnvFromSource

func FileToVolume

func FileToVolume(f v1alpha2.File) (v1.Volume, v1.VolumeMount)

func FilesToVolumes

func FilesToVolumes(files []v1alpha2.File) ([]v1.Volume, []v1.VolumeMount)

func IsOwnedBy

func IsOwnedBy(owner metav1.Object, obj metav1.Object) bool

func ListConvert

func ListConvert[T client.Object](objects []client.Object) ([]T, error)

func ListExisting

func ListExisting[T client.Object](r Request, obj T) ([]T, error)

func ListNew

func ListNew[T client.Object](r Request, obj T) ([]T, error)

func ObjectsEquals

func ObjectsEquals(o1, o2 client.Object, scheme *runtime.Scheme) (bool, error)

Types

type CapsulePipeline

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

func NewCapsulePipeline

func NewCapsulePipeline(
	config *configv1alpha1.OperatorConfig,
	scheme *runtime.Scheme,
	vm scheme.VersionMapper,
	logger logr.Logger,
) *CapsulePipeline

func (*CapsulePipeline) AddStep

func (p *CapsulePipeline) AddStep(step Step[CapsuleRequest])

func (*CapsulePipeline) DeleteCapsule

func (p *CapsulePipeline) DeleteCapsule(
	ctx context.Context,
	capsule *v1alpha2.Capsule,
	client client.Client,
	opts ...CapsuleRequestOption,
) (*Result, error)

func (*CapsulePipeline) RunCapsule

func (p *CapsulePipeline) RunCapsule(
	ctx context.Context,
	capsule *v1alpha2.Capsule,
	client client.Client,
	opts ...CapsuleRequestOption,
) (*Result, error)

func (*CapsulePipeline) Steps

func (p *CapsulePipeline) Steps() []Step[CapsuleRequest]

type CapsuleRequest

type CapsuleRequest interface {
	Request
	// Capsule returns a deepcopy of the capsule object being reconciled.
	Capsule() *v1alpha2.Capsule
	// MarkUsedObject marks the object as used by the Capsule which will be present in the Capsule's Status
	MarkUsedObject(res v1alpha2.UsedResource) error
}

CapsuleRequest contains a single reconcile request for a given capsule. It contains both the set of existing kubernetes objects owned by the capsule and the set of objects recorded to be applied after all steps in the pipeline has been executed (called 'new' objects). The set of existing objects cannot be modified (as the interface does not allow for writing to Kubernetes) but there are both read and write access to the set of new objects.

func NewCapsuleRequest

func NewCapsuleRequest(
	p *CapsulePipeline,
	capsule *v1alpha2.Capsule,
	client client.Client,
	opts ...CapsuleRequestOption,
) CapsuleRequest

type CapsuleRequestOption

type CapsuleRequestOption interface {
	// contains filtered or unexported methods
}

func WithAdditionalResources

func WithAdditionalResources(resources []*pipeline.Object) CapsuleRequestOption

func WithDryRun

func WithDryRun() CapsuleRequestOption

func WithForce

func WithForce() CapsuleRequestOption

type Change

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

type ExecutableRequest

type ExecutableRequest[T Request] interface {
	GetRequest() T
	GetBase() *RequestBase
}

TODO This ExecuteableRequest type construction is a bit messy Find a better abstraction

type Object

type Object struct {
	Current      client.Object
	New          client.Object
	Materialized client.Object
}

type ObjectKey

type ObjectKey struct {
	client.ObjectKey
	schema.GroupVersionKind
}

func (ObjectKey) MarshalLog

func (ok ObjectKey) MarshalLog() interface{}

func (ObjectKey) String

func (ok ObjectKey) String() string

type ObjectStatusCallback

type ObjectStatusCallback interface {
	UpdateStatus(namespace string, capsule string, pluginID uuid.UUID, change *apiplugin.ObjectStatusChange)
}

type OutputObject

type OutputObject struct {
	ObjectKey ObjectKey
	Object    client.Object
	State     ResourceState
}

type ProjectEnvironmentRequest

type ProjectEnvironmentRequest interface {
	Request
	// ProjectEnvironment returns a deepcopy of the capsule object being reconciled.
	ProjectEnvironment() *v1alpha2.ProjectEnvironment
}

type Request

type Request interface {
	// Scheme returns the serialization scheme used by the rig operator.
	// It contains all the types used by a Capsule.
	Scheme() *runtime.Scheme
	// Reader is a Kubernetes reader with access to the cluster the rig operator is running in.
	Reader() client.Reader
	// GetExisting populates 'obj' with a copy of the corresponding object owned by the capsule currently present in the cluster.
	// If the name of 'obj' isn't set, it defaults to the Capsule name.
	GetExisting(gk schema.GroupKind, name string) (client.Object, error)
	GetExistingInto(obj client.Object) error
	// GetNew populates 'obj' with a copy of the corresponding object owned by the capsule about to be applied.
	// If the name of 'obj' isn't set, it defaults to the Capsule name.
	GetNew(gk schema.GroupKind, name string) (client.Object, error)
	GetNewInto(obj client.Object) error
	// Set updates the object recorded to be applied.
	// If the name of 'obj' isn't set, it defaults to the Capsule name.
	Set(obj client.Object) error
	// Delete records the given object to be deleted.
	// The behavior is such that that calling req.Delete(obj) and then req.GetNew(obj)
	// returns a not-found error from GetNew.
	// If an object of the given type and name is present in the cluster, calling req.GetExisting(obj) succeeds
	// as calls to Delete (or Set) will only be applied to the cluster at the very end of the reconcilliation.
	// If the name of 'obj' isn't set, it defaults to the Capsule name.
	Delete(gk schema.GroupKind, name string) error
	// ListExisting returns a list with a copy of the objects of the corresponding type owned by the capsule and currently present in the cluster.
	// If you want a slice of typed objects, use the generic free-standing ListExisting function.
	ListExisting(gk schema.GroupKind) ([]client.Object, error)
	// ListNew returns a list with a copy of the objects of the corresponding type owned by the capsule and about to be applied.
	// If you want a slice of typed objects, use the generic free-standing ListNew function.
	ListNew(gk schema.GroupKind) ([]client.Object, error)
}

type RequestBase

type RequestBase struct {
	RequestDeps
	RequestState
	Strategies RequestStrategies
}

func NewRequestBase

func NewRequestBase(
	c client.Client,
	reader client.Reader,
	vm scheme.VersionMapper,
	config *configv1alpha1.OperatorConfig,
	scheme *runtime.Scheme,
	logger logr.Logger,
	strategies RequestStrategies,
	object client.Object,
) RequestBase

func (*RequestBase) Commit

func (r *RequestBase) Commit(ctx context.Context) (map[ObjectKey]*Change, error)

func (*RequestBase) Delete

func (r *RequestBase) Delete(gk schema.GroupKind, name string) error

func (*RequestBase) GetExisting

func (r *RequestBase) GetExisting(gk schema.GroupKind, name string) (client.Object, error)

func (*RequestBase) GetExistingInto added in v1.9.1

func (r *RequestBase) GetExistingInto(obj client.Object) error

func (*RequestBase) GetNew

func (r *RequestBase) GetNew(gk schema.GroupKind, name string) (client.Object, error)

func (*RequestBase) GetNewInto added in v1.9.1

func (r *RequestBase) GetNewInto(obj client.Object) error

func (*RequestBase) ListExisting

func (r *RequestBase) ListExisting(gk schema.GroupKind) ([]client.Object, error)

func (*RequestBase) ListNew

func (r *RequestBase) ListNew(gk schema.GroupKind) ([]client.Object, error)

func (*RequestBase) PrepareRequest

func (r *RequestBase) PrepareRequest() *Result

func (*RequestBase) Reader

func (r *RequestBase) Reader() client.Reader

func (*RequestBase) Scheme

func (r *RequestBase) Scheme() *runtime.Scheme

func (*RequestBase) Set

func (r *RequestBase) Set(obj client.Object) error

type RequestDeps

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

type RequestState

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

TODO Make generic over object?

type RequestStrategies

type RequestStrategies interface {
	// Status updating strategies
	UpdateStatusWithChanges(ctx context.Context, changes map[ObjectKey]*Change, generation int64) error
	UpdateStatusWithError(ctx context.Context, err error) error

	// Execution loop strategies
	LoadExistingObjects(ctx context.Context) error
	Prepare()
	OwnedLabel() string

	GetKey(gk schema.GroupKind, name string) (ObjectKey, error)
}

type ResourceState

type ResourceState string
const (
	ResourceStateDeleted       ResourceState = "deleted"
	ResourceStateUpdated       ResourceState = "updated"
	ResourceStateUnchanged     ResourceState = "unchanged"
	ResourceStateCreated       ResourceState = "created"
	ResourceStateFailed        ResourceState = "failed"
	ResourceStateAlreadyExists ResourceState = "alreadyExists"
	ResourceStateChangePending ResourceState = "changePending"
)

type Result

type Result struct {
	InputObjects  []client.Object
	OutputObjects []OutputObject
}

func ExecuteRequest

func ExecuteRequest[T Request](
	ctx context.Context,
	req ExecutableRequest[T],
	steps []Step[T],
	commit bool,
) (*Result, error)

type Step

type Step[T Request] interface {
	Apply(ctx context.Context, req T) error
	WatchObjectStatus(ctx context.Context, namespace, capsule string, callback ObjectStatusCallback) error
	PluginIDs() []uuid.UUID
}

Jump to

Keyboard shortcuts

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