~/bend-docscommunity

src/kube.bend relies on unsafe/foreign

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

12 imports
import Base
import ./json.bend as J
import ./core.bend as C
import ./config.bend as K
import ./client.bend as Cl
import ./queue.bend as Q
import ./control.bend as X
import ./runtime.bend as R
import ./serve.bend as V
import ./leader.bend as E
import ./sys.bend as Y
import ./log.bend as L

Types

type Opts source · line 33 · raw

Data

max: reconciles at once and label: the primary's label selector, both for Kube.run only (a spec carries its own); port: health and metrics (0: off); leader: the Lease to hold while running; grace: how long SIGTERM waits for running reconciles, in ms; qps and burst: the client's rate limit (qps 0: none); timeout: the reconcile timeout of every spec that sets none (X.Spec.timeout), in ms (0: none).

Definitions

def Opts.default source · line 41 · raw

Opts

8 reconciles at once, health and metrics on :8080, no leader election, a 20s grace period (with up to 4s to hand the lease back, inside Kubernetes' default 30s), 50 requests a second with bursts of 100, and no reconcile timeout.

def Opts.with_leader source · line 44 · raw

@o:Opts -> @ns:String -> @name:String -> @id:String -> Opts

def Opts.with_election source · line 52 · raw

@o:Opts -> @ns:String -> @name:String -> Opts

Leader election under a Lease in ns named name, identified as this replica: its HOSTNAME (the pod name) and a random suffix, so two replicas never share an identity. Prefer this to with_leader.

def Opts.with_lease source · line 57 · raw

@o:Opts -> @lo:0x341d8c21d651622b4e114e45f1f37703/src/leader.LOpts -> Opts

Leader election with every setting given (E.LOpts: namespace, name, identity, lease seconds, renew deadline ms, retry ms).

def Opts.with_label source · line 62 · raw

@o:Opts -> @label:String -> Opts

def Opts.with_max source · line 67 · raw

@o:Opts -> @max:U32 -> Opts

def Opts.with_port source · line 72 · raw

@o:Opts -> @port:U32 -> Opts

def Opts.with_grace source · line 77 · raw

@o:Opts -> @ms:U32 -> Opts

def Opts.with_timeout source · line 86 · raw

@o:Opts -> @ms:U32 -> Opts

A reconcile timeout, ms, for every spec that sets none (0: none, the default), as controller-runtime's manager-wide ReconciliationTimeout. A spec's own X.Spec.timeout wins. Bend cannot cancel a reconcile, so a reconcile past it exits the process (status 1), as X.Spec.timeout says.

def Opts.with_rate source · line 92 · raw

@o:Opts -> @qps:U32 -> @burst:U32 -> Opts

qps 0 turns the rate limit off.

def Kube.serve.go source · line 97 · raw

@+port:U32 -> @+status:Chan(0x341d8c21d651622b4e114e45f1f37703/src/runtime.SMsg) -> @+meter:Chan(0x341d8c21d651622b4e114e45f1f37703/src/control.Meter) -> @off:Bool -> IO(Unit)

def Kube.port.of source · line 104 · raw

@+port:U32 -> @e:Result<&1, &1, Pair(U32, String), String> -> U32

def Kube.serve.at source · line 111 · raw

@+port:U32 -> @+status:Chan(0x341d8c21d651622b4e114e45f1f37703/src/runtime.SMsg) -> @+meter:Chan(0x341d8c21d651622b4e114e45f1f37703/src/control.Meter) -> IO(Unit)

def Kube.serve source · line 116 · raw

@+port:U32 -> @+status:Chan(0x341d8c21d651622b4e114e45f1f37703/src/runtime.SMsg) -> @+meter:Chan(0x341d8c21d651622b4e114e45f1f37703/src/control.Meter) -> IO(Unit)

The health and metrics port: BEND_KUBE_PORT when set (0 for none), else Opts.port.

def Kube.on_signal source · line 122 · raw

@drain:IO(Bool) -> IO(Unit)

Without leader election: on SIGTERM or SIGINT, drain, then exit 0; a second signal exits at once.

def Kube.ident.of source · line 128 · raw

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

def Kube.ident source · line 141 · raw

IO(String)

This replica's identity: the pod name and a random suffix.

def Kube.elect.as source · line 146 · raw

@+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @lo:0x341d8c21d651622b4e114e45f1f37703/src/leader.LOpts -> @drain:IO(Bool) -> @work:IO(Unit) -> @auto:Bool -> IO(Unit)

def Kube.elect source · line 155 · raw

@+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @l:Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/leader.LOpts> -> @drain:IO(Bool) -> @work:IO(Unit) -> IO(Unit)

def Kube.pool_on source · line 164 · raw

@m:Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/config.Config> -> IO(Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/config.Config>)

Each watch on another cluster gets a pool of its own: a pool holds connections to one API server, never shared across servers.

def Kube.pool_secs source · line 172 · raw

@ss:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Sec> -> IO(List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Sec>)

def Kube.pool_specs source · line 181 · raw

@ss:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec> -> IO(List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec>)

def Kube.timeouts source · line 191 · raw

@ss:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec> -> @+ms:U32 -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec>

def Kube.pool source · line 222 · raw

IO(Chan(Socket))

Up to 8 idle keep-alive connections shared by every request.

def Kube.limited source · line 225 · raw

@+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @+qps:U32 -> @+burst:U32 -> @off:Bool -> IO(0x341d8c21d651622b4e114e45f1f37703/src/config.Config)

def Kube.connect source · line 236 · raw

@+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @+qps:U32 -> @+burst:U32 -> IO(0x341d8c21d651622b4e114e45f1f37703/src/config.Config)

A config for another cluster (X.Spec.on, X.Spec.watch_on) with its own rate limit (qps 0: none), as Kube.control gives the controllers' config; Kube.control gives it its own connection pool.

def Kube.rate source · line 239 · raw

@o:Opts -> @+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> IO(0x341d8c21d651622b4e114e45f1f37703/src/config.Config)

def Opts.elects source · line 244 · raw

@o:Opts -> Bool

def Kube.fenced source · line 251 · raw

@+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @m:Maybe<&2, Chan(0x341d8c21d651622b4e114e45f1f37703/src/config.FenceMsg)> -> 0x341d8c21d651622b4e114e45f1f37703/src/config.Config

def Kube.fence source · line 260 · raw

@on:Bool -> IO(Maybe<&2, Chan(0x341d8c21d651622b4e114e45f1f37703/src/config.FenceMsg)>)

Under leader election, a leadership fence shared by the controllers' config and the election's (Leader.fence, Fence.check in client.bend).

def Opts.ctrl source · line 301 · raw

@o:Opts -> @primary:0x341d8c21d651622b4e114e45f1f37703/src/core.Api -> @owned:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/core.Api> -> 0x341d8c21d651622b4e114e45f1f37703/src/runtime.Ctrl

Templates

template Kube.start.go source · line 198 · raw

@-rec:(@_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/control.Ctx -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @+ecfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @+specs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec> -> @+p:U32 -> @l:Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/leader.LOpts> -> @+grace:U32 -> IO(Unit)

template Kube.start source · line 214 · raw

@-rec:(@_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/control.Ctx -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @+ecfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @specs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec> -> @o:Opts -> IO(Unit)

cfg serves the controllers (rate-limited); ecfg serves leader election, outside the rate limit, so a burst of reconciles never delays a renewal. Every spec without its own reconcile timeout takes Opts.timeout, and every watch on another cluster gets its own connection pool.

template Kube.pooled source · line 268 · raw

@-rec:(@_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/control.Ctx -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @+cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @specs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec> -> @+o:Opts -> IO(Unit)

template Kube.control_with source · line 277 · raw

@-rec:(@_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/control.Ctx -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @cfg:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @specs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec> -> @+o:Opts -> IO(Unit)

Runs controllers against a given config (another cluster, a test server); Kube.control_all infers it. The config gets a connection pool and the rate limit.

template Kube.configured source · line 282 · raw

@-rec:(@_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/control.Ctx -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @c:Result<&2, &2, String, 0x341d8c21d651622b4e114e45f1f37703/src/config.Config> -> @specs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec> -> @+o:Opts -> IO(Unit)

template Kube.control_all source · line 292 · raw

@-rec:(@_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/control.Ctx -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @specs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/control.Spec> -> @o:Opts -> IO(Unit)

Runs several controllers, sharing their watches (Manager): rec(obj, ctx) reconciles obj for controller X.Ctx.idx(ctx), its place in specs.

template Kube.control source · line 298 · raw

@-rec:(@_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/control.Ctx -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @spec:0x341d8c21d651622b4e114e45f1f37703/src/control.Spec -> @o:Opts -> IO(Unit)

Runs one controller (kube-runtime's Controller::new(..).run(..)).

template Kube.run source · line 308 · raw

@-rec:(@_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @primary:0x341d8c21d651622b4e114e45f1f37703/src/core.Api -> @owned:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/core.Api> -> @+o:Opts -> IO(Unit)

Runs a controller for primary, owning owned, reconciling with rec(obj, cfg); Opts.label and Opts.max shape it.

template Kube.run_all source · line 314 · raw

@-rec:(@_:U32 -> @_:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @_:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> IO(0x341d8c21d651622b4e114e45f1f37703/src/queue.Action)) -> @cs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/runtime.Ctrl> -> @o:Opts -> IO(Unit)

Several controllers in one process, sharing their watches: rec(i, obj, cfg) reconciles for the i-th controller of cs.