Skip to main content

LeaderElector

@webda/kubernetes


Class: LeaderElector

Defined in: kubernetes/src/operator/leader.ts:57

Leader election on a coordination.k8s.io Lease

Every retry period, the candidate creates the Lease, renews it when it holds it, or takes it over when it expired. Writes use the Lease resourceVersion: two candidates never both win. A leader that fails to renew stops leading at once, before its lease can expire for the others.

Constructors​

Constructor​

new LeaderElector(api, options, callbacks): LeaderElector

Defined in: kubernetes/src/operator/leader.ts:72

Parameters​

api​

ObjectCoordinationV1Api

the coordination API

options​

LeaderElectionOptions

the lease and timings

callbacks​

LeaderCallbacks

leadership changes

Returns​

LeaderElector

Properties​

api​

protected api: ObjectCoordinationV1Api

Defined in: kubernetes/src/operator/leader.ts:73

the coordination API


callbacks​

protected callbacks: LeaderCallbacks

Defined in: kubernetes/src/operator/leader.ts:75

leadership changes


leading​

leading: boolean = false

Defined in: kubernetes/src/operator/leader.ts:65

Whether this candidate holds the lease


leaseDuration​

protected leaseDuration: number

Defined in: kubernetes/src/operator/leader.ts:60


options​

protected options: LeaderElectionOptions

Defined in: kubernetes/src/operator/leader.ts:74

the lease and timings


retryPeriod​

protected retryPeriod: number

Defined in: kubernetes/src/operator/leader.ts:61


running​

protected running: boolean = false

Defined in: kubernetes/src/operator/leader.ts:59


timer?​

protected optional timer?: Timeout

Defined in: kubernetes/src/operator/leader.ts:58

Methods​

attempt()​

protected attempt(): Promise<void>

Defined in: kubernetes/src/operator/leader.ts:117

Acquire or renew the lease once, then schedule the next attempt

Returns​

Promise<void>


setLeading()​

protected setLeading(leading): Promise<void>

Defined in: kubernetes/src/operator/leader.ts:135

Change the leadership, calling the callbacks

Parameters​

leading​

boolean

whether this candidate leads

Returns​

Promise<void>


start()​

start(): Promise<void>

Defined in: kubernetes/src/operator/leader.ts:85

Start competing for the lease

Returns​

Promise<void>

once the first attempt is done


stop()​

stop(): Promise<void>

Defined in: kubernetes/src/operator/leader.ts:93

Stop competing, releasing the lease when held

Returns​

Promise<void>


tryAcquireOrRenew()​

protected tryAcquireOrRenew(): Promise<boolean>

Defined in: kubernetes/src/operator/leader.ts:145

Create, renew or take over the lease

Returns​

Promise<boolean>

whether this candidate holds the lease