Skip to content

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.

Reconciles
Host (For). Controller name protection.
Finalizer
metal.platform-kit.org/claim-protection on 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

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.

The owner chain Asset, ManagementEndpoint, Host. The claim-protection finalizer stops the chain at the endpoint and the Host while a HostClaim binds the Host.AssetdeletedManagementEndpointfinalizerHostfinalizerHostClaimbindsownsownsclaimRefgarbage collection waits until the claim is released
The finalizer holds the endpoint and the Host. The release removes it.
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.
The protection reconcile loop: set or remove the finalizer on the Host, then on each fronting endpoint, then mark a held endpoint.Read the Host1StopgoneFinalizer on the Hostpresent while spec.claimRef is set2For each path in status.managedBy3Finalizer on the endpointpresent while it fronts a claimed Host4Mark a deleting endpointDeletionHeld = True, HostClaimed5next pass: a Host or endpoint event
  1. Read the Host.
  2. Add the finalizer if spec.claimRef is set. Remove it if not.
  3. Go through each endpoint in status.managedBy.
  4. Add the finalizer to the endpoint if it fronts any claimed Host. Remove it if not.
  5. If the endpoint has a deletion timestamp and a claimed Host, set DeletionHeld to 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 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:

  1. The Deployment passes the node name of the pod as NODE_NAME. The manager gets it with --node-name.
  2. The guard reads that Kubernetes Node and its addresses.
  3. 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.
  4. A Host runs a TalosNode when its spec.os names 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 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:

  1. Another control plane of the same cluster is in an operation that started and did not finish.
  2. 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.

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.

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.
API groupResourcesVerbsScopeMarker in
metal.platform-kit.orghostsgetlistwatchpatchclusterprotection_controller.go
metal.platform-kit.orgmanagementendpointsgetlistwatchpatchclusterprotection_controller.go
metal.platform-kit.orgmanagementendpoints/statuspatchclusterprotection_controller.go
corenodesgetclusterselfprotect.go
metal.platform-kit.orghostclaimsgetclusterselfprotect.go