~/bend-docscommunity

src/kube.bend relies on unsafe/foreign

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

Definitions

def Opts.default source · line 39 · 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), and 50 requests a second with bursts of 100.

def Opts.with_leader source · line 42 · raw

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

def Opts.with_election source · line 50 · 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 55 · raw

@o:Opts -> @lo:0x2c4c1c49bdb5ccfc58560ac0a132da8e/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 60 · raw

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

def Opts.with_max source · line 65 · raw

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

def Opts.with_port source · line 70 · raw

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

def Opts.with_grace source · line 75 · raw

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

def Opts.with_rate source · line 81 · raw

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

qps 0 turns the rate limit off.

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

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

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

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

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

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

def Kube.serve source · line 105 · raw

@+port:U32 -> @+status:Chan(0x2c4c1c49bdb5ccfc58560ac0a132da8e/src/runtime.SMsg) -> @+meter:Chan(0x2c4c1c49bdb5ccfc58560ac0a132da8e/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 111 · 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 117 · raw

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

def Kube.ident source · line 130 · raw

IO(String)

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

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

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

def Kube.elect source · line 144 · raw

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

def Kube.pool source · line 168 · raw

IO(Chan(Socket))

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

def Kube.limited source · line 171 · raw

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

def Kube.rate source · line 179 · raw

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

def Opts.ctrl source · line 215 · raw

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

Templates

template Kube.start source · line 153 · raw

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

template Kube.pooled source · line 184 · raw

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

template Kube.control_with source · line 191 · raw

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

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

template Kube.control_all source · line 206 · raw

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

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

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

template Kube.run source · line 222 · raw

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

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