extension

package
v0.118.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HookResult

type HookResult struct {
	// ReconcileResult will be returned by the reconcile function if no error occurs.
	ReconcileResult reconcile.Result

	// If set to true, reconciliation will be aborted with returning ReconcileResult after the current execution.
	AbortReconcile bool
}

HookResult represents the result of a reconciliation extension hook.

func AggregateHookResults

func AggregateHookResults(hrs ...*HookResult) *HookResult

AggregateHookResults aggregates multiple hook results into a single one. - If all hook results are nil, nil will be returned. - If there is exactly one non-nil hook result, a copy of it will be returned. - Otherwise the non-nil hook results will be aggregated as follows:

  • AbortReconcile and ReconcileResult.Requeue are ORed, so if one of them is true for any of the hook results, it will be true in the return value.
  • ReconcileResult.RequeueAfter is aggregated using a minimum function, so the return value's field will be set to the smallest value greater than zero that was set among the given hook results.
  • If ReconcileResult.Requeue is true, RequeueAfter will be set to zero to ensure an immediate reconcile.

func AggregateHookResultsWithInvertedAbortPriority

func AggregateHookResultsWithInvertedAbortPriority(hrs ...*HookResult) *HookResult

AggregateHookResultsWithInvertedAbortPriority works exactly like AggregateHookResults with the exception that the AbortReconcile values are ANDed instead of ORed. This is required for a few special cases where setting the value to 'false' is meant to enforce continuation.

func (*HookResult) DeepCopy

func (hr *HookResult) DeepCopy() *HookResult

type HookType

type HookType string
const (
	// Called at the beginning of the reconciliation.
	// Because this hook is called before the deploy item is fetched from the cluster, deploy item and target will always be nil in the hook function call.
	StartHook HookType = "Start"

	// Called after the responsibility has been checked, but before it is evaluated.
	// Beware: a non-nil hook result will override the result of the responsibility check - if something is returned, only HookResult.AbortReconcile decides whether to continue or abor the reconciliation.
	DuringResponsibilityCheckHook HookType = "DuringResponsibilityCheck" // called after the responsibility has been checked but before the reconcile is aborted, in case the deployer is not responsible

	// Called after it has been determined that the deployer is responsible for the deploy item.
	AfterResponsibilityCheckHook HookType = "AfterResponsibilityCheck"

	// Called while it is evaluated whether a reconcile is necessary.
	// Beware: a non-nil hook result with HookResult.AbortReconcile set to 'false' will enforce a full reconcile, even if it is not required by the default logic.
	//   However, a result with AbortReconcile set to 'true' will not abort the reconcile, if it is required by the default logic.
	//   The reason for this is that by the time the hook is called, the deploy item has already been altered (phase, lastReconcileTime, ...) and aborting the reconciliation would lead to an inconsistent state.
	ShouldReconcileHook HookType = "ShouldReconcile"

	// Called if the deploy item is to be aborted due to the abort operation annotation.
	// Beware: Aborting the reconciliation at this point might leave the deploy item in an inconsistent state and is discouraged.
	BeforeAbortHook HookType = "BeforeAbort"

	// Called if the deploy item is to be force-reconciled due to the force reconcile operation annotation.
	// Beware: Aborting the reconciliation at this point might leave the deploy item in an inconsistent state and is discouraged.
	BeforeForceReconcileHook HookType = "BeforeForceReconcile"

	// Called if the deploy item is to be deleted.
	// Beware: Aborting the reconciliation at this point might leave the deploy item in an inconsistent state and is discouraged.
	BeforeDeleteHook HookType = "BeforeDelete"

	// Called if a "normal" reconcile of the deploy item is about to happen.
	// This is the case if a reconcile is required and the deploy item is not aborted, force-reconciled, or deleted.
	// Beware: Aborting the reconciliation at this point might leave the deploy item in an inconsistent state and is discouraged.
	BeforeReconcileHook HookType = "BeforeReconcile"

	// Called before any of abortion, deletion, and (force-)reconciliation.
	// This will always be called if the reconciliation has not been aborted before or during the ShouldReconcile check.
	// Beware: Aborting the reconciliation at this point might leave the deploy item in an inconsistent state and is discouraged.
	BeforeAnyReconcileHook HookType = "BeforeAnyReconcile"

	// Called after a successful reconciliation.
	// This will always be called at the end of reconciliation, unless an error has occurred or the reconciliation has been aborted
	//   during the responsibility or ShouldReconcile check or by one of the earlier hooks.
	EndHook HookType = "End"
)

type ReconcileExtensionHook

type ReconcileExtensionHook func(context.Context, *lsv1alpha1.DeployItem, *lsv1alpha1.Target, HookType) (*HookResult, error)

ReconcileExtensionHook represents a function which will be called when the hook is executed.

type ReconcileExtensionHookSetup

type ReconcileExtensionHookSetup struct {
	Hook      ReconcileExtensionHook
	HookTypes []HookType
}

ReconcileExtensionHookSetup can be used to couple a hook function with the hooks it is meant for.

type ReconcileExtensionHooks

type ReconcileExtensionHooks map[HookType][]ReconcileExtensionHook

ReconcileExtensionHooks maps hook types to a list of hook functions.

func (ReconcileExtensionHooks) ExecuteHooks

ExecuteHooks executes all hooks of a given type in the order they are specified in. The results of all executed hooks are aggregated using the AggregateHookResults function, except for

DuringResponsibilityCheck and ShouldReconcile hooks, where AggregateHookResultsWithInvertedAbortPriority is used instead.

An error is returned if one of the hooks returns an error or if an unknown hook type is given.

func (ReconcileExtensionHooks) RegisterHook

RegisterHook appends the given hook function to the list of hook functions for all given hook types. It returns the ReconcileExtensionHooks object it is called on for chaining.

func (ReconcileExtensionHooks) RegisterHookSetup

RegisterHookSetup is a wrapper for RegisterHook which uses a ReconcileExtensionHookSetup object instead of a hook function and types. It returns the ReconcileExtensionHooks object it is called on for chaining.

Jump to

Keyboard shortcuts

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