finalizer

package
v0.0.0-...-255ad0c Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

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 NewHandler

func NewHandler(cl client.Client, finalizerName string) *Handler

func (*Handler) Add

func (f *Handler) Add(ctx context.Context, obj client.Object) (bool, error)

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.

Jump to

Keyboard shortcuts

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