Documentation ¶
Overview ¶
Package reconciler contatins types and methods that can be used in controller reconciliation logic. It depends on controller-runtime, so the use of kubebuilder or operator-sdk is highly recommended.
Index ¶
- Constants
- func SetupWithDynamicTypeWatches(r ReconcilerWithTypeTracker, bldr *builder.Builder) error
- func WithFinalizationFunc(fn func(context.Context, client.Client) error) finalizationFunction
- func WithFinalizer(f string) finalizer
- func WithInMemoryInitializationFunc(fn func(context.Context, client.Client, client.Object) error) inMemoryinitializationFunction
- func WithInitializationFunc(fn func(context.Context, client.Client, client.Object) error) initializationFunction
- type AppStatus
- type Health
- type ObjectWithAppStatus
- type Reconciler
- func (r *Reconciler) BuildTypeTracker(ctrl controller.Controller)
- func (r *Reconciler) FilteredEventHandler(ol client.ObjectList, filter func(event client.Object, o client.Object) bool, ...) handler.EventHandler
- func (r *Reconciler) Logger(ctx context.Context, keysAndValues ...interface{}) (context.Context, logr.Logger)
- func (r *Reconciler) ManageResourceLifecycle(ctx context.Context, req reconcile.Request, obj client.Object, ...) Result
- func (r *Reconciler) ReconcileOwnedResources(ctx context.Context, owner client.Object, list []resource.TemplateInterface) Result
- func (r *Reconciler) ReconcileStatus(ctx context.Context, instance ObjectWithAppStatus, ...) Result
- func (r *Reconciler) WithLogger(logger logr.Logger) *Reconciler
- type ReconcilerWithTypeTracker
- type Result
- type UnimplementedDeploymentStatus
- type UnimplementedStatefulSetStatus
- func (u *UnimplementedStatefulSetStatus) GetStatefulSetStatus(types.NamespacedName) *appsv1.StatefulSetStatus
- func (u *UnimplementedStatefulSetStatus) GetStatefulSets() []types.NamespacedName
- func (u *UnimplementedStatefulSetStatus) SetStatefulSetStatus(types.NamespacedName, *appsv1.StatefulSetStatus)
Constants ¶
const ( ContinueAction action = "Continue" ReturnAction action = "Return" ReturnAndRequeueAction action = "ReturnAndRequeue" )
Variables ¶
This section is empty.
Functions ¶
func SetupWithDynamicTypeWatches ¶ added in v0.5.0
func SetupWithDynamicTypeWatches(r ReconcilerWithTypeTracker, bldr *builder.Builder) error
SetupWithDynamicTypeWatches is a helper to build a controller that can watch resource types dynamically. It is typically used within the "SetupWithManager" function. Example usage:
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error { return reconciler.SetupWithDynamicTypeWatches(r, ctrl.NewControllerManagedBy(mgr). For(&v1alpha1.Test{}). // add any other watches here Watches(...}.Watches(...), ) }
func WithFinalizationFunc ¶ added in v0.4.0
WithFinalizationFunc can be used to provide functions that will be run on object finalization. A Finalizer must be set for these functions to be called.
func WithFinalizer ¶ added in v0.4.0
func WithFinalizer(f string) finalizer
WithFinalizer can be used to provide a finalizer string that the resource will be initialized with For finalization logic to be run before objet deletion, a finalizar must be passed.
func WithInMemoryInitializationFunc ¶ added in v0.4.0
func WithInMemoryInitializationFunc(fn func(context.Context, client.Client, client.Object) error) inMemoryinitializationFunction
WithInitializationFunc can be used to provide functions that run resource initialization, like for example applying defaults or labels to the resource.
func WithInitializationFunc ¶ added in v0.4.0
func WithInitializationFunc(fn func(context.Context, client.Client, client.Object) error) initializationFunction
WithInitializationFunc can be used to provide functions that run resource initialization, like for example applying defaults or labels to the resource.
Types ¶
type AppStatus ¶ added in v0.4.0
type AppStatus interface { // GetHealth(types.NamespacedName) Health // SetHealth(types.NamespacedName, Health) GetDeploymentStatus(types.NamespacedName) *appsv1.DeploymentStatus SetDeploymentStatus(types.NamespacedName, *appsv1.DeploymentStatus) GetStatefulSetStatus(types.NamespacedName) *appsv1.StatefulSetStatus SetStatefulSetStatus(types.NamespacedName, *appsv1.StatefulSetStatus) }
AppStatus is an interface describing a custom resource with an status that can be reconciled by the reconciler
type ObjectWithAppStatus ¶ added in v0.4.0
ObjectWithAppStatus is an interface that implements both client.Object and AppStatus
type Reconciler ¶
type Reconciler struct { client.Client Log logr.Logger Scheme *runtime.Scheme // contains filtered or unexported fields }
Reconciler computes a list of resources that it needs to keep in place
func NewFromManager ¶
func NewFromManager(mgr manager.Manager) *Reconciler
NewFromManager returns a new Reconciler from a controller-runtime manager.Manager
func (*Reconciler) BuildTypeTracker ¶ added in v0.5.0
func (r *Reconciler) BuildTypeTracker(ctrl controller.Controller)
BuildTypeTracker passes the controller to the reconciler so watches can be added dynamically
func (*Reconciler) FilteredEventHandler ¶ added in v0.4.0
func (r *Reconciler) FilteredEventHandler(ol client.ObjectList, filter func(event client.Object, o client.Object) bool, logger logr.Logger) handler.EventHandler
FilteredEventHandler returns an EventHandler for the specific client.ObjectList passed as parameter. It will produce reconcile requests for any client.Object of the given type that returns true when passed to the filter function. If the filter function is "nil" all the listed object will receive a reconcile request. The filter function receives both the object that generated the event and the object that might need to be reconciled in response to that event. Depending on whether it returns true or false the reconciler request will be generated or not.
In the following example, a watch for Secret resources which match the name "secret" is added to the reconciler. The watch will generate reconmcile requests for v1alpha1.Test resources any time a Secret with name "secret" is created/uddated/deleted
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&v1alpha1.Test{}). Watches(&source.Kind{Type: &corev1.Secret{TypeMeta: metav1.TypeMeta{Kind: "Secret"}}}, r.FilteredEventHandler( &v1alpha1.TestList{}, func(event, o client.Object) bool { return event.GetName() == "secret" }, r.Log)). Complete(r) }
func (*Reconciler) Logger ¶ added in v0.4.0
func (r *Reconciler) Logger(ctx context.Context, keysAndValues ...interface{}) (context.Context, logr.Logger)
Logger returns the Reconciler logger and a copy of the context that also includes the logger inside to pass it around easily.
func (*Reconciler) ManageResourceLifecycle ¶ added in v0.4.0
func (r *Reconciler) ManageResourceLifecycle(ctx context.Context, req reconcile.Request, obj client.Object, opts ...lifecycleOption) Result
ManageResourceLifecycle manages the lifecycle of the resource, from initialization to finalization and deletion. The behaviour can be modified depending on the options passed to the function:
- WithInitializationFunc(...): pass a function with initialization logic for the custom resource. The function will be executed and if changes to the custom resource are detected the resource will be updated. It can be used to set default values on the custom resource. Can be used more than once.
- WithInMemoryInitializationFunc(...): pass a function with initialization logic to the custom resource. If the custom resource is modified in nay way, the changes won't be persisted in the API server and will only have effect within the reconcile loop. Can be used more than once.
- WithFinalizer(...): passes a string that will be configured as a resource finalizar, ensuring that the custom resource has the finalizer in place, updating it if required.
- WithFinalizationFunc(...): pass finalization functions that will be run when the custom resource is being deleted. Only works ifa finalizer is also passed, otherwise the custom resource will be immediately deleted and the functions won't run. Can be used more than once.
func (*Reconciler) ReconcileOwnedResources ¶
func (r *Reconciler) ReconcileOwnedResources(ctx context.Context, owner client.Object, list []resource.TemplateInterface) Result
ReconcileOwnedResources handles generalized resource reconcile logic for a controller:
- Takes a list of templates and calls resource.CreateOrUpdate on each one of them. The templates need to implement the resource.TemplateInterface interface. Users can take advantage of the generic resource.Template[T] struct that the resource package provides, which already implements the resource.TemplateInterface.
- Each template is added to the list of managed resources if resource.CreateOrUpdate returns with no error
- If the resource pruner is enabled any resource owned by the custom resource not present in the list of managed resources is deleted. The resource pruner must be enabled in the global config (see package config) and also not explicitly disabled in the resource by the '<annotations-domain>/prune: true/false' annotation.
func (*Reconciler) ReconcileStatus ¶ added in v0.2.0
func (r *Reconciler) ReconcileStatus(ctx context.Context, instance ObjectWithAppStatus, deployments, statefulsets []types.NamespacedName, mutators ...func() bool) Result
ReconcileStatus can reconcile the status of a custom resource when the resource implements the ObjectWithAppStatus interface. It is specifically targeted for the status of custom resources that deploy Deployments/StatefulSets, as it can aggregate the status of those into the status of the custom resource. It also accepts functions with signature "func() bool" that can reconcile the status of the custom resource and return whether update is required or not.
func (*Reconciler) WithLogger ¶ added in v0.4.0
func (r *Reconciler) WithLogger(logger logr.Logger) *Reconciler
WithLogger sets the Reconciler logger
type ReconcilerWithTypeTracker ¶ added in v0.5.0
type ReconcilerWithTypeTracker interface { reconcile.Reconciler BuildTypeTracker(ctrl controller.Controller) }
ReconcilerWithTypeTracker is a reconciler with a TypeTracker The type tracker is used by the "resource pruner" and "dynamic watches" features
type Result ¶ added in v0.4.0
func (Result) ShouldReturn ¶ added in v0.4.0
type UnimplementedDeploymentStatus ¶ added in v0.4.0
type UnimplementedDeploymentStatus struct{}
UnimplementedDeploymentStatus type can be used for resources that doesn't use Deployments
func (*UnimplementedDeploymentStatus) GetDeploymentStatus ¶ added in v0.4.0
func (u *UnimplementedDeploymentStatus) GetDeploymentStatus(types.NamespacedName) *appsv1.DeploymentStatus
func (*UnimplementedDeploymentStatus) GetDeployments ¶ added in v0.4.0
func (u *UnimplementedDeploymentStatus) GetDeployments() []types.NamespacedName
func (*UnimplementedDeploymentStatus) SetDeploymentStatus ¶ added in v0.4.0
func (u *UnimplementedDeploymentStatus) SetDeploymentStatus(types.NamespacedName, *appsv1.DeploymentStatus)
type UnimplementedStatefulSetStatus ¶ added in v0.4.0
type UnimplementedStatefulSetStatus struct{}
UnimplementedStatefulSetStatus type can be used for resources that doesn't use StatefulSets
func (*UnimplementedStatefulSetStatus) GetStatefulSetStatus ¶ added in v0.4.0
func (u *UnimplementedStatefulSetStatus) GetStatefulSetStatus(types.NamespacedName) *appsv1.StatefulSetStatus
func (*UnimplementedStatefulSetStatus) GetStatefulSets ¶ added in v0.4.0
func (u *UnimplementedStatefulSetStatus) GetStatefulSets() []types.NamespacedName
func (*UnimplementedStatefulSetStatus) SetStatefulSetStatus ¶ added in v0.4.0
func (u *UnimplementedStatefulSetStatus) SetStatefulSetStatus(types.NamespacedName, *appsv1.StatefulSetStatus)