pipeline

package
v1.8.17 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	AppsDeploymentGVK                      = appsv1.SchemeGroupVersion.WithKind("Deployment")
	CoreServiceGVK                         = corev1.SchemeGroupVersion.WithKind("Service")
	CoreNamespace                          = corev1.SchemeGroupVersion.WithKind("Namespace")
	CMCertificateGVK                       = cmv1.SchemeGroupVersion.WithKind(cmv1.CertificateKind)
	NetIngressGVK                          = netv1.SchemeGroupVersion.WithKind("Ingress")
	AutoscalingvHorizontalPodAutoscalerGVK = autoscalingv2.SchemeGroupVersion.WithKind("HorizontalPodAutoscaler")
	BatchCronJobGVK                        = batchv1.SchemeGroupVersion.WithKind("CronJob")
	MonitoringServiceMonitorGVK            = monitorv1.SchemeGroupVersion.WithKind(monitorv1.ServiceMonitorsKind)
	VPAVerticalPodAutoscalerGVK            = vpav1.SchemeGroupVersion.WithKind("VerticalPodAutoscaler")
	CoreServiceAccount                     = corev1.SchemeGroupVersion.WithKind("ServiceAccount")
)

Functions

func IsOwnedBy

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

func ListExisting added in v1.8.16

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

func ListNew added in v1.8.16

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

func ObjectsEquals

func ObjectsEquals(o1, o2 client.Object) bool

Types

type CapsulePipeline added in v1.8.1

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

func NewCapsulePipeline added in v1.8.1

func NewCapsulePipeline(
	cc client.Client,
	cr client.Reader,
	config *configv1alpha1.OperatorConfig,
	scheme *runtime.Scheme,
	logger logr.Logger,
) *CapsulePipeline

func (*CapsulePipeline) AddStep added in v1.8.1

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

func (*CapsulePipeline) RunCapsule added in v1.8.1

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

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, opts ...CapsuleRequestOption) CapsuleRequest

type CapsuleRequestOption

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

func WithAdditionalResources added in v1.7.4

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

func WithDryRun

func WithDryRun() CapsuleRequestOption

func WithForce

func WithForce() CapsuleRequestOption

type Change added in v1.8.1

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

type ExecutableRequest added in v1.8.2

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

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

func NewProjectEnvironmentRequest added in v1.8.15

func NewProjectEnvironmentRequest(
	c client.Client,
	reader client.Reader,
	config *configv1alpha1.OperatorConfig,
	scheme *runtime.Scheme,
	logger logr.Logger,
	projectEnv *v1alpha2.ProjectEnvironment,
) ExecutableRequest[ProjectEnvironmentRequest]

type Object

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

type ObjectKey added in v1.8.1

type ObjectKey struct {
	client.ObjectKey
	schema.GroupVersionKind
}

func (ObjectKey) MarshalLog added in v1.8.1

func (ok ObjectKey) MarshalLog() interface{}

func (ObjectKey) String added in v1.8.1

func (ok ObjectKey) String() string

type ObjectsEqual

type ObjectsEqual func(o1, o2 client.Object) bool

type OutputObject

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

type ProjectEnvironmentRequest added in v1.8.15

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

type Request added in v1.8.1

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(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(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 behaviour 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) succeds
	// 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(obj client.Object) 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(obj client.Object) ([]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(obj client.Object) ([]client.Object, error)
}

type RequestBase added in v1.8.1

type RequestBase struct {
	RequestDeps
	RequestState
	Strategies RequestStrategies
}

func NewRequestBase added in v1.8.1

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

func (*RequestBase) Commit added in v1.8.1

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

func (*RequestBase) Delete added in v1.8.1

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

func (*RequestBase) GetExisting added in v1.8.1

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

func (*RequestBase) GetNew added in v1.8.1

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

func (*RequestBase) ListExisting added in v1.8.16

func (r *RequestBase) ListExisting(obj client.Object) ([]client.Object, error)

func (*RequestBase) ListNew added in v1.8.16

func (r *RequestBase) ListNew(obj client.Object) ([]client.Object, error)

func (*RequestBase) PrepareRequest added in v1.8.1

func (r *RequestBase) PrepareRequest() *Result

func (*RequestBase) Reader added in v1.8.1

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

func (*RequestBase) Scheme added in v1.8.1

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

func (*RequestBase) Set added in v1.8.1

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

type RequestDeps added in v1.8.1

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

type RequestState added in v1.8.1

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

TODO Make generic over object?

type RequestStrategies added in v1.8.1

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(obj client.Object) (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 added in v1.8.1

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
}

Jump to

Keyboard shortcuts

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