~/bend-docscommunity

src/kube.bend relies on unsafe/foreign

raw source on the hub · import bend-kube-runtime@0.7.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).

type Pool source · line 165 · raw

Data

Connection pools for other clusters, one per cluster and identity (K.Config.ident), shared by every watch and reconcile that talks to it and never across servers: a pool holds connections to one server.

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:0x4f5f473f9903832811734f64f633d6d3/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(0x4f5f473f9903832811734f64f633d6d3/src/runtime.SMsg) -> @+meter:Chan(0x4f5f473f9903832811734f64f633d6d3/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(0x4f5f473f9903832811734f64f633d6d3/src/runtime.SMsg) -> @+meter:Chan(0x4f5f473f9903832811734f64f633d6d3/src/control.Meter) -> IO(Unit)

def Kube.serve source · line 116 · raw

@+port:U32 -> @+status:Chan(0x4f5f473f9903832811734f64f633d6d3/src/runtime.SMsg) -> @+meter:Chan(0x4f5f473f9903832811734f64f633d6d3/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:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> @lo:0x4f5f473f9903832811734f64f633d6d3/src/leader.LOpts -> @drain:IO(Bool) -> @work:IO(Unit) -> @auto:Bool -> IO(Unit)

def Kube.elect source · line 155 · raw

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

def Pool.has source · line 168 · raw

@ps:List<&2, Pool> -> @+id:String -> Bool

def Pool.pick source · line 175 · raw

@hit:Bool -> @p:Chan(Socket) -> @rest:Maybe<&2, Chan(Socket)> -> Maybe<&2, Chan(Socket)>

def Pool.find source · line 182 · raw

@ps:List<&2, Pool> -> @+id:String -> Maybe<&2, Chan(Socket)>

def Pool.cfg_in source · line 189 · raw

@cs:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config> -> @+id:String -> Bool

def Pool.keep source · line 196 · raw

@+c:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> @dup:Bool -> @rest:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config> -> List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config>

def Pool.unique source · line 204 · raw

@cs:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config> -> List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config>

One config per cluster and identity.

def Pool.of_on source · line 211 · raw

@m:Maybe<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config> -> @rest:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config> -> List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config>

def Pool.of_secs source · line 218 · raw

@ss:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/control.Sec> -> List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config>

def Pool.of_specs source · line 226 · raw

@ss:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/control.Spec> -> List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config>

Every other cluster the specs watch, in order, repeats included.

def Pool.attach.got source · line 233 · raw

@+c:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> @m:Maybe<&2, Chan(Socket)> -> 0x4f5f473f9903832811734f64f633d6d3/src/config.Config

def Pool.attach source · line 240 · raw

@m:Maybe<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config> -> @+ps:List<&2, Pool> -> Maybe<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config>

def Pool.attach_secs source · line 247 · raw

@ss:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/control.Sec> -> @+ps:List<&2, Pool> -> List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/control.Sec>

def Pool.attach_specs source · line 254 · raw

@ss:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/control.Spec> -> @+ps:List<&2, Pool> -> List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/control.Spec>

def Kube.pools source · line 262 · raw

@cs:List<&2, 0x4f5f473f9903832811734f64f633d6d3/src/config.Config> -> IO(List<&2, Pool>)

A new pool for each config.

def Kube.pool_specs source · line 272 · raw

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

The specs with every other cluster's config on its cluster's pool.

def Kube.timeouts source · line 276 · raw

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

def Kube.pool source · line 307 · raw

IO(Chan(Socket))

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

def Kube.limited source · line 310 · raw

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

def Kube.connect source · line 321 · raw

@+cfg:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> @+qps:U32 -> @+burst:U32 -> IO(0x4f5f473f9903832811734f64f633d6d3/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 324 · raw

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

def Opts.elects source · line 329 · raw

@o:Opts -> Bool

def Kube.fenced source · line 336 · raw

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

def Kube.fence source · line 345 · raw

@on:Bool -> IO(Maybe<&2, Chan(0x4f5f473f9903832811734f64f633d6d3/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 407 · raw

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

Templates

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

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

template Kube.start source · line 299 · raw

@-rec:(@_:0x4f5f473f9903832811734f64f633d6d3/src/json.Json -> @_:0x4f5f473f9903832811734f64f633d6d3/src/control.Ctx -> IO(0x4f5f473f9903832811734f64f633d6d3/src/queue.Action)) -> @-map:(@_:U32 -> @_:0x4f5f473f9903832811734f64f633d6d3/src/json.Json -> @_:0x4f5f473f9903832811734f64f633d6d3/src/control.Ctx -> List<&2, String>) -> @+cfg:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> @+ecfg:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> @specs:List<&2, 0x4f5f473f9903832811734f64f633d6d3/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 353 · raw

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

template Kube.control_with_mapped source · line 363 · raw

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

Kube.control_with, with the controllers' mapper for RMap relations: map(n, obj, ctx) names the primaries an object of the n-th related watch triggers (kube-runtime's watches(.., mapper)). It is pure and runs in the controller loop, after each batch, against the caches in ctx.

template Kube.control_with source · line 371 · raw

@-rec:(@_:0x4f5f473f9903832811734f64f633d6d3/src/json.Json -> @_:0x4f5f473f9903832811734f64f633d6d3/src/control.Ctx -> IO(0x4f5f473f9903832811734f64f633d6d3/src/queue.Action)) -> @cfg:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> @specs:List<&2, 0x4f5f473f9903832811734f64f633d6d3/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 375 · raw

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

template Kube.control_all_mapped source · line 384 · raw

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

Kube.control_all with the controllers' mapper (Kube.control_with_mapped).

template Kube.control_all source · line 391 · raw

@-rec:(@_:0x4f5f473f9903832811734f64f633d6d3/src/json.Json -> @_:0x4f5f473f9903832811734f64f633d6d3/src/control.Ctx -> IO(0x4f5f473f9903832811734f64f633d6d3/src/queue.Action)) -> @specs:List<&2, 0x4f5f473f9903832811734f64f633d6d3/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_mapped source · line 399 · raw

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

One controller whose related watches may map objects by code (X.Spec.watches(s, api, X.RMap{})): map(n, obj, ctx) answers the primary keys ("ns/name", or "name") that obj, of the n-th related watch, triggers.

template Kube.control source · line 404 · raw

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

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

template Kube.run source · line 414 · raw

@-rec:(@_:0x4f5f473f9903832811734f64f633d6d3/src/json.Json -> @_:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> IO(0x4f5f473f9903832811734f64f633d6d3/src/queue.Action)) -> @primary:0x4f5f473f9903832811734f64f633d6d3/src/core.Api -> @owned:List<&2, 0x4f5f473f9903832811734f64f633d6d3/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 420 · raw

@-rec:(@_:U32 -> @_:0x4f5f473f9903832811734f64f633d6d3/src/json.Json -> @_:0x4f5f473f9903832811734f64f633d6d3/src/config.Config -> IO(0x4f5f473f9903832811734f64f633d6d3/src/queue.Action)) -> @cs:List<&2, 0x4f5f473f9903832811734f64f633d6d3/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.