result

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReconcileResult

type ReconcileResult interface {
	// Completed indicates that the current iteration of the reconciliation loop is complete, and the top-level
	// Reconcile() method should return [ReconcileResult.Output] to the controller runtime.
	//
	// This returns true for a [Done] or terminal [Error] (where the output will stop the entire reconciliation loop);
	// and for a [RequeueSoon] or regular [Error] (where the output will trigger a retry).
	//
	// This returns false for a [Continue].
	Completed() bool
	// Output converts this result into a format that the main Reconcile() method can return to the controller runtime.
	//
	// Calling this method on a [Continue] will panic.
	Output() (ctrl.Result, error)
	// IsError indicates whether this result is an [Error].
	IsError() bool
	// IsRequeue indicates whether this result is a [RequeueSoon].
	IsRequeue() bool
	// IsDone indicates whether this result is a [Done].
	IsDone() bool
	// GetError returns the wrapped error if the result is an [Error], otherwise it returns nil.
	GetError() error
}

ReconcileResult represents the result of a step in the reconciliation process.

We typically split the top-level Reconcile() method of a controller into multiple sub-functions. Each of these functions uses ReconcileResult to communicate to its caller how the current iteration should proceed. There are 4 possible implementations: Continue, Done, RequeueSoon, and Error.

The idiomatic way to handle a ReconcileResult in an intermediary sub-function is:

if recResult := callStep1(); recResult.Completed() {
   // Global success, requeue or error: stop what we're doing and propagate up
   return recResult
}
// Otherwise, proceed with the next step(s)
if recResult := callStep2(); recResult.Completed() {
   // etc...

The idiomatic way to handle a ReconcileResult in the top-level Reconcile() method is:

recResult := callSomeSubmethod()
// Possibly inspect the result (e.g. to set an error field in the status)
return recResult.Output()

func Continue

func Continue() ReconcileResult

Continue indicates that the current step in the reconciliation is done. The caller should proceed with the next step.

func Done

func Done() ReconcileResult

Done indicates that the entire reconciliation loop was successful. The caller should skip the next steps (if any), and propagate the result up the stack. This will eventually reach the top-level Reconcile() method, which should stop the reconciliation.

func Error

func Error(e error) ReconcileResult

Error indicates that the current step in the reconciliation has failed. The caller should skip the next steps (if any), and propagate the result up the stack. This will eventually reach the top-level Reconcile() method, which should return the error to the controller runtime.

If the argument is wrapped with reconcile.TerminalError, the reconciliation loop will stop; otherwise, it will be retried with exponential backoff.

func RequeueSoon

func RequeueSoon(after time.Duration) ReconcileResult

RequeueSoon indicates that the current step in the reconciliation requires a requeue after a certain amount of time. The caller should skip the next steps (if any), and propagate the result up the stack. This will eventually reach the top-level Reconcile() method, which should schedule a requeue with the given delay.

Jump to

Keyboard shortcuts

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