reconcilers

package
v0.0.0-...-83b13a5 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexControllersOfType

func IndexControllersOfType(mgr ctrl.Manager, field string, owner, ownee runtime.Object, scheme *runtime.Scheme) error

func MergeMaps

func MergeMaps(maps ...map[string]string) map[string]string

MergeMaps flattens a sequence of maps into a single map. Keys in latter maps overwrite previous keys. None of the arguments are mutated.

func RetrieveValue

func RetrieveValue(ctx context.Context, key StashKey) interface{}

func StashValue

func StashValue(ctx context.Context, key StashKey, value interface{})

func WithStash

func WithStash(ctx context.Context) context.Context

Types

type Builder

type Builder = builder.Builder

type ChildReconciler

type ChildReconciler struct {
	// ParentType of resource to reconcile
	ParentType apis.Object
	// ChildType is the resource being created/updated/deleted by the
	// reconciler. For example, a parent Deployment would have a ReplicaSet as a
	// child.
	ChildType apis.Object
	// ChildListType is the listing type for the child type. For example,
	// PodList is the list type for Pod
	ChildListType runtime.Object

	// Setup performs initialization on the manager and builder this reconciler
	// will run with. It's common to setup field indexes and watch resources.
	//
	// +optional
	Setup func(mgr ctrl.Manager, bldr *builder.Builder) error

	// DesiredChild returns the desired child object for the given parent
	// object, or nil if the child should not exist.
	//
	// Expected function signature:
	//     func(parent apis.Object) (apis.Object, error)
	//     func(ctx context.Context, parent apis.Object) (apis.Object, error)
	DesiredChild interface{}

	// ReflectChildStatusOnParent updates the parent object's status with values
	// from the child. Select types of error are passed, including:
	// - apierrs.IsConflict
	//
	// Expected function signature:
	//     func(parent, child apis.Object, err error)
	ReflectChildStatusOnParent interface{}

	// HarmonizeImmutableFields allows fields that are immutable on the current
	// object to be copied to the desired object in order to avoid creating
	// updates which are guaranteed to fail.
	//
	// Expected function signature:
	//     func(current, desired apis.Object)
	//
	// +optional
	HarmonizeImmutableFields interface{}

	// MergeBeforeUpdate copies desired fields on to the current object before
	// calling update. Typically fields to copy are the Spec, Labels and
	// Annotations.
	//
	// Expected function signature:
	//     func(current, desired apis.Object)
	MergeBeforeUpdate interface{}

	// SemanticEquals compares two child resources returning true if there is a
	// meaningful difference that should trigger an update.
	//
	// Expected function signature:
	//     func(a1, a2 apis.Object) bool
	SemanticEquals interface{}

	// Sanitize is called with an object before logging the value. Any value may
	// be returned. A meaningful subset of the resource is typically returned,
	// like the Spec.
	//
	// Expected function signature:
	//     func(child apis.Object) interface{}
	//
	// +optional
	Sanitize interface{}

	Config

	// IndexField is used to index objects of the child's type based on their
	// controlling owner. This field needs to be unique within the manager.
	IndexField string
}

ChildReconciler is a sub reconciler that manages a single child resource for a parent. The reconciler will ensure that exactly one child will match the desired state by: - creating a child if none exists - updating an existing child - removing an unneeded child - removing extra children

The flow for each reconciliation request is: - DesiredChild - if child is desired:

  • HarmonizeImmutableFields (optional)
  • SemanticEquals
  • MergeBeforeUpdate

- ReflectChildStatusOnParent

During setup, the child resource type is registered to watch for changes. A field indexer is configured for the owner on the IndexField.

func (*ChildReconciler) Reconcile

func (r *ChildReconciler) Reconcile(ctx context.Context, parent apis.Object) (ctrl.Result, error)

func (*ChildReconciler) SetupWithManager

func (r *ChildReconciler) SetupWithManager(mgr ctrl.Manager, bldr *builder.Builder) error

type Config

type Config struct {
	client.Client
	APIReader client.Reader
	Recorder  record.EventRecorder
	Log       logr.Logger
	Scheme    *runtime.Scheme
	Tracker   tracker.Tracker
}

Config holds common resources for controllers. The configuration may be passed to sub-reconcilers.

type Kind

type Kind = source.Kind

type Manager

type Manager = manager.Manager

type ParentReconciler

type ParentReconciler struct {
	// Type of resource to reconcile
	Type runtime.Object

	// SubReconcilers are called in order for each reconciler request. If a sub
	// reconciler errs, further sub reconcilers are skipped.
	SubReconcilers []SubReconciler

	Config
}

ParentReconciler is a controller-runtime reconciler that reconciles a given existing resource. The ParentType resource is fetched for the reconciler request and passed in turn to each SubReconciler. Finally, the reconciled resource's status is compared with the original status, updating the API server if needed.

func (*ParentReconciler) Reconcile

func (r *ParentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)

func (*ParentReconciler) SetupWithManager

func (r *ParentReconciler) SetupWithManager(mgr ctrl.Manager) error

type StashKey

type StashKey string

type SubReconciler

type SubReconciler interface {
	SetupWithManager(mgr ctrl.Manager, bldr *builder.Builder) error
	Reconcile(ctx context.Context, parent apis.Object) (ctrl.Result, error)
}

SubReconciler are participants in a larger reconciler request. The resource being reconciled is passed directly to the sub reconciler. The resource's status can be mutated to reflect the current state.

type SyncReconciler

type SyncReconciler struct {
	// Setup performs initialization on the manager and builder this reconciler
	// will run with. It's common to setup field indexes and watch resources.
	//
	// +optional
	Setup func(mgr ctrl.Manager, bldr *builder.Builder) error

	// Sync does whatever work is necessary for the reconciler
	//
	// Expected function signature:
	//     func(ctx context.Context, parent apis.Object) error
	//     func(ctx context.Context, parent apis.Object) (ctrl.Result, error)
	Sync interface{}

	Config
}

SyncReconciler is a sub reconciler for custom reconciliation logic. No behavior is defined directly.

func (*SyncReconciler) Reconcile

func (r *SyncReconciler) Reconcile(ctx context.Context, parent apis.Object) (ctrl.Result, error)

func (*SyncReconciler) SetupWithManager

func (r *SyncReconciler) SetupWithManager(mgr ctrl.Manager, bldr *builder.Builder) error

Jump to

Keyboard shortcuts

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