controllers

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Description: This file defines a common Reconciler implementation for kubernetes controllers that use ResourceStatus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxRequeueInterval

func MaxRequeueInterval() time.Duration

MaxRequeueInterval is used when either the CRD or CR have issues or if there are permission issues to read CR or update its status. It is also used as a max retry interval, after too many retries. In this case we want controllers to keep trying, but very slow (waiting for the fix to be pushed).

func MinRequeueInterval

func MinRequeueInterval() time.Duration

MinRequeueInterval is the min duration between tries on same CR. This is exposed for testing.

Types

type Handler

type Handler interface {
	// CreateResource is called to create an empty CRD resource object.
	CreateResource() resources.Resource
	// Reconcile is called to perform the actual reconciliation of CRD, when its spec changes
	Reconcile(
		ctx context.Context,
		log logrus.FieldLogger,
		in resources.Resource) ReconcileResult
	// EndReconcile is called when reconciliation finishes. It is always called, even if reconcile fails before calling
	// the Handler's Reconcile method.
	// This method is for logging and metrics, ReconcileResult is intentionally passed by value so there is no point modifying it.
	EndReconcile(ctx context.Context, log logrus.FieldLogger, rr ReconcileResult)
}

Handler provides the actual per-CRD implementation of the reconciler.

type ReconcileResult

type ReconcileResult struct {
	// Skipped indicates that reconciler has decided to skip this CR.
	Skipped bool
	// ReconcileErr is set when reconciliation fails, or when status changes fail.
	ReconcileErr error
	// PropagateErr is set when reconciler error needs to be reported as a failure to the controller and retry immedaitely
	// (rather than in intervals).
	PropagateErr bool
	// ControllerRes is the result to be returned back to the controller's infra.
	ControllerRes ctrl.Result
	// contains filtered or unexported fields
}

reconcileResult holds the outcome of the reconciler

type Reconciler

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

Reconciler is a controller for CRD resources.

func NewReconciler

func NewReconciler(cl client.Client, kind, version string, log logrus.FieldLogger, handler Handler) *Reconciler

NewReconciler creates a new reconciler instance.

func (*Reconciler) Client

func (r *Reconciler) Client() client.Client

Client returns the client to access k8s API.

func (*Reconciler) Kind

func (r *Reconciler) Kind() string

Kind returns the CRD's kind

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile is invoked when controller receives resource spec.

func (*Reconciler) Setup

func (r *Reconciler) Setup(mgr ctrl.Manager) error

Setup registers this Reconciler instance as a controller to process target resources.

func (*Reconciler) Version

func (r *Reconciler) Version() string

Version returns the CRD's version served by this reconciler

Jump to

Keyboard shortcuts

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