Documentation
¶
Index ¶
Constants ¶
const EpochAnnotation = "haptic.io/leader-epoch"
EpochAnnotation carries the fencing epoch on the leader Lease.
Variables ¶
var ErrForeignLeader = errors.New("the lease is held at a newer epoch")
ErrForeignLeader reports that the Lease names another holder, or an epoch this controller never claimed: a newer leader owns the fleet.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component is an event adapter that wraps the pure leader election component and publishes events for observability.
This is the coordination layer that connects the pure k8s/leaderelection package to the controller's event bus.
func New ¶
func New( config *k8sleaderelection.Config, clientset kubernetes.Interface, eventBus *busevents.EventBus, callbacks k8sleaderelection.Callbacks, epoch *Term, logger *slog.Logger, ) (*Component, error)
New creates a new leader election component.
This function wraps the pure leader election elector and adds event publishing for observability. The callbacks provided by the caller are wrapped to also publish events before/after the callback executes. epoch may be nil, in which case no fencing epoch is claimed; the deployer then dispatches at epoch zero, which is correct only for a single writer.
func (*Component) KeepLeaseOnStop ¶
func (c *Component) KeepLeaseOnStop()
KeepLeaseOnStop makes the loop's stop leave the Lease held, for a successor iteration on this replica to resume without any other replica seeing a vacancy.
func (*Component) ReleaseLease ¶
func (c *Component) ReleaseLease()
ReleaseLease vacates a Lease kept for a successor that will not run.
type LeaseEpoch ¶
type LeaseEpoch struct {
// contains filtered or unexported fields
}
LeaseEpoch is the fencing epoch of this controller's leadership terms: a counter on the leader Lease that each term increments before it dispatches anything. Every apply carries it, and a pod that has accepted a higher epoch refuses lower ones — so a controller that lost the lease but has not noticed yet cannot write over its successor.
The Lease's own fields are not usable for this: the identity is the pod name, so client-go carries AcquireTime and LeaderTransitions across a same-identity re-acquire.
func NewLeaseEpoch ¶
func NewLeaseEpoch(client kubernetes.Interface, namespace, name, identity string, logger *slog.Logger) *LeaseEpoch
NewLeaseEpoch builds the epoch source for one Lease.
func (*LeaseEpoch) Bump ¶
func (e *LeaseEpoch) Bump(ctx context.Context) error
Bump claims the next epoch by incrementing the Lease annotation, retrying the read-modify-write while another writer wins the race. It must complete before this term dispatches: an unclaimed epoch is refused by every pod that has seen a higher one, which stalls deployments rather than corrupting them.
func (*LeaseEpoch) Identity ¶
func (e *LeaseEpoch) Identity() string
Identity is this controller's leader-election identity.
func (*LeaseEpoch) LeaderEpoch ¶
func (e *LeaseEpoch) LeaderEpoch() uint64
LeaderEpoch is the epoch this controller last claimed. Zero means it has claimed none, which every pod's fence outranks.
func (*LeaseEpoch) Reclaim ¶
Reclaim lifts this controller's epoch past one a pod has already accepted. A pod outranking the leader means the counter regressed — a Lease that was deleted, recreated or restored from a backup loses the annotation — so the Lease is re-read: while it still names this holder at the epoch this term claimed, no rival exists and the annotation is raised to floor+1. It reports ErrForeignLeader when the Lease proves otherwise, which is the one case where the pod is right and this controller must stop writing.
type Term ¶
type Term struct {
*LeaseEpoch
// contains filtered or unexported fields
}
Term is one leadership term as its writers see it: the identity and epoch every apply carries, and the way to hand the term back when something proves this controller is not the fleet's writer any more.
func NewTerm ¶
func NewTerm(epoch *LeaseEpoch, standDown func(reason string)) *Term
NewTerm binds the term's epoch to the way its holder gives leadership up. standDown must release the Lease — only a fresh acquisition claims a fresh epoch, so anything short of it leaves this replica elected and refused.