Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CleanupFn ¶
type CleanupFn func() error
CleanupFn is a closure which can be used in the reconciler to define finalizer logic just before the object is removed from kube-apiserver.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler encapsulates finalizer handling. It can: - add finalizer to a given object and persist it - perform cleanup defined as CleanupFn if the object is marked for deletion
Example usage in the controller reconcile loop:
finalizerHandler := finalizer.NewHandler(r.Client, "federation.openshift-service-mesh.io/mesh-federation") if finalized, errFinalize := finalizerHandler.Finalize(ctx, meshFederation, func() error { // finalizer logic return nil }); finalized { return ctrl.Result{}, errFinalize } if finalizerAlreadyExists, errAdd := finalizerHandler.Add(ctx, meshFederation); !finalizerAlreadyExists { return ctrl.Result{}, errAdd }
func (*Handler) Add ¶
Add adds the defined finalizer to the object and then persists it if the finalizer was not already present. Returns true if the finalizer was already present. Returns an error if updating the object failed.
func (*Handler) Finalize ¶
func (f *Handler) Finalize(ctx context.Context, obj client.Object, cleanupFn CleanupFn) (bool, error)
Finalize executes cleanup logic defined in cleanupFn only if the object is marked for deletion. Returns true if finalizer logic was attempted. Returns an error if the cleanup function was unsuccessful or the removal of the finalizer failed.