Documentation ¶
Overview ¶
Package v1 contains helpers to build a composite controller reconciler. It defines a Controller interface which provides methods required for reconciling a composite controller. It also provides an implementation of the Reconcile method that can be embedded in a controller to satisfy the controller-runtime's Reconciler interface.
Index ¶
- Variables
- func AddFinalizer(obj metav1.Object, name string)
- func DefaultIsUninitialized(conditions []conditionsv1.Condition) bool
- func HasFinalizer(obj metav1.Object, name string) bool
- func OwnerReferenceFromObject(obj client.Object) metav1.OwnerReference
- func RemoveFinalizer(obj metav1.Object, name string)
- type CleanupStrategy
- type CompositeReconciler
- type CompositeReconcilerOptions
- func WithCleanupStrategy(cleanupStrat CleanupStrategy) CompositeReconcilerOptions
- func WithClient(cli client.Client) CompositeReconcilerOptions
- func WithController(ctrlr Controller) CompositeReconcilerOptions
- func WithFinalizer(finalizer string) CompositeReconcilerOptions
- func WithInitCondition(cndn conditionsv1.Condition) CompositeReconcilerOptions
- func WithLogger(log logr.Logger) CompositeReconcilerOptions
- func WithName(name string) CompositeReconcilerOptions
- func WithPrototype(obj client.Object) CompositeReconcilerOptions
- func WithScheme(scheme *runtime.Scheme) CompositeReconcilerOptions
- type Controller
Constants ¶
This section is empty.
Variables ¶
var DefaultInitCondition conditionsv1.Condition = conditionsv1.Condition{ Type: conditionsv1.ConditionProgressing, Status: corev1.ConditionTrue, Reason: "Initializing", Message: "Component initializing", }
DefaultInitCondition is the default init condition used by the composite reconciler to add to the status of a new resource.
Functions ¶
func AddFinalizer ¶
AddFinalizer adds the named finalizer to obj, if it isn't already present.
func DefaultIsUninitialized ¶
func DefaultIsUninitialized(conditions []conditionsv1.Condition) bool
DefaultIsUninitialized performs uninitialized check on an object based on the status conditions.
func HasFinalizer ¶
HasFinalizer returns true if obj has the named finalizer.
func OwnerReferenceFromObject ¶
func OwnerReferenceFromObject(obj client.Object) metav1.OwnerReference
OwnerReferenceFromObject creates an owner reference with the given object.
func RemoveFinalizer ¶
RemoveFinalizer removes the named finalizer from obj, if it's present.
Types ¶
type CleanupStrategy ¶
type CleanupStrategy int
CleanupStrategy is the resource cleanup strategy used by the reconciler.
const ( // OwnerReferenceCleanup depends on k8s garbage collector. All the child // objects of a parent are added with a reference of the parent object. // When the parent object gets deleted, all the child objects are garbage // collected. OwnerReferenceCleanup CleanupStrategy = iota // FinalizerCleanup allows using custom cleanup logic. When this strategy // is set, a finalizer is added to the parent object to avoid accidental // deletion of the object. When the object is marked for deletion with a // deletion timestamp, the custom cleanup code is executed to delete all // the child objects. Once all custom cleanup code finished, the finalizer // from the parent object is removed and the parent object is allowed to be // deleted. FinalizerCleanup )
type CompositeReconciler ¶
type CompositeReconciler struct {
// contains filtered or unexported fields
}
CompositeReconciler defines a composite reconciler.
func (*CompositeReconciler) Init ¶
func (c *CompositeReconciler) Init(mgr ctrl.Manager, prototype client.Object, opts ...CompositeReconcilerOptions) error
Init initializes the CompositeReconciler for a given Object with the given options.
type CompositeReconcilerOptions ¶
type CompositeReconcilerOptions func(*CompositeReconciler)
CompositeReconcilerOptions is used to configure CompositeReconciler.
func WithCleanupStrategy ¶
func WithCleanupStrategy(cleanupStrat CleanupStrategy) CompositeReconcilerOptions
WithCleanupStrategy sets the CleanupStrategy of the CompositeReconciler.
func WithClient ¶
func WithClient(cli client.Client) CompositeReconcilerOptions
WithClient sets the k8s client in the reconciler.
func WithController ¶
func WithController(ctrlr Controller) CompositeReconcilerOptions
WithController sets the Controller in a CompositeReconciler.
func WithFinalizer ¶
func WithFinalizer(finalizer string) CompositeReconcilerOptions
WithFinalizer sets the name of the finalizer used by the CompositeReconciler.
func WithInitCondition ¶
func WithInitCondition(cndn conditionsv1.Condition) CompositeReconcilerOptions
WithInitCondition sets the initial status Condition to be used by the CompositeReconciler on a resource object.
func WithLogger ¶
func WithLogger(log logr.Logger) CompositeReconcilerOptions
WithLogger sets the Logger in a CompositeReconciler.
func WithName ¶
func WithName(name string) CompositeReconcilerOptions
WithName sets the name of the CompositeReconciler.
func WithPrototype ¶
func WithPrototype(obj client.Object) CompositeReconcilerOptions
WithPrototype sets a prototype of the object that's reconciled.
func WithScheme ¶
func WithScheme(scheme *runtime.Scheme) CompositeReconcilerOptions
WithScheme sets the runtime Scheme of the CompositeReconciler.
type Controller ¶
type Controller interface { // Apply default values to the primary object spec. Use this in case a // defaulting webhook has not been deployed. Default(context.Context, client.Object) // Validate validates the primary object spec before it's created. It // ensures that all required fields are present and valid. Use this in case // a validating webhook has not been deployed. Validate(context.Context, client.Object) error // Initialize sets the provided initialization condition on the object // status. This helps some operations in Operation() know about the // creation phase and run initialization specific operations. Initialize(context.Context, client.Object, conditionsv1.Condition) error // UpdateStatus queries the status of the child objects and based on them, // sets the status of the primary object instance. It doesn't save the // updated object in the API. API update is done in PatchStatus() after // collecting and comparing all the status updates. This is also called // when cleanup is in progress. This should be able to remove previous // status related to child objects that have been terminated. UpdateStatus(context.Context, client.Object) error // Operate runs the core operation of the controller that ensures that // the child objects or the other objects and configurations in the // environment are in the desired state. It should be able to update any // existing resources or create one, if there's a configuration drift, // based on the type of objects. // The returned result is the returned reconcile result. Operate(context.Context, client.Object) (result ctrl.Result, err error) // Cleanup runs the custom cleanup operation to delete or undo the changes // made by the controller. This can be empty for controllers that use owner // reference based garbage collection for cleanup. For controllers with // custom cleanup requirement, the cleanup logic can be defined here. Cleanup(context.Context, client.Object) (result ctrl.Result, err error) }
Controller is the controller interface that must be implemented by a composite controller. It provides methods required for reconciling a composite controller.