The reconciliation loop in an Operator
the control-loop model.
reconcile compares desired spec to observed state and converges them, idempotently; triggered by resource changes, watched dependents, and periodic resync.
WHAT THIS TESTS Whether you grasp the level-triggered control-loop philosophy at the heart of Kubernetes and operators, as opposed to edge-triggered imperative event handling.
A GOOD ANSWER COVERS The reconciliation loop is the function an operator's controller runs to drive the world toward the declared desired state. Its primary goal is convergence: given a custom resource's spec, observe the actual state of the resources it manages and take whatever actions are needed so actual matches desired, then report status. A crucial property is that it is level-based and idempotent. Rather than reacting to the specifics of an event, it always reads the current desired and actual state and computes what to do, so running it twice produces no extra effect. Triggers include creation, update, or deletion of the custom resource itself; changes to dependent objects the controller owns or watches, surfaced through ownerReferences and watches; a periodic resync interval as a safety net; and explicit requeues, often with backoff, after transient errors or when waiting on something to become ready. This design tolerates missed events and controller restarts gracefully.
COMMON WRONG ANSWERS Describing reconcile as imperative per-event handlers with side effects tied to the event payload, ignoring idempotency, or forgetting periodic resync and dependent-object triggers.
LIKELY FOLLOW-UPS Why level-triggered over edge-triggered? How does requeue with backoff work? How do ownerReferences propagate events? What makes reconcile idempotent?
ONE CONCRETE EXAMPLE An operator manages a Cache resource desiring two replicas. Reconcile reads the spec, sees only one pod exists, and creates the second. If the controller crashes and restarts, the next reconcile simply observes two pods already match the spec and does nothing. If someone deletes a pod, the watch on owned pods triggers reconcile, which recreates it, all without depending on which event fired.
Read the original → kubernetes.io
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.