v1

package
v0.0.0-...-9d92eb5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package v1 contains helpers to build a composite controller reconciler. It defines a Controller interface which provides methods required for reconciling a composite controller. It also provides an implementation of the Reconcile method that can be embedded in a controller to satisfy the controller-runtime's Reconciler interface.

Index

Constants

This section is empty.

Variables

View Source
var DefaultInitCondition conditionsv1.Condition = conditionsv1.Condition{
	Type:    conditionsv1.ConditionProgressing,
	Status:  corev1.ConditionTrue,
	Reason:  "Initializing",
	Message: "Component initializing",
}

DefaultInitCondition is the default init condition used by the composite reconciler to add to the status of a new resource.

Functions

func AddFinalizer

func AddFinalizer(obj metav1.Object, name string)

AddFinalizer adds the named finalizer to obj, if it isn't already present.

func DefaultIsUninitialized

func DefaultIsUninitialized(conditions []conditionsv1.Condition) bool

DefaultIsUninitialized performs uninitialized check on an object based on the status conditions.

func HasFinalizer

func HasFinalizer(obj metav1.Object, name string) bool

HasFinalizer returns true if obj has the named finalizer.

func OwnerReferenceFromObject

func OwnerReferenceFromObject(obj client.Object) metav1.OwnerReference

OwnerReferenceFromObject creates an owner reference with the given object.

func RemoveFinalizer

func RemoveFinalizer(obj metav1.Object, name string)

RemoveFinalizer removes the named finalizer from obj, if it's present.

Types

type CleanupStrategy

type CleanupStrategy int

CleanupStrategy is the resource cleanup strategy used by the reconciler.

const (
	// OwnerReferenceCleanup depends on k8s garbage collector. All the child
	// objects of a parent are added with a reference of the parent object.
	// When the parent object gets deleted, all the child objects are garbage
	// collected.
	OwnerReferenceCleanup CleanupStrategy = iota
	// FinalizerCleanup allows using custom cleanup logic. When this strategy
	// is set, a finalizer is added to the parent object to avoid accidental
	// deletion of the object. When the object is marked for deletion with a
	// deletion timestamp, the custom cleanup code is executed to delete all
	// the child objects. Once all custom cleanup code finished, the finalizer
	// from the parent object is removed and the parent object is allowed to be
	// deleted.
	FinalizerCleanup
)

type CompositeReconciler

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

CompositeReconciler defines a composite reconciler.

func (*CompositeReconciler) Init

Init initializes the CompositeReconciler for a given Object with the given options.

func (*CompositeReconciler) Reconcile

func (c *CompositeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, reterr error)

Reconcile implements the composite controller reconciliation.

type CompositeReconcilerOptions

type CompositeReconcilerOptions func(*CompositeReconciler)

CompositeReconcilerOptions is used to configure CompositeReconciler.

func WithCleanupStrategy

func WithCleanupStrategy(cleanupStrat CleanupStrategy) CompositeReconcilerOptions

WithCleanupStrategy sets the CleanupStrategy of the CompositeReconciler.

func WithClient

WithClient sets the k8s client in the reconciler.

func WithController

func WithController(ctrlr Controller) CompositeReconcilerOptions

WithController sets the Controller in a CompositeReconciler.

func WithFinalizer

func WithFinalizer(finalizer string) CompositeReconcilerOptions

WithFinalizer sets the name of the finalizer used by the CompositeReconciler.

func WithInitCondition

func WithInitCondition(cndn conditionsv1.Condition) CompositeReconcilerOptions

WithInitCondition sets the initial status Condition to be used by the CompositeReconciler on a resource object.

func WithLogger

func WithLogger(log logr.Logger) CompositeReconcilerOptions

WithLogger sets the Logger in a CompositeReconciler.

func WithName

func WithName(name string) CompositeReconcilerOptions

WithName sets the name of the CompositeReconciler.

func WithPrototype

func WithPrototype(obj client.Object) CompositeReconcilerOptions

WithPrototype sets a prototype of the object that's reconciled.

func WithScheme

func WithScheme(scheme *runtime.Scheme) CompositeReconcilerOptions

WithScheme sets the runtime Scheme of the CompositeReconciler.

type Controller

type Controller interface {
	// Apply default values to the primary object spec. Use this in case a
	// defaulting webhook has not been deployed.
	Default(context.Context, client.Object)

	// Validate validates the primary object spec before it's created. It
	// ensures that all required fields are present and valid. Use this in case
	// a validating webhook has not been deployed.
	Validate(context.Context, client.Object) error

	// Initialize sets the provided initialization condition on the object
	// status. This helps some operations in Operation() know about the
	// creation phase and run initialization specific operations.
	Initialize(context.Context, client.Object, conditionsv1.Condition) error

	// UpdateStatus queries the status of the child objects and based on them,
	// sets the status of the primary object instance. It doesn't save the
	// updated object in the API. API update is done in PatchStatus() after
	// collecting and comparing all the status updates. This is also called
	// when cleanup is in progress. This should be able to remove previous
	// status related to child objects that have been terminated.
	UpdateStatus(context.Context, client.Object) error

	// Operate runs the core operation of the controller that ensures that
	// the child objects or the other objects and configurations in the
	// environment are in the desired state. It should be able to update any
	// existing resources or create one, if there's a configuration drift,
	// based on the type of objects.
	// The returned result is the returned reconcile result.
	Operate(context.Context, client.Object) (result ctrl.Result, err error)

	// Cleanup runs the custom cleanup operation to delete or undo the changes
	// made by the controller. This can be empty for controllers that use owner
	// reference based garbage collection for cleanup. For controllers with
	// custom cleanup requirement, the cleanup logic can be defined here.
	Cleanup(context.Context, client.Object) (result ctrl.Result, err error)
}

Controller is the controller interface that must be implemented by a composite controller. It provides methods required for reconciling a composite controller.

Jump to

Keyboard shortcuts

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