transform

package
v0.3.0-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package transform provides a generic implementation of controller which transforms resources A into resources B.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller provides a generic implementation of a controller 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.
  • if this controller is configured to set finalizers on its inputs, the finalizer will only be removed when matching output is destroyed.

func NewController

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

NewController creates a new TransformController.

func (*Controller[Input, Output]) Inputs

func (ctrl *Controller[Input, Output]) Inputs() []controller.Input

Inputs implements controller.Controller interface.

func (*Controller[Input, Output]) Outputs

func (ctrl *Controller[Input, Output]) Outputs() []controller.Output

Outputs implements controller.Controller interface.

func (*Controller[Input, Output]) Run

func (ctrl *Controller[Input, Output]) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error

Run implements controller.Controller interface.

type ControllerOption

type ControllerOption func(*ControllerOptions)

ControllerOption is an option for TransformController.

func WithExtraInputs

func WithExtraInputs(inputs ...controller.Input) ControllerOption

WithExtraInputs adds extra inputs to the controller.

func WithInputFinalizers

func WithInputFinalizers() ControllerOption

WithInputFinalizers enables setting finalizers on controller inputs.

The finalizer on input will be removed only when matching output is destroyed.

func WithInputListOptions

func WithInputListOptions(opts ...state.ListOption) ControllerOption

WithInputListOptions adds an filter on input resource list.

E.g. query only resources with specific labels.

type ControllerOptions

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

ControllerOptions configures TransformController.

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
	// TransformFunc should modify Output based on Input and any additional resources fetched via Reader.
	//
	// If TransformFunc returns error tagged with SkipReconcileTag, the error is ignored and the controller will
	// call reconcile on next event.
	// If TransformFunc returns any other error, controller will fail.
	TransformFunc func(context.Context, controller.Reader, *zap.Logger, Input, Output) error
	// FinalizerRemovalFunc is called when Input is being torn down while Input Finalizers are enabled.
	//
	// 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 controller will fail.
	// If FinalizerRemoveFunc returns an error tagged with SkipReconcileTag, the error is ignored and the controller will
	// retry on next reconcile event.
	FinalizerRemovalFunc func(context.Context, controller.Reader, *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