Workflow controller
The Workflow controller runs a Workflow's graph. It creates a node's Task when the node's needs are settled, and it reads each Task's result to settle the node. It decides from the Workflow, the Tasks that carry its uid label and the time. The manager performs each create, each delete and each Board append.
| Read | Answers |
|---|---|
| Workflow | What do I apply, and what does the status hold? |
| Node decisions | When does a node start, and when is it settled? |
| Interface | What does the controller read, and what does the manager do? |
| Task controller | Who runs each Task that a Workflow creates? |
One run #
- You apply a Workflow. The store gives it the finalizer
fleet.dev/workflow-tasks. - In each sweep, the manager reconciles each Workflow that is not settled. It also reconciles a Workflow that has no status, whose spec generation changed, that has events to publish, or that is being deleted.
- The controller adds a
Waitingentry for each node tostatus.nodes. - It reads the Task of each node that is not settled. A Task with a result settles the node.
- It settles the
Waitingnodes that cannot run, and starts the nodes that can run, up toparallelism. - It writes the status: the intent of each create, the node phases, the Workflow's phase and the events of each change. Then the manager creates the Tasks and publishes the events.
- When every node is settled, the Workflow is
SucceededorFailed. The manager does not reconcile it again until you delete it.
Implementation and evidence #
| Responsibility | Source | Tests |
|---|---|---|
| Pure decisions: node phases, creates, retires, events, recovery | WorkflowController | Controller passes, Workflow E2E |
| Resource, status, graph check, the brief section and the events | Workflow types, validation | Unit tests in workflow.rs; Workflow E2E |
| Sweep, intent before effect, fenced create and retire, receipts, Board appends, the finalizer | Manager, owned Tasks | Workflow E2E |
The workflow.fleet.dev/ labels, retire_workflow_task, the finalizer |
Store | Store contract |
fleet status workflow |
CLI | Workflow E2E |
| Crate edges and the field manager | architecture.toml | Architecture suite |
The E2E suite runs the manager on the file store with a test clock and the
fake runtime. It covers a node that starts when its needs ship and reads
what they left, a failed need that skips a node and fails the Workflow, an
always node, parallelism, a Task subscribed to fleet.workflow.phase,
a delete that retires the Tasks before the Workflow goes, and a second
apply that changes nothing. Through the fleet binary, it covers the
refusals of a bad graph and of a spec change, and fleet status workflow.
Node decisions #
In each reconcile, the controller applies these steps in order:
- Adopt: when a create has an intent and no
Createdreceipt, and its Task exists with this Workflow's uid, the create gets the receiptCreated, withadoptedtrue. - Observe: for each node that is not settled:
- Its Task exists: the node is
Running. When the Task has a result, the node isSucceededfor the outcomeshipped, andFailedfor any other outcome. - Its Task does not exist, the node is
Running, and the store refused the create three times: the node isFailed, with reasonCreateFailed: <why>. - Its Task does not exist, the node is
Running, and the controller had recorded its uid: the node isFailed, with reasonTaskGone.
- Its Task exists: the node is
- Skip: a
Waitingnode whose needs are all settled, whosewhenissucceededand that has a need that is notSucceededisSkipped. The reason names the need and its phase. The controller repeats this step until no node changes, so a skip goes down the graph in one reconcile. - Start: a
Waitingnode whose needs are all settled, and that is not skipped, is ready. The controller starts the ready nodes in the order ofspec.nodes, while fewer thanparallelismnodes areRunning. A start writes the create's intent undercreate/<node>, and the node isRunning. - Create: for each
Runningnode whose Task does not exist, whose create has noCreatedreceipt and is not given up, the controller plans the create. - Phase: the controller computes the Workflow's phase from the node phases. See Lifecycle.
- Events: for each phase change, of the Workflow or of a node, the
controller adds an event to
pendingEvents.
A settled node never changes again. A Task that carries a Workflow's uid label and has a result is locked in the store:
- The store refuses an amendment to it, from
fleet amendor a plugin'samends[]. - The store refuses
fleet send TASK --retry KEYfor an amendment that was queued before the result and given up on.fleet send TASK --drop KEYstays allowed. - The store refuses a status write that changes its
result.
So the result that settles a node is always its Task's first result.
The Task of a started node has:
- the name
<workflow>-<node>; - the labels of
template.metadata.labels, andworkflow.fleet.dev/nameandworkflow.fleet.dev/uid; - the spec
template.spec, with each field of the node'sspecin place of the field with the same name; - for a node with needs, a brief with the section that quotes what each need left. See The brief of a node with needs.
Conditions #
| Type | Status | Reason | Meaning |
|---|---|---|---|
NeedsAttention |
True | CreateUnknown |
The store could not say, through three attempts, whether a node's Task was created. The message names the Task. |
NeedsAttention |
False | Resolved |
No create is in doubt any more. |
Workflow controller interface #
Controller API #
WorkflowController is in
fleet-controllers. It
is pure.
| Item | Meaning |
|---|---|
WorkflowInput |
The Workflow, the Tasks whose workflow.fleet.dev/uid label is its uid, and now. |
WorkflowController::due(obj) |
True when the Workflow has no status, is being deleted, its spec generation is not observedGeneration, pendingEvents is not empty, or its phase is not settled. |
WorkflowController::reconcile(input) |
Returns a Plan: the status, a Create for each node Task to create, a RetireWorkflowTask effect for each Task to delete, and remove_finalizer when a deleted Workflow has no Task left. |
Manager execution protocol #
The manager reconciles the due Workflows after the CronTasks in each sweep. When no Workflow is due, it reads nothing more. Otherwise it lists the Tasks once for all due Workflows. When it cannot list the Tasks, it reconciles no Workflow: an Unknown listing is never read as no Task.
For each due Workflow the manager does these steps:
- It writes the planned status, compare-and-swap under the lease. The status holds the intent of each create and delete, and the events to publish.
- It performs each create with
Store::create_fenced. Then it writes the receipt under the key. - It performs each delete with
Store::retire_workflow_task, fenced on the Task's uid. Then it writes the receipt under the key. - It appends each event in
pendingEventsto the Boardfleet, ascontroller/workflow-controller. Then it removes the appended events frompendingEvents. - When the plan says so, it removes the finalizer
fleet.dev/workflow-tasks.
A delete only marks the Task. The Task controller releases its session. The Workflow keeps its finalizer until the Task listing has no Task of this Workflow.
Recovery #
An intent with no receipt means that the manager stopped between the two writes. The controller answers it from the Task listing:
- The Task exists and carries this Workflow's uid: the controller records
the receipt
Created, withadoptedtrue. - The Task does not exist: the controller makes the create again, under the same key and the same name.
- A create that finds a Task with the same name but without this uid gets
the receipt
Failed. The controller never takes another Workflow's Task. - A create that the store refused is tried again in the next reconcile.
The record counts the earlier refusals in
refusals. The latest one is inreceipt. Attempts whose outcome was Unknown do not count. After three refusals the create is given up, and the node isFailed. - A create whose outcome is Unknown is tried again in each reconcile, with
no limit: Fleet never reads Unknown as absence. The record counts the
attempts in doubt in
unknowns. Only a Known outcome clears the count. After three attempts in doubt,NeedsAttentionis True with reasonCreateUnknown. - A delete is planned again in each reconcile while the Task exists and is not marked for deletion.
- An event that the manager did not append stays in
pendingEvents, and the next reconcile appends it. Each event has a key, so the Board does not keep a second copy of an event that the manager appended twice. - When the Board refuses an event, such as when the Board
fleetdoes not exist, the manager drops that event. It is not published again. Runfleet initto make a missing Boardfleet.
Store port and write ownership #
| Write | Who | Rule |
|---|---|---|
| Workflow status | workflow-controller |
It owns every field. |
| A Task, created | workflow-controller |
Only through create_fenced, under the lease. |
The workflow.fleet.dev/name and -uid labels |
workflow-controller |
Set at create. fleet apply refuses them, the store refuses them from any other writer, and nobody changes them later. |
| A Task, deleted | workflow-controller |
Only through retire_workflow_task, under the lease: the Task's uid must match, and the Task must carry this Workflow's uid. The Task may be running. |
The finalizer fleet.dev/workflow-tasks |
workflow-controller |
Removed only when no Task of the Workflow is left. |
Events of type fleet.workflow.* on the Board fleet |
workflow-controller |
Appended under the lease, with the source controller/workflow-controller. |