src/leader.bend relies on unsafe/foreign
raw source on the hub · import bend-kube-runtime@0.5.4.0/src/leader.bend as Leader
9 imports
import Base import ./json.bend as J import ./core.bend as C import ./config.bend as K import ./client.bend as Cl import ./time.bend as T import ./sys.bend as Y import ./log.bend as L import ./lease.bend as E
Types
type LOpts source · line 20 · raw
Data
LOpts@ns:String -> @name:String -> @id:String -> @dur:U32 -> @deadline:U32 -> @retry:U32 -> LOpts
type LEv source · line 75 · raw
Type
What the loop just saw.
LTryLEv
LAt@w:0xab6da4e9d8da6541d5508a9052c594cb/src/time.Wall -> @mono:U32 -> LEv
LRead@w:0xab6da4e9d8da6541d5508a9052c594cb/src/time.Wall -> @mono:U32 -> @r:Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json> -> LEv
LDecided@now:U32 -> @d:Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/lease.Decision> -> LEv
LCheck@now:U32 -> @ok:Bool -> LEv
LWrote@now:U32 -> @ok:Bool -> @late:Bool -> LEv
LFail@stop:Bool -> LEv
Definitions
def LOpts.default source · line 23 · raw
@ns:String -> @name:String -> @id:String -> LOpts
def LOpts.api source · line 26 · raw
@o:LOpts -> 0xab6da4e9d8da6541d5508a9052c594cb/src/core.Api
def LOpts.id source · line 31 · raw
@o:LOpts -> String
def LOpts.name source · line 36 · raw
@o:LOpts -> String
def LOpts.retry source · line 41 · raw
@o:LOpts -> U32
def LOpts.deadline source · line 46 · raw
@o:LOpts -> U32
def Leader.read.err source · line 51 · raw
@e:0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr -> @missing:Bool -> Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, Maybe<&2, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json>>
def Leader.read source · line 59 · raw
@r:Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json> -> Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, Maybe<&2, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json>>
The Lease read: Some, None on 404, or the error.
def Leader.decide source · line 66 · raw
@r:Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, Maybe<&2, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json>> -> @+o:LOpts -> @+obs:0xab6da4e9d8da6541d5508a9052c594cb/src/lease.Obs -> @+mono:U32 -> @+w:0xab6da4e9d8da6541d5508a9052c594cb/src/time.Wall -> Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/lease.Decision>
def Leader.wrote source · line 84 · raw
@r:Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json> -> Bool
def Leader.timed.of source · line 87 · raw
@m:Maybe<&1, Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json>> -> Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json>
def Leader.timed source · line 95 · raw
@+ms:U32 -> @act:IO(Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json>) -> IO(Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json>)
A lease call that takes longer than ms fails.
def Leader.mono source · line 104 · raw
IO(U32)
The monotonic clock in ms (never stepped; wrapped subtraction handles its 49.7-day wrap): every timing decision (expiry, the renew deadline, lateness) uses it; the wall clock only stamps the Lease.
def Leader.started source · line 108 · raw
@leading:Bool -> @start:Maybe<&1, IO(Unit)> -> IO(Unit)
On first acquiring: log and start the work.
def Leader.lost source · line 117 · raw
IO(Unit)
A leader that cannot renew within the deadline stops at once (a candidate that fails just tries again).
def Leader.fence.put source · line 120 · raw
@p:Poll<&1, &1, Maybe<&1, 0xab6da4e9d8da6541d5508a9052c594cb/src/config.Fence>, Unit> -> @+ch:Chan(0xab6da4e9d8da6541d5508a9052c594cb/src/config.Fence) -> @+f:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Fence -> IO(Unit)
def Leader.fence source · line 126 · raw
@m:Maybe<&2, Chan(0xab6da4e9d8da6541d5508a9052c594cb/src/config.Fence)> -> @+f:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Fence -> IO(Unit)
Moves the leadership fence (K.Config.fence) to a renewal: the controllers' requests check it, so none leaves once this renewal is past the deadline.
def Leader.renewed source · line 137 · raw
@late:Bool -> @go:IO(Unit) -> IO(Unit)
A leader's renewal that landed only after the renew deadline counts as lost (client-go's RenewDeadline): a standby may already have judged the lease expired.
def Leader.run source · line 145 · raw
@outer:Nat -> @fuel:Nat -> @ev:LEv -> @+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @+obs:0xab6da4e9d8da6541d5508a9052c594cb/src/lease.Obs -> @+leading:Bool -> @+last:U32 -> @start:Maybe<&1, IO(Unit)> -> IO(Unit)
The election loop. start runs once, when the lease is first ours.
def Leader.release.said source · line 211 · raw
@r:Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json> -> IO(Bool)
def Leader.release.mine source · line 219 · raw
@+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @l:0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json -> @mine:Bool -> IO(Bool)
def Leader.release.got source · line 229 · raw
@r:Result<&2, &2, 0xab6da4e9d8da6541d5508a9052c594cb/src/client.KErr, 0xab6da4e9d8da6541d5508a9052c594cb/src/json.Json> -> @+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @w:0xab6da4e9d8da6541d5508a9052c594cb/src/time.Wall -> IO(Bool)
Hands the lease back if it is ours; answers whether there is nothing left to do.
def Leader.release.once source · line 240 · raw
@+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> IO(Bool)
def Leader.release.again source · line 245 · raw
@n:Nat -> @+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @done:Bool -> IO(Unit)
def Leader.release.timed source · line 252 · raw
@m:Maybe<&1, Unit> -> IO(Unit)
def Leader.release source · line 261 · raw
@+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> IO(Unit)
Hands the lease back, reading it afresh and trying again if a renewal raced the write (a 409), up to three times, within 4s in all.
def Leader.again source · line 266 · raw
IO(Unit)
A second SIGTERM or SIGINT while draining exits at once.
def Leader.handover source · line 273 · raw
@+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @drained:Bool -> IO(Unit)
The lease goes back only after a clean drain. A reconcile still running past the grace period could otherwise overlap the next leader's; the process exits holding the lease, which expires after its duration.
def Leader.on_signal source · line 283 · raw
@+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @drain:IO(Bool) -> IO(Unit)
On SIGTERM or SIGINT: drain (stop starting reconciles and wait for the running ones, up to the grace period), hand the lease back if nothing is left running, then exit 0; a second signal exits at once.
def Leader.elect.go source · line 291 · raw
@+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @drain:IO(Bool) -> @work:IO(Unit) -> IO(Unit)
Runs work only while we hold the lease (client-go's RunOrDie); drain runs on SIGTERM before the lease is handed back.
def LOpts.check source · line 295 · raw
@o:LOpts -> Maybe<&2, String>
def Leader.elect.ok source · line 300 · raw
@+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @drain:IO(Bool) -> @work:IO(Unit) -> @bad:Maybe<&2, String> -> IO(Unit)
def Leader.elect source · line 311 · raw
@+cfg:0xab6da4e9d8da6541d5508a9052c594cb/src/config.Config -> @+o:LOpts -> @drain:IO(Bool) -> @work:IO(Unit) -> IO(Unit)
Runs work only while we hold the lease (client-go's RunOrDie), after checking the timing is safe (Lease.timing); drain runs on SIGTERM before the lease is handed back.