Documentation
¶
Overview ¶
Package leaderelection gates the hub's singleton controllers so a hub scaled to multiple replicas still reconciles each object exactly once.
The lock is a coordination.k8s.io/v1 Lease held in a kcp workspace (kcp serves Leases inside every logical cluster), which keeps the hub's only hard dependency kcp — no host-cluster ServiceAccount or RBAC is required, and the hub works unchanged when it runs outside Kubernetes.
Only *write* loops belong behind this gate. State that the request path reads — most importantly the provider routing registry, which the catalog controller keeps in sync — must be maintained on every replica, or a non-leader would serve requests against an empty routing table.
Index ¶
Constants ¶
const ( DefaultLeaseDuration = 15 * time.Second DefaultRenewDeadline = 10 * time.Second DefaultRetryPeriod = 2 * time.Second )
Default lease timings. They match controller-runtime's defaults, which are tuned for a control plane that may briefly stall (kcp shard restart, front proxy failover) without triggering a spurious failover.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run campaigns for the lease and calls run every time this replica is elected, with a context that is cancelled the moment leadership is lost. It blocks until ctx is done, re-entering the election after each loss, so a transient kcp hiccup costs the hub a controller pause rather than a process restart — the same replica keeps serving API-proxy, portal, and provider traffic throughout.
run must return promptly once its context is cancelled: the next leader may already be reconciling.
Types ¶
type Options ¶
type Options struct {
// Config must already target the workspace holding the Lease (i.e. its
// Host carries the /clusters/<path> segment).
Config *rest.Config
// Namespace and Name identify the Lease object.
Namespace string
Name string
// Identity distinguishes this replica. Defaults to the pod hostname plus
// the process ID, which stays unique if two replicas ever share a host.
Identity string
LeaseDuration time.Duration
RenewDeadline time.Duration
RetryPeriod time.Duration
}
Options configures a single election.