Documentation
¶
Overview ¶
Package reconcile holds the diff and converge logic at the heart of the agent. It compares the desired state (from the control plane) against the actual state (containers on the host carrying our label prefix) and converges: start missing, stop extra, restart unhealthy or stale. Every operation is idempotent and safely retryable, so a converge that is interrupted and re-run reaches the same end state.
The logic here depends only on the docker.Client interface, so it is fully unit testable with a fake client (see reconcile_test.go).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply executes a plan against the docker client. It is idempotent: a step whose effect is already in place is a cheap no-op, and a failure on one step does not abort the rest, so the next poll retries what did not land. The set of errors encountered is returned joined, so the caller can log and carry on rather than crash.
Types ¶
type Action ¶
type Action string
Action names a single convergence step, for structured logging.
const ( // ActionStart starts a missing container for a desired workload. ActionStart Action = "start" // ActionStop stops and removes a container with no matching desired workload. ActionStop Action = "stop" // ActionRestart restarts an unhealthy or crashed container. ActionRestart Action = "restart" // ActionRoll stops a stale container (wrong image or spec version) and starts // a fresh one. ActionRoll Action = "roll" )
type Plan ¶
type Plan struct {
Steps []Step
}
Plan is the ordered set of steps computed by Diff. Stops run before starts so a roll frees resources before claiming them again.
func Converge ¶
Converge is the full diff-then-apply cycle: list actual containers, compute the plan and apply it. It returns the plan (for logging) and any converge errors.
func Diff ¶
func Diff(desired contract.DesiredState, actual []docker.Container) Plan
Diff computes the convergence plan for a desired state against the observed containers. It is pure: it performs no I/O and mutates nothing, which is what makes it unit testable.
Rules, per desired workload with Replicas = N:
- Exactly N replica slots (indices 0..N-1) should each have one healthy, up-to-date container. A missing slot is started; a stale one is rolled; an unhealthy or crashed one is restarted in place.
- A container at an index >= N (a scale-down), a duplicate for a slot already filled, or a legacy container from an agent that predates replica indexing, is surplus and stopped.
- Replicas == 0 stops every container for the workload (the Egg goes cold on purpose).
- A container with no matching desired workload is stopped (extra).
type Step ¶
type Step struct {
Action Action
WorkloadID string
// BlobID is the internal Blob identity of the Egg the step concerns, if
// known. Never rendered to customers.
BlobID string
// ContainerID is the target container, where one exists.
ContainerID string
// ReplicaIndex is the 0-based replica slot this step concerns. ActionStart uses
// it to name and label the new container; stop, roll and restart carry it for
// logging and idempotency.
ReplicaIndex int
}
Step is one planned or performed convergence action, kept for logging and for assertion in tests.