Controller · manager
HostOperation controller
The HostOperation controller is the executor. It runs the steps of an approved HostOperation against the BMC, the Talos API and the Kubernetes API of the node. It is the only controller that changes a machine after a person approved it.
At a glance
Section titled “At a glance”- Reconciles
- HostOperation (
For). Controller namehostoperation. - Workers
- 4 passes at the same time, each on another Host and another BMC.
- Writes
- The operation status:
Approved,Executed,baseline,steps, phase. It never writes the spec. - Talks to
- The BMC (write session), the Talos API of the node, the Kubernetes API of the workload cluster, and the media service.
- Pass budget
- 1 minute. 15 minutes with
flashFirmwareorstageFirmware. 35 minutes withtalosUpgrade. - Requeue
- 5 seconds for a waiting step. 30 seconds while a guard holds. The next window opening while a window holds.
- Source
- hostoperation_controller.go
Watches
Section titled “Watches”| Kind | Relation | Why a change starts a pass |
|---|---|---|
| HostOperation | For |
A person approved, aborted or annotated the operation. |
| HostOperation | Watches, the other operations on the same Host |
A predecessor finished. The next one in the queue can start. |
| Host | Watches, index .spec.hostRef.name |
The Host appeared, its paths changed, or maintenance ended. |
Start gates and step loop
Section titled “Start gates and step loop”Step through the figure, or use the arrow keys.
The executor: start gates and step loop
1 / 18
Read
A pass starts when the operation, a sibling operation or its Host changes. A finished operation only waits for its TTL.
kubectl get hostoperations -ARead. A pass starts when the operation, a sibling operation or its Host changes. A finished operation only waits for its TTL.
kubectl get hostoperations -AAbort. If a person asked for an abort and the operation has no baseline, it ends at once. Nothing touched the machine.
pk-metal abort <operation>Approval. If approval is required and approvedBy is empty, the pass stops. Approved is False with the reason AwaitingApproval.
pk-metal approve <operation>Rollout. An operation that names a rollout starts only while the rollout approval covers its plan hash, node, host and actions. If not, it fails.
Known actions. If this operator version does not run one of the actions, the operation fails before it starts.
Queue. Only one operation runs on a Host. A started one goes first, then the oldest. The others wait with OperationQueued.
Locks. A pass takes a lock on the Host and on each BMC of the Host. If a lock is busy, the pass comes back later. It changed nothing.
Maintenance. If the Host has the maintenance annotation, an operation that did not start waits with HostInMaintenance.
kubectl annotate host <host> metal.platform-kit.org/maintenance-Window. If a MaintenanceWindow covers the Host and no window is open, the operation waits until the next one opens. An install does not wait.
Guards. A disruptive operation asks the self guard and the cluster guard. If either one holds it, it waits with SelfDisruption or ClusterDisruption.
Baseline. The executor checks the queue again against the API server. It reads the BMC and writes the baseline before the first change to the machine.
Next step. The pass continues after the last recorded step. Before each step it checks for an abort and for enough time left in the pass budget.
Cluster guard. A step that takes a control plane down asks the cluster guard again, right before it acts. A drain before it can take a long time.
Run step. The step first compares its goal with the machine. An image that is already inserted, or a power state already reached, is success.
Record. The executor adds the step to status.steps and writes the status before the next step. A pass that stops continues from this record.
Wait. A step that waits for the world, or a guard that holds, ends the pass. The next pass comes after the wait interval, 5 seconds by default.
Failed. A step that fails ends the operation. Executed is False with StepFailed. The executor never retries. A person retries or deletes it.
pk-metal retry <operation>Succeeded. When no step is left, the executor reads the reset time once more and sets Executed to True. The TTL then deletes the operation.
Reconcile loop
Section titled “Reconcile loop”- Read the operation. If it is deleted, revoke its media grants and stop. If it finished, delete it when its TTL ends. A failed operation never expires.
- If a person asked for an abort before the start, end the operation with
Aborted. Nothing touched the machine. - If the operation needs approval and
spec.approval.approvedByis empty, setApprovedto False withAwaitingApprovaland stop. - If the operation names a rollout, check that the approved plan of the TalosRollout covers it. If not, fail with
RolloutRefused. - If an action is not known to this operator version, fail the operation before it starts.
- If another operation holds the Host, wait with
OperationQueued. - Take the locks on the Host and on each BMC of the Host. If one is busy, try again after 5 seconds.
- Before the start only: hold for maintenance, for a closed maintenance window, and for the self guard.
- Start: check the queue against the API server, read the BMC baseline, and ask the self guard and the cluster guard again. Write the baseline last.
- Run the steps from the last recorded step. Before each step, check for an abort, the pass budget and, for a disruptive step, the cluster guard.
- Record each step in
status.stepsand write the status before the next step. - After the last step, read the reset time again and set
Executedto True withStepsSucceeded.
Guards and decisions
Section titled “Guards and decisions”- Approval is admission
- The executor only reads the approval. The admission policy checks who approved. The executor RBAC has no
patchon operations, so it cannot approve. - One operation per Host
- A started operation goes first, then the oldest. The executor checks the queue in the cache, then again against the API server before the start.
- Resumable steps
- Each step compares its goal with the world before it acts. A pass that stops halfway re-enters the step safely.
- No retry
- A step that fails ends the operation for good. A person reads why, then uses pk-metal retry or deletes it.
- A network error is a wait
- If the BMC or the cluster API does not answer this pass, the step waits. It does not fail.
- Running work finishes
- Maintenance, a closed window and the self guard hold only an operation that did not start. Stopping between a mount and its boot leaves the machine worse off.
- Abort undoes what it can
- An abort between steps ejects media that a step mounted and clears a boot override. It uncordons a node that this operation cordoned. A reboot or a removed etcd member stays.
- Media grants
- For a config medium or an embedded installer, the executor issues a grant on the media service. The grant checks the digest that the person approved. It ends with the operation.
Step budgets
Section titled “Step budgets”| Step | Wait limit |
|---|---|
| PowerCycle, PowerOff and the other BMC steps that wait | 5 minutes. A graceful power-off adds its graceful window. |
| AwaitCheckIn | timeoutSeconds, default 30 minutes (--checkin-timeout for a boot) |
| Drain | timeoutSeconds, default 900 seconds |
| WaitNodeReady | timeoutSeconds, default 1800 seconds |
| WaitEtcdHealthy | timeoutSeconds, default 900 seconds |
| TalosUpgrade | 45 minutes |
| TalosReboot, TalosShutdown, TalosReset, TalosApplyConfig | 20 minutes |
Writes
Section titled “Writes”| Object or field | When | Field manager |
|---|---|---|
Operation status (Approved, Executed, baseline, steps, observedResetTime, phase) |
Before the first change, and after each step | manager (status update) |
Host annotation metal.platform-kit.org/release-power-off |
Before a boot of a claim starts | manager (merge patch) |
| TalosNode annotation that asks for a check now | After a reboot step | manager (patch) |
| Delete of the operation | TTL ended after success | manager |
Events StepFailed, StepsSucceeded, Aborted |
On each outcome | pk-metal event source |
Conditions
Section titled “Conditions”| Condition | Status | Reasons |
|---|---|---|
Approved |
True | Approved, ApprovalNotRequired |
Approved |
False | AwaitingApproval |
Executed |
Unknown | Executing, OperationQueued, HostNotFound, HostInMaintenance, OutsideMaintenanceWindow, SelfDisruption, ClusterDisruption, NoReachablePath |
Executed |
False | StepFailed, RolloutRefused, HostNotClaimed, Aborted |
Executed |
True | StepsSucceeded |
An Unknown reason other than Executing is the blockedOn of the operation. The phase stays Proposed while it holds.
Failure modes
Section titled “Failure modes”| You see | Cause | Do this |
|---|---|---|
Phase Failed, StepFailed |
A step failed or its wait ran out. | Use Operation failed. |
Waits with OutsideMaintenanceWindow |
A window covers the Host and is closed. | Wait, or set metal.platform-kit.org/ignore-window. See MaintenanceWindow controller. |
Waits with ClusterDisruption |
Etcd would not stay healthy. | Use etcd unhealthy or quorum lost. |
Waits with OperationQueued |
Another operation holds the Host. | Approve or delete that one first. See Approve, hold, retry and abort. |
Permissions
Section titled “Permissions”| API group | Resources | Verbs | Scope | Marker in |
|---|---|---|---|---|
metal.platform-kit.org | hostoperations | getlistwatchdelete | cluster | hostoperation_controller.go |
metal.platform-kit.org | hostoperations/status | update | cluster | hostoperation_controller.go |
metal.platform-kit.org | hosts | getlistwatchpatch | cluster | hostoperation_controller.go |
metal.platform-kit.org | hostclaims | get | cluster | hostoperation_controller.go |
metal.platform-kit.org | managementendpoints | getlistwatch | cluster | hostoperation_controller.go |
metal.platform-kit.org | biossettings | getlistwatch | cluster | hostoperation_controller.go |
os.platform-kit.org | bootassetstalosnodestalosclusters | getlistwatch | cluster | hostoperation_controller.go |
core | secrets | getlistwatch | namespace pk-metal | hostoperation_controller.go |
core | configmaps | getlistwatch | namespace pk-metal | hostoperation_controller.go |
events.k8s.io | events | createpatch | cluster | hostoperation_controller.go |
os.platform-kit.org | talosrollouts | getlistwatch | cluster | hostoperation_rollout.go |
os.platform-kit.org | talosnodes | getlistwatchpatch | cluster | hostoperation_reinstall.go |
os.platform-kit.org | talosclusterstalosnodesetcdsnapshots | getlistwatch | cluster | hostoperation_etcdrecover.go |
metal.platform-kit.org | maintenancewindows | getlistwatch | cluster | window.go |
metal.platform-kit.org | maintenancewindows/status | update | cluster | window.go |
The maintenancewindows/status row belongs to the MaintenanceWindow controller, whose markers are in the same file.
Protocol model explains the model test.