controllerhelper

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package controllerhelper contains common helper for controllers.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoManagedFields = errors.New("no managed fields found for field manager")

ErrNoManagedFields is returned when no managed fields are found for the field manager. It indicates the resource was never managed by this controller and should be applied.

Functions

func Diff added in v0.2.0

func Diff(current runtime.Object, desired *unstructured.Unstructured, fieldManager string) (*typed.Comparison, error)

Diff calculates the difference between the current and desired objects.

func EnsureFinalizer added in v0.2.0

func EnsureFinalizer(ctx context.Context, cl client.Client, finalizer string, obj client.Object) (bool, error)

EnsureFinalizer adds the given finalizer to obj if not already present. Returns (true, nil) when the finalizer was just added, (false, nil) if already present, or (false, err) on patch failure.

func EnsureInUseFinalizer added in v0.2.0

func EnsureInUseFinalizer(ctx context.Context, c client.Client, scheme *runtime.Scheme,
	finalizer, fieldManager string, obj client.Object, isReferenced bool) error

EnsureInUseFinalizer adds or removes a single finalizer on obj via server-side apply, based on whether the object is currently referenced (isReferenced).

When isReferenced is true the finalizer is added; when false it is removed. A no-op guard avoids any API call when the current state already matches the desired state.

func FormatChangedFields added in v0.2.0

func FormatChangedFields(comparison *typed.Comparison) string

FormatChangedFields returns a human-readable summary of the changed fields from a comparison.

func HandleObjectDeletion

func HandleObjectDeletion(ctx context.Context, cl client.Client, am *artifact.Manager, finalizer string, obj client.Object) (bool, error)

HandleObjectDeletion handles the deletion of an object. It removes the finalizer and cleans up the local resources associated with the object.

func NodeMatchesSelector

func NodeMatchesSelector(ctx context.Context, cl client.Client, nodeName string, labelSelector *metav1.LabelSelector) (bool, error)

NodeMatchesSelector checks if a selector matches the node labels.

func PatchStatusSSA added in v0.2.0

func PatchStatusSSA(ctx context.Context, c client.Client, scheme *runtime.Scheme, obj client.Object, fieldManager string) error

PatchStatusSSA patches the status subresource of the given object using server-side apply. It converts the object to extract its current status, builds a minimal unstructured apply-configuration containing only identity fields and the status.

func RemoveLocalResources

func RemoveLocalResources(ctx context.Context, cl client.Client, am *artifact.Manager, finalizer string, obj client.Object) (bool, error)

RemoveLocalResources removes local resources associated with the object. Helps to clean up local resources when the object is not targeting the current node anymore. It also removes the finalizer from the object.

func ToUnstructured added in v0.2.0

func ToUnstructured(obj any) (*unstructured.Unstructured, error)

ToUnstructured converts an object to an unstructured.Unstructured.

Types

This section is empty.

Jump to

Keyboard shortcuts

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