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:
- A desired workload with replicas >= 1 and no healthy up-to-date container is started (or rolled if a stale one exists).
- A desired workload with replicas == 0 has any container stopped (the Egg goes cold on purpose).
- A container with no matching desired workload is stopped (extra).
- A container whose image or spec version differs from desired is rolled.
- A crashed or unhealthy container for a still-desired workload is restarted.
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
}
Step is one planned or performed convergence action, kept for logging and for assertion in tests.