qtransform

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package qtransform implements a generic controller which transforms Input resources into Output resources based on QController.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControllerOption

type ControllerOption func(*ControllerOptions)

ControllerOption is an option for QTransformController.

func WithConcurrency

func WithConcurrency(n uint) ControllerOption

WithConcurrency sets the maximum number of concurrent reconciles.

func WithExtraMappedDestroyReadyInput

func WithExtraMappedDestroyReadyInput[I generic.ResourceWithRD](mapFunc MapperFuncGeneric[I]) ControllerOption

WithExtraMappedDestroyReadyInput adds an extra mapped destroy-ready input to the controller.

func WithExtraMappedInput

func WithExtraMappedInput[I generic.ResourceWithRD](mapFunc MapperFuncGeneric[I]) ControllerOption

WithExtraMappedInput adds an extra mapped input to the controller.

func WithExtraMappedInputKind

func WithExtraMappedInputKind[I generic.ResourceWithRD](mapFunc MapperFuncGeneric[I], inputKind controller.InputKind) ControllerOption

WithExtraMappedInputKind adds an extra input with the given kind to the controller.

func WithExtraOutputs

func WithExtraOutputs(outputs ...controller.Output) ControllerOption

WithExtraOutputs adds extra outputs to the controller.

func WithIgnoreTeardownUntil

func WithIgnoreTeardownUntil(finalizers ...resource.Finalizer) ControllerOption

WithIgnoreTeardownUntil ignores input resource teardown until the input resource has only mentioned finalizers left.

This allows to keep output resources not destroyed until other controllers remove their finalizers.

Implicitly the controller will also ignore its own finalizer, so if the list is empty, the controller will wait to be the last one not done with the resource.

func WithOutputKind

func WithOutputKind(kind controller.OutputKind) ControllerOption

WithOutputKind sets main output resource kind.

type ControllerOptions

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

ControllerOptions configures QTransformController.

type MapperFuncGeneric

type MapperFuncGeneric[I generic.ResourceWithRD] func(context.Context, *zap.Logger, controller.QRuntime, I) ([]resource.Pointer, error)

MapperFuncGeneric is a generic version of mapperFunc.

func MapperNone

func MapperNone[I generic.ResourceWithRD]() MapperFuncGeneric[I]

MapperNone is a mapper that returns no pointers.

func MapperSameID

MapperSameID is a mapper that returns the same namespace ID as the input resource, but uses output resource type.

type QController

type QController[Input generic.ResourceWithRD, Output generic.ResourceWithRD] struct {
	generic.NamedController
	// contains filtered or unexported fields
}

QController provides a generic implementation of a QController which implements controller transforming Input resources into Output resources.

Controller supports full flow with finalizers:

  • if other controllers set finalizers on this controller outputs, this controller will handle this and wait for the finalizers to be fully removed before attempting to delete the output.
  • the finalizer on inputs will only be removed when matching output is destroyed.

func NewQController

func NewQController[Input generic.ResourceWithRD, Output generic.ResourceWithRD](
	settings Settings[Input, Output],
	opts ...ControllerOption,
) *QController[Input, Output]

NewQController creates a new QTransformController.

func (*QController[Input, Output]) MapInput

func (ctrl *QController[Input, Output]) MapInput(ctx context.Context, logger *zap.Logger, r controller.QRuntime, ptr resource.Pointer) ([]resource.Pointer, error)

MapInput implements controller.QController interface.

func (*QController[Input, Output]) Reconcile

func (ctrl *QController[Input, Output]) Reconcile(ctx context.Context, logger *zap.Logger, r controller.QRuntime, ptr resource.Pointer) error

Reconcile implements controller.QController interface.

func (*QController[Input, Output]) Settings

func (ctrl *QController[Input, Output]) Settings() controller.QSettings

Settings implements controller.QController interface.

type Settings

type Settings[Input generic.ResourceWithRD, Output generic.ResourceWithRD] struct {
	// Name is the name of the controller.
	Name string
	// MapMetadataFunc defines a function which creates new empty Output based on Input.
	//
	// Only Output metadata is important, the spec is ignored.
	MapMetadataFunc func(Input) Output
	// MapMetadataOptionalFunc acts like a MapMetadataFunc, but returns optional Output.
	//
	// If the Output is not present, the controller will skip the input.
	MapMetadataOptionalFunc func(Input) optional.Optional[Output]
	// UnmapMetadataFunc defines a function which creates new empty Input based on Output.
	//
	// Only Input metadata is important, the spec is ignored.
	UnmapMetadataFunc func(Output) Input
	// TransformFunc should modify Output based on Input and any additional resources fetched via Reader.
	//
	// If the TransformFunc fails, the item will be requeued according to QController rules.
	TransformFunc func(context.Context, controller.Reader, *zap.Logger, Input, Output) error
	// TransformExtraOutputFunc acts like TransformFunc, but used with extra outputs.
	//
	// If the controller produces additional outputs, this function should be used instead of TransformFunc.
	// The only difference is that Reader+Writer is passed as the argument.
	TransformExtraOutputFunc func(context.Context, controller.ReaderWriter, *zap.Logger, Input, Output) error
	// FinalizerRemovalFunc is called when Input is being torn down.
	//
	// This function defines the pre-checks to be done before finalizer on the input can be removed.
	// If this function returns an error, the finalizer won't be removed and this item will be requeued.
	FinalizerRemovalFunc func(context.Context, controller.Reader, *zap.Logger, Input) error
	// FinalizerRemovalExtraOutputFunc is called when Input is being torn down when Extra Outputs are enabled.
	//
	// If the controller produces additional outputs, this function should be used instead of FinalizerRemovalFunc.
	// The only difference is that Reader+Writer is passed as the argument.
	FinalizerRemovalExtraOutputFunc func(context.Context, controller.ReaderWriter, *zap.Logger, Input) error
}

Settings configures the controller.

type SkipReconcileTag

type SkipReconcileTag struct{}

SkipReconcileTag is used to tag errors when reconciliation should be skipped without an error.

It's useful when next reconcile event should bring things into order.

Jump to

Keyboard shortcuts

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