leaderelection

package
v0.2.31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
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 ControllerOptions added in v0.2.25

func ControllerOptions() config.Controller

ControllerOptions permits rebuilding controllers across sequential leadership terms. controller-runtime's default name registry is process-global and never forgets stopped controllers. Use only for managers owned by Run's callback: Run waits for the previous callback to finish before starting the next term. Callers must keep controller names distinct within each term. Skipping validation disables that check even within one manager; duplicates would silently share metrics and log labels.

func Run

func Run(ctx context.Context, opts Options, run func(context.Context)) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL