pub fn should_reconcile(
current_generation: Option<i64>,
observed_generation: Option<i64>,
) -> boolExpand description
Check if a resource’s spec has changed by comparing generation with observed_generation.
This is the standard Kubernetes pattern for determining if reconciliation is needed.
The metadata.generation field is incremented by Kubernetes only when the spec changes,
while status.observed_generation is set by the controller after processing a spec.
§Arguments
current_generation- The resource’s currentmetadata.generationobserved_generation- The controller’s laststatus.observed_generation
§Returns
true- Reconciliation is needed (spec changed or first reconciliation)false- No reconciliation needed (spec unchanged, status-only update)
§Example
ⓘ
use bindy::reconcilers::should_reconcile;
fn check_if_reconcile_needed(resource: &MyResource) -> bool {
let current = resource.metadata.generation;
let observed = resource.status.as_ref()
.and_then(|s| s.observed_generation);
should_reconcile(current, observed)
}§Kubernetes Generation Semantics
metadata.generation: Incremented by Kubernetes API server when spec changesstatus.observed_generation: Set by controller to matchmetadata.generationafter reconciliation- When they match: spec hasn’t changed since last reconciliation → skip work
- When they differ: spec has changed → reconcile
- When
observed_generationis None: first reconciliation → reconcile