components

package
v0.26.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// ErrorReasonInvalidManagedControlPlaneLabels means that the resource does not have the expected labels in the expected formats.
	ErrorReasonInvalidManagedControlPlaneLabels = "InvalidManagedControlPlaneLabels"
)

Variables

Functions

func AllConditionsTrue

func AllConditionsTrue(conditions ...openmcpv1alpha1.ComponentCondition) bool

AllConditionsTrue returns true if all given conditions are "True".

func DefaultComponentControllerPredicates

func DefaultComponentControllerPredicates() predicate.Predicate

DefaultComponentControllerPredicates returns a predicate combination which should be useful for most - if not all - component controllers.

func EnsureDependencyFinalizer

func EnsureDependencyFinalizer(ctx context.Context, c client.Client, reqComp components.Component, depComp components.Component, expected bool) error

EnsureDependencyFinalizer ensures that the dependency finalizer of component 'depComp' either exists or doesn't exist (based on argument 'expected') on the resource of component 'reqComp'.

func GenerateCreatedFromGenerationPatch

func GenerateCreatedFromGenerationPatch(cp, ic client.Object, addReconcileAnnotation bool) client.Patch

GenerateCreatedFromGenerationPatch returns a patch which sets the generation labels according to the given ManagedControlPlane. If cp is nil, the value of the corresponding generation value is defaulted to -1. This should never happen. if ic is nil, the generated patch will remove the corresponding generation label, if it exists.

func GetComponent

func GetComponent[T components.ManagedComponent](reg components.ComponentRegistry[T], ctx context.Context, c client.Client, component openmcpv1alpha1.ComponentType, name, namespace string) (T, error)

GetComponent fetches a single component resource from the cluster.

func GetComponents

GetComponents iterates over the list of known components and tries to fetch each corresponding resource. The component-specific resources are expected to have the same name and namespace as the ManagedControlPlane. The resulting map contains only entries for component resources that were found. A missing resource will not result in an error.

func GetCondition

GetCondition returns a pointer to the condition for the given type, if it exists. Otherwise, nil is returned.

func GetCreatedFromGeneration

func GetCreatedFromGeneration(obj client.Object) (int64, int64, openmcperrors.ReasonableError)

GetCreatedFromGeneration reads the generation labels for the ManagedControlPlane and the InternalConfiguration from the object and returns their values as int64. If the object does not have an InternalConfiguration generation label, -1 is returned for its value. Returns an error if the ManagedControlPlane generation label does not exist or either label's value cannot be parsed into an int64.

func GetDependents

func GetDependents(requirement components.Component) sets.Set[string]

GetDependents returns all dependency finalizers present on the given component, with the dependency finalizer prefix removed.

func HasAnyDependencyFinalizer

func HasAnyDependencyFinalizer(obj client.Object) bool

HasAnyDependencyFinalizer returns true if the given resource has a dependency finalizer from any other component.

func HasDepedencyFinalizer

func HasDepedencyFinalizer(obj client.Object, ct openmcpv1alpha1.ComponentType) bool

HasDepedencyFinalizer returns true if the given resource has a dependency finalizer from the given component.

func IsAnnotationAlreadyExistsError

func IsAnnotationAlreadyExistsError(err error) bool

func IsComponentReady

func IsComponentReady(comp components.Component, relevantConditions ...string) bool

IsComponentReady returns true if the component's observedGenerations are up-to-date and all of its relevant conditions are "True". If relevantConditions is empty, all of the component's conditions are deemed relevant. Condition types in relevantConditions for which no condition exists on the component are considered "Unknown" and cause the method to return false.

func IsComponentReadyRaw

func IsComponentReadyRaw(cpGen, icGen, rGen int64, obsGen openmcpv1alpha1.ObservedGenerations, conditions ...openmcpv1alpha1.ComponentCondition) bool

IsComponentReadyRaw returns true if the component's observed generations are up-to-date and all of the given conditions are "True". The first three arguments contain the generations of the ManagedControlPlane, InternalConfiguration, and component resource, respectively. They are compared to the observedGenerations in the given ObservedGenerations struct (which usually comes from the component resource's status). The generation of the InternalConfiguration is expected to be -1, if no InternalConfiguration exists. The generation of the component resource can be set to -1 if it is not known (it will then be ignored).

func IsDependencyReady

func IsDependencyReady(dep components.Component, ownCPGeneration, ownICGeneration int64, relevantConditions ...string) bool

IsDependencyReady checks if a dependency is ready. The first argument is the resource (components.Component). The second argument is the generation of the ManagedControlPlane the current component was generated from. The third argument is the generation of the InternalConfiguration the current component was generated from, or -1 if no InternalConfiguration exists. Further arguments can be used to specify which conditions should be checked for readiness. If none are specified, all existing ones have to be "True". In addition to the IsComponentReady/IsComponentReadyRaw functions, this one only returns true if the depended on component was created from the same generation of the ManagedControlPlane as the current component.

func NewCondition

func NewCondition(conType string, status openmcpv1alpha1.ComponentConditionStatus, reason, message string) openmcpv1alpha1.ComponentCondition

NewCondition creates a new ComponentCondition with the given values and the current time as LastTransitionTime.

func PatchAnnotation

func PatchAnnotation(ctx context.Context, c client.Client, obj client.Object, annKey, annValue string, mode ...PatchAnnotationMode) error

PatchAnnotation patches the given annotation into the given object. Returns a AnnotationAlreadyExistsError if the annotation exists with a different value on the object and mode ANNOTATION_OVERWRITE is not set. To remove an annotation, set mode to ANNOTATION_DELETE. The given annValue does not matter in this case. Note that mode is meant to be a single optional mode argument. The behavior if multiple modes are specified at the same time is undefined.

func SetCreatedFromGeneration

func SetCreatedFromGeneration(obj client.Object, cp client.Object, ic client.Object)

SetCreatedFromGeneration sets the managedcontrolplane generation label to the generation of the given ManagedControlPlane. If the passed-in InternalConfiguration is not nil, its generation is also added as a label.

func UpdateStatus

UpdateStatus updates the status of the given component resource. The passed-in reconcile result is returned unmodified to be able to call this function in a reconcile return statement. The ready, reconcileError, reason, and msg parameters are used to update the common status of the component resource. If the status of oldComponent and component differs, the changes are applied too. Note: In order to only update the common status, call this with comp.DeepCopy() as oldComponent and comp as component. oldComponent and component MUST NOT point to the same object!

Types

type AnnotationAlreadyExistsError

type AnnotationAlreadyExistsError struct {
	Annotation   string
	DesiredValue string
	ActualValue  string
}

func NewAnnotationAlreadyExistsError

func NewAnnotationAlreadyExistsError(ann, desired, actual string) *AnnotationAlreadyExistsError

func (*AnnotationAlreadyExistsError) Error

type ComponentConditionListUpdater

type ComponentConditionListUpdater struct {
	Now metav1.Time
	// contains filtered or unexported fields
}

ComponentConditionListUpdater is a helper struct for updating a component's conditions. Use the ConditionUpdater constructor for initializing.

func ConditionUpdater

func ConditionUpdater(conditions openmcpv1alpha1.ComponentConditionList, removeUntouched bool) *ComponentConditionListUpdater

ConditionUpdater creates a builder-like helper struct for updating a list of ComponentConditions. The 'conditions' argument contains the old condition list. If removeUntouched is true, the condition list returned with Conditions() will have all conditions removed that have not been updated. If false, all conditions will be kept. Note that calling this function stores the current time as timestamp that is used as LastTransitionTime if a condition's status changed. To overwrite this timestamp, modify the 'Now' field of the returned struct manually.

The given condition list is not modified.

Usage example: status.conditions = ConditionUpdater(status.conditions, true).UpdateCondition(...).UpdateCondition(...).Conditions()

func (*ComponentConditionListUpdater) Conditions

Conditions returns the updated condition list. If the condition updater was initialized with removeUntouched=true, this list will only contain the conditions which have been updated in between the condition updater creation and this method call. Otherwise, it will potentially also contain old conditions. The conditions are returned sorted by their type.

func (*ComponentConditionListUpdater) HasCondition

func (c *ComponentConditionListUpdater) HasCondition(conType string) bool

HasCondition returns true if a condition with the given type exists in the updated condition list.

func (*ComponentConditionListUpdater) UpdateCondition

UpdateCondition updates or creates the condition with the specified type. All fields of the condition are updated with the values given in the arguments, but the condition's LastTransitionTime is only updated (with the timestamp contained in the receiver struct) if the status changed. Returns the receiver for easy chaining.

func (*ComponentConditionListUpdater) UpdateConditionFromTemplate

UpdateConditionFromTemplate is a convenience wrapper around UpdateCondition which allows it to be called with a preconstructed ComponentCondition.

type GenerationLabelsChangedPredicate

type GenerationLabelsChangedPredicate struct {
	predicate.Funcs
}

GenerationLabelsChangedPredicate reacts on changes to the cp/ir generation labels.

func (GenerationLabelsChangedPredicate) Update

type InvalidGenerationLabelValueError

type InvalidGenerationLabelValueError struct {
	// contains filtered or unexported fields
}

func NewInvalidGenerationLabelValueError

func NewInvalidGenerationLabelValueError(value string, culpritIsIC bool) *InvalidGenerationLabelValueError

func (*InvalidGenerationLabelValueError) Error

func (*InvalidGenerationLabelValueError) Reason

type PatchAnnotationMode

type PatchAnnotationMode string
const (
	ANNOTATION_OVERWRITE PatchAnnotationMode = "overwrite"
	ANNOTATION_DELETE    PatchAnnotationMode = "delete"
)

type ReconcileResult

type ReconcileResult[T components.Component] struct {
	// The old component, before it was modified.
	// Basically, if OldComponent.Status differs from Component.Status, the status will be patched during UpdateStatus.
	// May be nil, in this case only the common status is updated.
	// Changes to anything except the status are ignored.
	OldComponent T
	// The current components.
	// If nil, UpdateStatus becomes a no-op.
	Component T
	// The result of the reconciliation.
	// Is simply passed through.
	Result ctrl.Result
	// The error that occurred during reconciliation, if any.
	ReconcileError openmcperrors.ReasonableError
	// The reason for the component's condition.
	// If empty, it is taken from the error, if any.
	Reason string
	// The message for the component's condition.
	// Potential error messages from the reconciliation error are appended.
	Message string
	// Conditions contains a list of conditions that should be updated on the component.
	// Note that this must not contain the <component>Reconciliation condition, as that one is constructed from this struct's other fields.
	// Also note that names of conditions are globally unique, so take care to avoid conflicts with other components.
	// Futhermore, all conditions on the component resource that are not included in this list anymore will be removed.
	// The lastTransition timestamp of the condition will be overwritten with the current time while updating.
	Conditions []openmcpv1alpha1.ComponentCondition
}

The result of a reconciliation.

func (*ReconcileResult[T]) LogRequeue

func (rr *ReconcileResult[T]) LogRequeue(log logging.Logger, verbosity logging.LogLevel)

LogRequeue logs a message with the given logger at the given verbosity if the currently reconciled object is requeued for another reconciliation.

type StatusChangedPredicate

type StatusChangedPredicate struct {
	predicate.Funcs
}

StatusChangedPredicate returns true if the object's status changed. Getting the status is done via reflection and only works if the corresponding field is named 'Status'. If getting the status fails, this predicate always returns true.

func (StatusChangedPredicate) Update

Jump to

Keyboard shortcuts

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