resources

package
v0.0.0-...-1165094 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIfNamespaceExists

func CheckIfNamespaceExists(
	ctx context.Context,
	clientset *kubernetes.Clientset,
	namespace string,
	logger *logr.Logger,
) (bool, error)

CheckIfNamespaceExists checks if the given namespace (which is supposed to be the namespace from a reconcile request) exists in the cluster. If the namespace does not exist, it returns false, and this is supposed to stop the reconcile

func CheckImminentDeletionAndHandleFinalizers

func CheckImminentDeletionAndHandleFinalizers(
	ctx context.Context,
	k8sClient client.Client,
	resource dash0operator.Dash0Resource,
	finalizerId string,
	logger *logr.Logger,
) (bool, bool, error)

CheckImminentDeletionAndHandleFinalizers checks if the resource is marked for deletion, that is, if it has a deletion timestamp set and whether it has a finalizer set.

Returns (isMarkedForDeletion, runCleanupActions, error). If isMarkedForDeletion and runCleanupActions are both true, the resource has a deletion timestamp, but it also still has a finalizer set. The caller is expected to run all cleanup actions for this resource and remove the finalizer, then stop the reconcile. If isMarkedForDeletion is true and runCleanupActions is false, the resource has a deletion timestamp and does not have a finalizer set. The caller does not need to take any particular action and can stop the reconcile.

func FindUniqueOrMostRecentResourceInScope

func FindUniqueOrMostRecentResourceInScope(
	ctx context.Context,
	k8sClient client.Client,
	namespace string,
	resourcePrototype dash0operator.Dash0Resource,
	logger *logr.Logger,
) (dash0operator.Dash0Resource, error)

FindUniqueOrMostRecentResourceInScope tries to fetch the unique resource of a given type in a scope (cluster or namespace). If multiple resources exist, it returns the most recent one. If no resources exist, it returns nil.

func InitStatusConditions

func InitStatusConditions(
	ctx context.Context,
	k8sClient client.Client,
	resource dash0operator.Dash0Resource,
	conditions []metav1.Condition,
	logger *logr.Logger,
) (bool, error)

func VerifyThatResourceIsUniqueInScope

func VerifyThatResourceIsUniqueInScope(
	ctx context.Context,
	k8sClient client.Client,
	req ctrl.Request,
	resource dash0operator.Dash0Resource,
	updateStatusFailedMessage string,
	logger *logr.Logger,
) (bool, error)

VerifyThatResourceIsUniqueInScope checks whether there are any additional resources of the same type in the namespace, besides the one that the current reconcile request applies to. The bool the function returns has the semantic stopReconcile, that is, if the function returns true, it expects the caller to stop the reconcile. If there are no errors and the resource is unique, the function will return (false, nil). If there are multiple resources in the namespace, but the given resource is the most recent one, the function will return (false, nil) as well, since the newest resource should be reconciled. If there are multiple resources and the given one is not the most recent one, the function will return (true, nil), and the caller is expected to stop the reconcile and not requeue it. If any error is encountered when searching for other resource etc., that error will be returned, the caller is expected to ignore the bool result and requeue the reconcile request.

Types

type CheckResourceResult

type CheckResourceResult struct {
	Resource             dash0operator.Dash0Resource
	StopReconcile        bool
	ResourceDoesNotExist bool
}

func VerifyThatResourceExists

func VerifyThatResourceExists(
	ctx context.Context,
	k8sClient client.Client,
	req ctrl.Request,
	resourcePrototype dash0operator.Dash0Resource,
	logger *logr.Logger,
) (CheckResourceResult, error)

VerifyThatResourceExists loads the resource that the current reconcile request applies to. If that resource does not exist, the function logs a message and returns (nil, true, nil) and expects the caller to stop the reconciliation (without requeing it). If any other error occurs while trying to fetch the resource, the function logs the error and returns (nil, true, err) and expects the caller to requeue the reconciliation.

func VerifyThatUniqueNonDegradedResourceExists

func VerifyThatUniqueNonDegradedResourceExists(
	ctx context.Context,
	k8sClient client.Client,
	req ctrl.Request,
	resourcePrototype dash0operator.Dash0Resource,
	updateStatusFailedMessage string,
	logger *logr.Logger,
) (CheckResourceResult, error)

VerifyThatUniqueNonDegradedResourceExists loads the resource that the current reconcile request applies to, if it exists. It also checks whether there is only one such resource (or, if there are multiple, if the currently reconciled one is the most recently created one). The bool returned has the meaning "stop the reconcile request", that is, if the function returns true, it expects the caller to stop the reconcile request immediately and not requeue it.

If an error occurs during any of the checks (for example while talking to the Kubernetes API server), the function will return that error, the caller should then ignore the CheckResourceResult result and requeue the reconcile request.

  • If the resource does not exist, the function logs a message and returns a CheckResourceResult with StopReconcile=true and ResourceDoesNotExist=true, the caller is expected to stop the reconciliation (without requeing it).
  • If the resource exists but has already been marked as degraded by a previous reconcile cycle, the function will skip the uniqueness check and return the resource and StopReconcile=false. The caller is expected to handle the degraded resource adequately.
  • If there are multiple resources in the namespace, but the given resource is the most recent one, the function will return the resource together StopReconcile=false, since the newest resource should be reconciled. The caller should continue with the reconcile request in that case.
  • If there are multiple resources and the given one is not the most recent one, the function will return the resource together with StopReconcile=false. The caller is expected to handle degraded resource adequately.
  • If any error is encountered when searching for resources etc., that error will be returned, the caller is expected to ignore the CheckResourceResult result and requeue the reconcile request.

type SortByCreationTimestamp

type SortByCreationTimestamp []client.Object

func (SortByCreationTimestamp) Len

func (s SortByCreationTimestamp) Len() int

func (SortByCreationTimestamp) Less

func (s SortByCreationTimestamp) Less(i, j int) bool

func (SortByCreationTimestamp) Swap

func (s SortByCreationTimestamp) Swap(i, j int)

Jump to

Keyboard shortcuts

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