Documentation
¶
Index ¶
- func CheckIfNamespaceExists(ctx context.Context, clientset *kubernetes.Clientset, namespace string, ...) (bool, error)
- func CheckImminentDeletionAndHandleFinalizers(ctx context.Context, k8sClient client.Client, ...) (bool, bool, error)
- func FindUniqueOrMostRecentResourceInScope(ctx context.Context, k8sClient client.Client, namespace string, ...) (dash0operator.Dash0Resource, error)
- func InitStatusConditions(ctx context.Context, k8sClient client.Client, ...) (bool, error)
- func VerifyThatResourceIsUniqueInScope(ctx context.Context, k8sClient client.Client, req ctrl.Request, ...) (bool, error)
- type CheckResourceResult
- type SortByCreationTimestamp
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 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 ¶
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)