Skip to main content

Module conditions

Module conditions 

Source
Expand description

Maintaining the standard status.conditions of a resource.

These functions operate on the Condition type that Kubernetes defines for this purpose, following the same rules as k8s.io/apimachinery/pkg/api/meta.SetStatusCondition:

  • A resource has at most one condition of each type.
  • lastTransitionTime records when the condition’s status last changed. It does not change when only the reason, message, or observedGeneration do, so it answers “how long has this been False?” rather than “when was this last written?”.
  • observedGeneration records the metadata.generation of the resource that the condition was determined from. A condition whose observedGeneration is older than the resource’s current generation describes a spec that has since been changed, so should not be trusted as describing the current one (see find_observed).

A reconciler typically computes each condition from what it observed, applies them with set, and writes the status back only if any of them changed:

let change = conditions::set(
    &mut status.conditions,
    if ready {
        DesiredCondition::new("Ready", ConditionStatus::True, "DeploymentAvailable", "")
    } else {
        DesiredCondition::new(
            "Ready",
            ConditionStatus::False,
            "DeploymentUnavailable",
            "waiting for the deployment's pods to become ready",
        )
    }
    .observed_generation(generation),
);
if change.is_changed() {
    // write the status
}

Structs§

DesiredCondition
A condition as a reconciler wants it to be, to be applied with set.
InvalidConditionStatus
The error returned when parsing a string that is not True, False, or Unknown as a ConditionStatus.

Enums§

ConditionChange
What set changed.
ConditionStatus
The status of a Condition.

Functions§

find
Returns the condition of the given type, if present.
find_observed
Returns the condition of the given type, if present and determined from the given generation of its resource (which should be that resource’s current metadata.generation).
remove
Removes the condition of the given type, returning whether it was present.
set
Sets the condition of desired.type_ to desired, adding it if it is not already present, and returns what changed.