~/bend-docscommunity

src/runtime.bend relies on unsafe/foreign

raw source on the hub · import bend-kube-runtime@0.1.1.0/src/runtime.bend as Runtime

12 imports
import Base
import ./json.bend as J
import ./utf8.bend as U
import ./http.bend as H
import ./core.bend as C
import ./config.bend as K
import ./net.bend as N
import ./client.bend as Cl
import ./watcher.bend as W
import ./store.bend as S
import ./queue.bend as Q
import ./log.bend as L

Types

type Msg source · line 27 · raw

Data

type Snap source · line 33 · raw

Data

The controller's state as the health server reports it.

type SMsg source · line 40 · raw

Data

The status keeper's inbox: a controller's latest snapshot (by its index), or a query for all of them (none until a controller runs: a standby replica).

type Stats source · line 45 · raw

Data

Counters since start.

type Sub source · line 53 · raw

Data

Who a watcher feeds: each subscriber's inbox, and the source number the outputs carry there (0 for a controller's primary, 1.. for its owned).

type WCtx source · line 56 · raw

Data

type DEv source · line 60 · raw

Type

What the driver just saw.

type Dig source · line 97 · raw

Data

After a recv: the stream's state, and the step its whole lines make.

type CState source · line 294 · raw

Data

type CCtx source · line 297 · raw

Data

type Job source · line 301 · raw

Data

A reconcile to start: the key and the object the store holds for it.

type CEv source · line 305 · raw

Type

What the controller loop just saw.

type Ctrl source · line 644 · raw

Data

A controller of a manager: its primary watch (with a label selector), the kinds it owns, and how many reconciles it runs at once. A manager's reconcile gets the controller's index (its place in the list) first.

type Watch source · line 647 · raw

Data

Definitions

def DEv.recv source · line 69 · raw

@p:Pair(Socket, Result<&1, &1, Pair(U32, String), List<&2, U32>>) -> DEv

def Drv.inputs source · line 75 · raw

@ls:List<&2, List<&2, U32>> -> List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Input>

The inputs a run of watch lines makes; blank lines are skipped.

def Drv.inputs.par source · line 87 · raw

@+depth:Nat -> @+ls:List<&2, List<&2, U32>> -> List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Input>

The same, with the lines decoded and parsed in parallel: each line is its own JSON document, so the halves split (to depth levels, up to 2^depth tasks) run as Bend parallel calls, on every core.

def Drv.status source · line 100 · raw

@r:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> U32

def Drv.ended source · line 107 · raw

@r:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> Bool

def Drv.digest.end.go source · line 118 · raw

@st:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.WState -> @outs:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Out> -> @+wait:Bool -> @r:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> @carry:List<&2, U32> -> @+end:Bool -> Dig

def Drv.digest.end source · line 127 · raw

@s:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Step -> @r:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> @carry:List<&2, U32> -> @+end:Bool -> Dig

A stream that ended cleanly is a watch timeout: the watcher resumes.

def Drv.digest.fin source · line 132 · raw

@st:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.WState -> @r:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> @cl:Pair(List<&2, U32>, List<&2, List<&2, U32>>) -> @+end:Bool -> Dig

def Drv.digest.lines source · line 139 · raw

@st:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.WState -> @rb:Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp, List<&2, U32>) -> @carry:List<&2, U32> -> @+eof:Bool -> Dig

def Drv.digest.ok source · line 145 · raw

@st:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.WState -> @r:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> @carry:List<&2, U32> -> @+eof:Bool -> @+code:U32 -> @ok:Bool -> Dig

def Drv.digest.go source · line 153 · raw

@st:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.WState -> @r:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> @carry:List<&2, U32> -> @+eof:Bool -> @+code:U32 -> Dig

def Drv.digest source · line 156 · raw

@st:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.WState -> @+r:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> @carry:List<&2, U32> -> @+eof:Bool -> Dig

def Drv.send source · line 159 · raw

@chan:Chan(Msg) -> @+src:U32 -> @outs:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Out> -> IO(Unit)

def Drv.send_all source · line 168 · raw

@subs:List<&2, Sub> -> @+outs:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Out> -> IO(Unit)

Hands the outputs to every subscriber (a shared watch fans out).

def Drv.jitter source · line 175 · raw

@+ms:U32 -> @r:Result<&1, &1, Pair(U32, String), U32> -> U32

def Drv.pause.go source · line 182 · raw

@+ms:U32 -> @+fails:U32 -> @path:String -> IO(Unit)

def Drv.pause source · line 188 · raw

@wait:Bool -> @+fails:U32 -> @path:String -> IO(Unit)

Sleeps the watcher's backoff, with up to 50% jitter, when asked to.

def Drv.note_list source · line 197 · raw

@first:Bool -> @path:String -> IO(Unit)

A list from its first page (startup, or a relist after 410 Gone).

def Drv.close source · line 204 · raw

@s:Maybe<&1, Socket> -> IO(Unit)

def WState.fails source · line 211 · raw

@s:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.WState -> U32

def WCtx.list_req source · line 216 · raw

@c:WCtx -> @cont:String -> 0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Req

def WCtx.watch_req source · line 221 · raw

@c:WCtx -> @rv:String -> 0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Req

def WCtx.path source · line 226 · raw

@c:WCtx -> String

def WCtx.cfg source · line 231 · raw

@c:WCtx -> 0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config

def WCtx.subs source · line 236 · raw

@c:WCtx -> List<&2, Sub>

def Drv.run source · line 243 · raw

@fuel:Nat -> @ev:DEv -> @+st:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.WState -> @+resp:0x7222ee9dc1fb2fecc4a955ab3997433b/src/http.Resp -> @+carry:List<&2, U32> -> @+ctx:WCtx -> IO(Unit)

The watcher's loop: list, then watch and stream, reconnecting and relisting as the state machine says, until the fuel or the channel ends.

def Ctl.self_keys source · line 312 · raw

@outs:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Out> -> List<&2, String>

The keys a primary watcher's outputs trigger: every object it applies. Deletions trigger nothing; finalizers are how a reconciler sees them.

def Ctl.gone_keys source · line 324 · raw

@outs:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Out> -> List<&2, String>

The keys of objects a primary watcher saw deleted.

def Ctl.ref_keys source · line 333 · raw

@rs:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.ObjRef> -> List<&2, String>

def Ctl.out_obj source · line 340 · raw

@o:0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Out -> Maybe<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json>

def Ctl.owner_keys.put source · line 351 · raw

@m:Maybe<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json> -> @+kind:String -> @rest:List<&2, String> -> List<&2, String>

def Ctl.owner_keys source · line 362 · raw

@outs:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Out> -> @+kind:String -> List<&2, String>

The keys an owned watcher's outputs trigger: the owners of the kind every changed object names (kube-runtime's Controller::owns), deletions included.

def Stats.count source · line 369 · raw

@+n:Nat -> U32

def Stats.events source · line 372 · raw

@x:Stats -> @+n:U32 -> Stats

def Stats.done source · line 377 · raw

@x:Stats -> @a:0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Action -> Stats

def Ctl.on_outs source · line 384 · raw

@st:CState -> @+src:U32 -> @+outs:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/watcher.Out> -> @+kind:String -> @own:Bool -> CState

def Ctl.on_done source · line 394 · raw

@s:0x7222ee9dc1fb2fecc4a955ab3997433b/src/store.Store -> @x:Stats -> @r:Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Timer>) -> Pair(CState, List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Timer>)

def Ctl.on_done.st source · line 400 · raw

@st:CState -> @key:String -> @+a:0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Action -> Pair(CState, List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Timer>)

def Ctl.on_wake source · line 405 · raw

@st:CState -> @key:String -> @g:U32 -> Pair(CState, List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Timer>)

def Ctl.on_msg source · line 411 · raw

@st:CState -> @m:Msg -> @+kind:String -> Pair(CState, List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Timer>)

A message's effect on the state, and the timers it arms.

def Ctl.dispatch.drop source · line 420 · raw

@r:Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Timer>) -> @jobs:List<&2, Job> -> Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, Job>)

def Ctl.dispatch.put source · line 426 · raw

@+key:String -> @m:Maybe<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json> -> @q:0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue -> @jobs:List<&2, Job> -> Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, Job>)

def Ctl.dispatch.acc source · line 435 · raw

@+k:String -> @m:Maybe<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json> -> @acc:Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, Job>) -> Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, Job>)

def Ctl.dispatch.go source · line 441 · raw

@ks:List<&2, String> -> @+s:0x7222ee9dc1fb2fecc4a955ab3997433b/src/store.Store -> @acc:Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, Job>) -> Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, Job>)

def Ctl.dispatch.wrap source · line 449 · raw

@s:0x7222ee9dc1fb2fecc4a955ab3997433b/src/store.Store -> @x:Stats -> @r:Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, Job>) -> Pair(CState, List<&2, Job>)

def Ctl.dispatch.fin source · line 454 · raw

@+s:0x7222ee9dc1fb2fecc4a955ab3997433b/src/store.Store -> @x:Stats -> @r:Pair(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue, List<&2, String>) -> Pair(CState, List<&2, Job>)

def Ctl.dispatch.ready source · line 460 · raw

@+s:0x7222ee9dc1fb2fecc4a955ab3997433b/src/store.Store -> @q:0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Queue -> @x:Stats -> @ready:Bool -> Pair(CState, List<&2, Job>)

def Ctl.dispatch source · line 468 · raw

@st:CState -> Pair(CState, List<&2, Job>)

The reconciles to start now: none until the store has its first list.

def Ctl.snap source · line 473 · raw

@st:CState -> @name:String -> Snap

def Ctl.timers source · line 478 · raw

@ts:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Timer> -> @+chan:Chan(Msg) -> IO(Unit)

def CCtx.chan source · line 489 · raw

@c:CCtx -> Chan(Msg)

def CCtx.cfg source · line 494 · raw

@c:CCtx -> 0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config

def CCtx.status source · line 499 · raw

@c:CCtx -> Chan(SMsg)

def CCtx.idx source · line 504 · raw

@c:CCtx -> U32

def CCtx.kind source · line 509 · raw

@c:CCtx -> String

def Ctl.watch.subs source · line 548 · raw

@+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @api:0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api -> @label:String -> @subs:List<&2, Sub> -> IO(Unit)

def Ctl.watch source · line 552 · raw

@+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @api:0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api -> @label:String -> @+src:U32 -> @+chan:Chan(Msg) -> IO(Unit)

def Ctl.watch_all source · line 556 · raw

@apis:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api> -> @+n:U32 -> @+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @+chan:Chan(Msg) -> IO(Unit)

def Api.kind source · line 564 · raw

@a:0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api -> String

def Keeper.all.put source · line 569 · raw

@r:Pair(Map<&2, Snap>, Snap) -> @rest:List<&2, Snap> -> List<&2, Snap>

def Keeper.all.go source · line 574 · raw

@ks:List<&2, String> -> @+m:Map<&2, Snap> -> List<&2, Snap>

def Keeper.all source · line 581 · raw

@+m:Map<&2, Snap> -> List<&2, Snap>

def Keeper.run source · line 586 · raw

@fuel:Nat -> @m:Maybe<&1, SMsg> -> @+last:Map<&2, Snap> -> @+inbox:Chan(SMsg) -> IO(Unit)

The status keeper: holds each controller's latest snapshot and answers queries at once.

def Keeper.start source · line 601 · raw

IO(Chan(SMsg))

Starts a status keeper; answers its inbox.

def Controller.inbox source · line 629 · raw

IO(Chan(Msg))

def Watch.key source · line 650 · raw

@+api:0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api -> @+label:String -> String

def Plan.hit source · line 653 · raw

@ws:List<&2, Watch> -> @+key:String -> Bool

def Plan.add source · line 661 · raw

@ws:List<&2, Watch> -> @+api:0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api -> @+label:String -> @+sub:Sub -> @hit:Bool -> List<&2, Watch>

Adds a subscription: to the watch of the same key, or as a new watch.

def Plan.sub source · line 670 · raw

@+ws:List<&2, Watch> -> @+api:0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api -> @+label:String -> @+sub:Sub -> List<&2, Watch>

def Plan.owned source · line 673 · raw

@os:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api> -> @+ch:Chan(Msg) -> @+n:U32 -> @ws:List<&2, Watch> -> List<&2, Watch>

def Plan.build source · line 681 · raw

@cs:List<&2, Ctrl> -> @chs:List<&2, Chan(Msg)> -> @ws:List<&2, Watch> -> List<&2, Watch>

Every watch the controllers need, each once, with all its subscribers.

def Manager.inboxes source · line 688 · raw

@cs:List<&2, Ctrl> -> IO(List<&2, Chan(Msg)>)

def Manager.watch source · line 697 · raw

@+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @ws:List<&2, Watch> -> IO(Unit)

Templates

template Ctl.spawn source · line 515 · raw

@-rec:(@_:U32 -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> IO(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Action)) -> @jobs:List<&2, Job> -> @+chan:Chan(Msg) -> @+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @+idx:U32 -> IO(Unit)

Starts a reconcile per job; each answers MDone on the channel.

template Ctl.run source · line 529 · raw

@-rec:(@_:U32 -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> IO(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Action)) -> @fuel:Nat -> @ev:CEv -> @+st:CState -> @+ctx:CCtx -> IO(Unit)

The controller loop: a message in, the state stepped, timers armed, reconciles started, the next message awaited.

template Ctl.loop source · line 607 · raw

@-rec:(@_:U32 -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> IO(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Action)) -> @+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @+primary:0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api -> @+max:U32 -> @+chan:Chan(Msg) -> @+status:Chan(SMsg) -> @+idx:U32 -> IO(Unit)

template Controller.start source · line 621 · raw

@-rec:(@_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> IO(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Action)) -> @+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @+primary:0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api -> @label:String -> @owned:List<&2, 0x7222ee9dc1fb2fecc4a955ab3997433b/src/core.Api> -> @+max:U32 -> @+chan:Chan(Msg) -> @+status:Chan(SMsg) -> IO(Unit)

Runs a controller (kube-runtime's Controller::new(..).owns(..).run(..)): primary is watched (only objects matching the label selector, "" for all) and reconciled, each of owned is watched and mapped to its owners of primary's kind; at most max reconciles run at once. rec answers what to do next for the object, as kube-runtime's Action. chan is the controller's inbox (Controller.inbox); status receives a snapshot after every step (Keeper.start).

template Manager.loops source · line 704 · raw

@-rec:(@_:U32 -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> IO(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Action)) -> @+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @cs:List<&2, Ctrl> -> @chs:List<&2, Chan(Msg)> -> @+status:Chan(SMsg) -> @+i:U32 -> IO(Unit)

template Manager.start source · line 715 · raw

@-rec:(@_:U32 -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/json.Json -> @_:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> IO(0x7222ee9dc1fb2fecc4a955ab3997433b/src/queue.Action)) -> @+cfg:0x7222ee9dc1fb2fecc4a955ab3997433b/src/config.Config -> @+cs:List<&2, Ctrl> -> @+status:Chan(SMsg) -> IO(Unit)

Runs every controller, sharing their watches. rec(i, obj, cfg) reconciles obj for controller i.