Controller · manager
Protection controller
The protection controller stops garbage collection from deleting a machine that a claim holds. This page also describes the two guards that keep the operator from rebooting itself or breaking etcd.
At a glance
Section titled “At a glance”- Reconciles
- Host (
For). Controller nameprotection. - Finalizer
metal.platform-kit.org/claim-protectionon the Host and on each ManagementEndpoint that fronts it.- Writes
- The finalizer, and the endpoint condition
DeletionHeld. - Requeue
- None. Host and endpoint events start the next pass.
- Source
- protection_controller.go
Why it exists
Section titled “Why it exists”An Asset owns its endpoint, and the endpoint owns the Hosts that it fronts. If you delete an Asset, garbage collection follows the owner chain. Without protection, a clean-up of an Asset could delete a machine in production or in the middle of an install.
Watches
Section titled “Watches”| Kind | Relation | Why a change starts a pass |
|---|---|---|
| Host | For |
A claim bound or released the Host. |
| ManagementEndpoint | Watches, mapped to the Hosts it fronts |
An endpoint got a deletion timestamp. |
Reconcile loop
Section titled “Reconcile loop”- Read the Host.
- Add the finalizer if
spec.claimRefis set. Remove it if not. - Go through each endpoint in
status.managedBy. - Add the finalizer to the endpoint if it fronts any claimed Host. Remove it if not.
- If the endpoint has a deletion timestamp and a claimed Host, set
DeletionHeldto True. The message names the claim to delete.
Each finalizer change is a merge patch with an optimistic lock, so that the controller never drops a finalizer that somebody else added.
The self guard
Section titled “The self guard”The self guard keeps the operator from rebooting the machine that it runs on, or a control plane of its own cluster. It matters after pk-metal pivot, when the operator runs on a cluster that it built. See Self-protection.
How the guard finds where the operator runs:
- The Deployment passes the node name of the pod as
NODE_NAME. The manager gets it with--node-name. - The guard reads that Kubernetes Node and its addresses.
- The TalosNode with the same name, or with one of these addresses, is the node of the operator. Its cluster is the cluster of the operator.
- A Host runs a TalosNode when its
spec.osnames it.
If no TalosNode matches, for example on a kind cluster, the guard allows everything.
| Host runs | Without the annotation | With metal.platform-kit.org/allow-self-disruption |
|---|---|---|
| The node of the operator pod | Held | Allowed |
| A control plane of the operator cluster | Held | Allowed only if no other control plane is in a power action, and a majority of the other control planes run and are ready now |
| Any other node | Allowed | Allowed |
The guard asks the other control planes through the Talos API, with a 5 second limit for each. A control plane that does not answer counts as down. The HostClaim controller, HostOperation controller and Convergence controller ask the self guard before they propose or start a power action. The Etcd backup controllers uses only its location step, to find the cluster of the operator.
The cluster guard
Section titled “The cluster guard”The cluster guard keeps etcd healthy in every Talos cluster that the operator built, not only its own. The HostOperation controller asks it before an operation starts and again before each step that takes a control plane down.
A step that takes a control plane down waits while one of these is true:
- Another control plane of the same cluster is in an operation that started and did not finish.
- Etcd is not fully healthy without the member of this node. These cases count: a member does not answer, has an error, has no leader or is a learner. An alarm is raised, or the rest is not a majority.
The guard counts from the etcd member list that it reads live from the members. It does not count TalosNodes.
The guard does not hold a worker, a control plane that is not an etcd member, or a cluster that was never bootstrapped.
Writes
Section titled “Writes”| Object or field | When | Field manager |
|---|---|---|
Finalizer metal.platform-kit.org/claim-protection on Host and endpoints |
When the claim state changes | manager (merge patch) |
Endpoint status.conditions[DeletionHeld] |
A deleting endpoint fronts a claimed Host | pk-metal-protection (server-side apply) |
The Host controller sets DeletionHeld on the Host itself.
Failure modes
Section titled “Failure modes”| You see | Cause | Do this |
|---|---|---|
Endpoint stays in deletion, DeletionHeld=True |
A claim holds the Host behind it. | Delete the claim. See Release a host. |
Operation waits with SelfDisruption |
The operator runs on the machine. | Move the operator first with pk-metal pivot, or set the annotation on the Host. |
Operation waits with ClusterDisruption |
Etcd would lose its majority. | Use etcd unhealthy or quorum lost. |
Permissions
Section titled “Permissions”| API group | Resources | Verbs | Scope | Marker in |
|---|---|---|---|---|
metal.platform-kit.org | hosts | getlistwatchpatch | cluster | protection_controller.go |
metal.platform-kit.org | managementendpoints | getlistwatchpatch | cluster | protection_controller.go |
metal.platform-kit.org | managementendpoints/status | patch | cluster | protection_controller.go |
core | nodes | get | cluster | selfprotect.go |
metal.platform-kit.org | hostclaims | get | cluster | selfprotect.go |