Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 4 min read

Desired State Is Not Enough: Authority, Generations, and Drift

This is article 7 of 10 in Beyond Kubernetes Defaults. Read article 6: Process-Local Deduplication Breaks the Moment You Add a Second Replica first, or start with article 1. Kubernetes taught an entire generation of sy

This is article 7 of 10 in Beyond Kubernetes Defaults. Read article 6: Process-Local Deduplication Breaks the Moment You Add a Second Replica first, or start with article 1.

Kubernetes taught an entire generation of systems engineers to think declaratively:

Describe the state you want and reconcile toward it.

That model is powerful.

The difficulty begins when a distributed system has several actors reporting and applying state across network boundaries.

Three states, not one

A useful separation is:

Desired

What the authoritative control plane wants.

Observed

What the runtime reports is actually true.

Last applied

What the authorized reconciler knows it successfully applied.

Those are not interchangeable copies of one record.

Why ownership matters

Suppose a desired object says generation 8.

The remote workload reports generation 7.

The controller remembers successfully applying generation 6.

That difference contains information:

desired = 8
observed = 7
last-applied = 6

It may indicate that desired state moved and the runtime observed an intermediate revision. The last-applied record is older, but the cause needs investigation: observation can be delayed, the controller may have restarted, or another actor may have changed the runtime.

If all three actors can overwrite one shared β€œgeneration” field, the system loses the ability to classify what happened.

The rule we use is:

Every authoritative field has one owner.

Generations make stale work visible

Networked reconciliation creates delayed work.

A plan can be computed, the connection can drop, a newer desired revision can arrive, and the old plan can wake up later.

A robust reconciler needs enough context to reject stale work:

  • desired generation;
  • connection/session generation;
  • object revision;
  • state digest;
  • authority/fencing state where relevant.

That makes β€œstale” a typed state rather than an operator guess.

Drift is not one boolean either

A useful drift classifier can distinguish:

  • in sync;
  • desired ahead;
  • observed ahead/unexpected;
  • stale;
  • disconnected;
  • unavailable/unknown.

Those conditions drive very different remediation.

β€œDrift=true” alone often hides the most important fact.

Reconciliation should stay inside its authority

Another benefit of explicit state ownership is preventing a controller from slowly absorbing unrelated product semantics.

A lifecycle reconciler can manage Plane configuration, connection state, drain/retire operations and convergence evidence without compiling customer Flows or executing Traffic.

That boundary matters as systems grow.

Kubernetes remains the model underneath

CRDs, status subresources, optimistic concurrency and controller-runtime are excellent mechanisms for implementing these contracts.

The additional work is semantic:

  • deciding which state is authoritative;
  • deciding who owns each field;
  • defining stale-state rejection;
  • preserving enough history for restart correctness;
  • emitting evidence of convergence.

Desired state is the beginning of reconciliation, not the whole state model.

Connection generation is easy to overlook

Imagine a controller computes a plan for a remote runtime, then that runtime disconnects and reconnects with a new session before the plan is applied.

The desired object may still be the same revision. The plan can still be stale because the connection context changed.

A connection/session generation lets the system invalidate work derived from an older session without pretending the product object itself changed.

This is another example of why one universal β€œgeneration” counter becomes confusing.

Last-applied state is evidence, not a second desired state

The controller-owned last-applied record should answer:

What did this authorized reconciler successfully apply?

It should not become another writer of desired intent or another copy of untrusted observed state.

That distinction becomes important during recovery. After restart, the controller can compare durable last-applied state with current desired and newly observed state, then decide whether it is converged, behind, or dealing with an unexpected runtime state.

Tombstones matter

Deletion and disablement are also state transitions.

If a desired object disappears without a durable retirement/tombstone concept, a restarted controller can accidentally recreate or β€œresurrect” state from old caches or observed data.

A tombstone or explicit disabled revision gives the system something authoritative to converge toward.

This is particularly useful for distributed systems where remote runtimes can be offline while the control-plane decision changes.

Evidence turns reconciliation into something inspectable

A mature reconciliation loop should be able to explain:

  • which desired revision it considered;
  • which observed generation it saw;
  • which plan/digest it computed;
  • whether the operation was rejected as stale;
  • which state became last-applied;
  • why the final condition is Ready, Drifted, Stale or Unavailable.

That record is more useful than a controller log saying β€œreconcile successful.”

When the simple model is enough

Many operators do not need this much machinery.

If one controller owns both spec and status, effects are local to the Kubernetes API, and resourceVersion conflicts provide adequate safety, Kubernetes' normal controller pattern is excellent.

The richer state model becomes useful when desired state crosses trust/network boundaries or several authorities must coordinate without becoming co-owners of the same fields.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.