~/bend-docscommunity

src/control.bend checks

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

6 imports
import Base
import ./json.bend as J
import ./core.bend as C
import ./config.bend as K
import ./watcher.bend as W
import ./store.bend as S

Types

type Pred source · line 44 · raw

Data

type Rel source · line 111 · raw

Data

type Fold source · line 260 · raw

Data

A batch of outputs folded into a cache: the cache after them, the keys they trigger, and the keys deleted.

type Sec source · line 395 · raw

Data

A related watch: what to watch (and its label selector), and how its objects map to primaries.

type Spec source · line 403 · raw

Data

A controller (kube-runtime's Controller::new(..).owns(..).watches(..)): the primary with its label and field selectors, the predicates its changes pass, the related watches, how many reconciles run at once, and how long one may run (timeout ms, 0 for no limit).

type Meter source · line 660 · raw

Data

What a reconcile tells the meter: add n to a counter, set a gauge, or (the health server) ask for every series in the Prometheus text format. labels is the inside of the braces, as kind="x",phase="y" ("" for none).

type Ctx source · line 676 · raw

Data

cfg: the client config; idx: the controller's index (0 for a lone controller); store: the primary's cache; caches: each related watch's, in the order they were added (Ctx.cache(c, 1) is the first); fails: how many times in a row this key's reconcile has failed (0 after a success), so a reconcile can escalate or give up; meter: where the controller's own metrics go (Metrics.add, Metrics.set), None outside Kube.control; clusters: each watch's config, the primary's first (Ctx.cluster).

Definitions

def Pred.part.gen source · line 51 · raw

@+o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @g:String -> @none:Bool -> String

The part of an object a predicate looks at.

def Pred.part source · line 58 · raw

@p:Pred -> @+o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> String

def Pred.print.go source · line 69 · raw

@ps:List<&2, Pred> -> @+o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> String

def Pred.deleting source · line 76 · raw

@d:Bool -> String

def Pred.print source · line 88 · raw

@ps:List<&2, Pred> -> @+o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> String

What the predicates see of an object, its uid, deletion and finalizers included: an object deleted and recreated under the same name (a new uid) always passes, whatever its generation; a finalizer added or removed (by this controller or another) always passes, so a controller that adds its finalizer and waits for the change is woken by it.

def Pred.changed source · line 92 · raw

@+ps:List<&2, Pred> -> @old:Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+new:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> Bool

def Pred.passes source · line 101 · raw

@ps:List<&2, Pred> -> @old:Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+new:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> Bool

Whether a change to the primary reconciles it: always without predicates; with them, when what they see differs from the cached object.

def Ref.names.any source · line 119 · raw

@xs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+name:String -> Bool

A field names the object: the string itself, or a list holding it.

def Ref.names source · line 128 · raw

@v:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @+name:String -> Bool

def Rel.near source · line 139 · raw

@+p:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @+ns:String -> Bool

A primary can relate to the object: one in the object's namespace, or any primary when either is cluster-scoped.

def Rel.ref.put source · line 143 · raw

@+p:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @hit:Bool -> @rest:List<&2, String> -> List<&2, String>

def Rel.refs source · line 150 · raw

@ps:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+path:List<&2, String> -> @+ns:String -> @+name:String -> List<&2, String>

def Rel.all source · line 159 · raw

@ps:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+ns:String -> List<&2, String>

def Rel.key.go source · line 168 · raw

@+ns:String -> @+name:String -> @namespaced:Bool -> String

The key of a primary named name, related to an object in namespace ns: in that namespace for a namespaced primary, by name alone otherwise.

def Rel.key source · line 175 · raw

@+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @+ns:String -> @+name:String -> String

def Rel.label source · line 179 · raw

@m:Maybe<&2, String> -> @+ns:String -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> List<&2, String>

The primary a label names.

def Rel.annot source · line 186 · raw

@o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @key:String -> Maybe<&2, String>

def Rel.annotated.go source · line 189 · raw

@+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @ns:Maybe<&2, String> -> @name:Maybe<&2, String> -> @+own:String -> List<&2, String>

def Rel.annotated source · line 201 · raw

@+o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @+nk:String -> @+vk:String -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> List<&2, String>

The primary two annotations name: its namespace (the object's own when that annotation is missing) and its name (nothing without it).

def Ref.group.go source · line 205 · raw

@ps:List<&2, String> -> String

The group of an apiVersion: "apps" of "apps/v1", "" of "v1".

def Ref.group source · line 212 · raw

@av:String -> String

def Ref.is_owner source · line 216 · raw

@+r:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> Bool

Whether an owner reference names the primary's kind, in its group.

def Rel.owner.put source · line 220 · raw

@+r:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @+ns:String -> @hit:Bool -> @rest:List<&2, String> -> List<&2, String>

def Rel.owner.go source · line 228 · raw

@rs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @+ns:String -> List<&2, String>

def Rel.owners source · line 237 · raw

@+o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> List<&2, String>

The primaries an object's owner references name (kube-runtime's trigger_owners): the primary's kind in its API group.

def Rel.keys source · line 242 · raw

@r:Rel -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @+o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> List<&2, String>

The primary keys a related object triggers; res is the primary's resource (its kind, group and scope).

def Fold.put source · line 263 · raw

@+key:String -> @hit:Bool -> @ks:List<&2, String> -> List<&2, String>

def Out.obj source · line 270 · raw

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

def Fold.prim.one source · line 281 · raw

@+ps:List<&2, Pred> -> @o:0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out -> @f:Fold -> Fold

def Fold.prim source · line 300 · raw

@+ps:List<&2, Pred> -> @outs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out> -> @f:Fold -> Fold

The primary's outputs: each applied or initially listed object reconciles when it passes the predicates, against the cache as it was before it. A deleted object, and one a relist no longer has, is gone: the queue forgets it.

def Fold.rel.keys source · line 307 · raw

@+r:Rel -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @m:Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> List<&2, String>

def Fold.rel.hit source · line 315 · raw

@+r:Rel -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @+o:0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @+s:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @ks:List<&2, String> -> @+x:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @hit:Bool -> Fold

def Out.is_delete source · line 326 · raw

@o:0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out -> Bool

def Fold.rel.with source · line 334 · raw

@+r:Rel -> @+ps:List<&2, Pred> -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @+o:0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @+s:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @ks:List<&2, String> -> @m:Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> Fold

A change triggers when it is a deletion or passes the watch's predicates.

def Fold.rel.dropped source · line 345 · raw

@+r:Rel -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @ds:List<&2, String> -> @+s:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> List<&2, String>

The primaries of related objects a relist drops (deleted while the watch was down), by their cached versions.

def Fold.rel.one.go source · line 354 · raw

@+r:Rel -> @+ps:List<&2, Pred> -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @+o:0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @+s:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @ks:List<&2, String> -> @done:Bool -> Fold

def Out.is_done source · line 363 · raw

@o:0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out -> Bool

def Fold.rel.one source · line 370 · raw

@+r:Rel -> @+ps:List<&2, Pred> -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @+o:0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @f:Fold -> Fold

def Fold.rel_where source · line 378 · raw

@+r:Rel -> @+ps:List<&2, Pred> -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @outs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out> -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @f:Fold -> Fold

A related watch's outputs: every change that passes the watch's predicates (ps; Nil passes all) triggers the primaries its relation maps the object to, as cached before and as it is now.

def Fold.rel source · line 387 · raw

@+r:Rel -> @+res:0x341d8c21d651622b4e114e45f1f37703/src/core.Res -> @outs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out> -> @+prim:0x341d8c21d651622b4e114e45f1f37703/src/store.Store -> @f:Fold -> Fold

Fold.rel_where without predicates: every change triggers.

def Spec.of source · line 409 · raw

@primary:0x341d8c21d651622b4e114e45f1f37703/src/core.Api -> Spec

A controller for primary: every change, no related watches, 8 at once, no timeout.

def Spec.label source · line 412 · raw

@s:Spec -> @l:String -> Spec

def Spec.field source · line 418 · raw

@s:Spec -> @f:String -> Spec

The primary's field selector (for example "metadata.name=x").

def Spec.filter source · line 423 · raw

@s:Spec -> @ps:List<&2, Pred> -> Spec

def Spec.max source · line 429 · raw

@s:Spec -> @n:U32 -> Spec

At least 1.

def Spec.timeout source · line 438 · raw

@s:Spec -> @ms:U32 -> Spec

A reconcile still running after ms is hung: the process logs it and exits (status 1), so the pod restarts, as a crash would. A reconcile in Bend cannot be cancelled, and freeing its key while it still runs would let the same key run twice.

def Spec.watches_where source · line 445 · raw

@s:Spec -> @a:0x341d8c21d651622b4e114e45f1f37703/src/core.Api -> @label:String -> @field:String -> @r:Rel -> Spec

Adds a related watch with label and field selectors ("" for none); the n-th one added is cache n (Ctx.cache).

def Spec.watches source · line 450 · raw

@s:Spec -> @a:0x341d8c21d651622b4e114e45f1f37703/src/core.Api -> @r:Rel -> Spec

def Spec.owns source · line 455 · raw

@s:Spec -> @a:0x341d8c21d651622b4e114e45f1f37703/src/core.Api -> Spec

Objects of a's kind that the primary owns (ownerReferences to the primary's kind and group).

def Spec.primary source · line 458 · raw

@s:Spec -> 0x341d8c21d651622b4e114e45f1f37703/src/core.Api

def Spec.res source · line 463 · raw

@s:Spec -> 0x341d8c21d651622b4e114e45f1f37703/src/core.Res

def Spec.kind source · line 468 · raw

@s:Spec -> String

def Spec.preds source · line 471 · raw

@s:Spec -> List<&2, Pred>

def Spec.secs source · line 476 · raw

@s:Spec -> List<&2, Sec>

def Spec.max_of source · line 481 · raw

@s:Spec -> U32

def Spec.label_of source · line 486 · raw

@s:Spec -> String

def Spec.field_of source · line 491 · raw

@s:Spec -> String

def Spec.timeout_of source · line 496 · raw

@s:Spec -> U32

def Sec.rel source · line 501 · raw

@s:Sec -> Rel

def Sec.drop source · line 506 · raw

@s:Sec -> List<&2, String>

def Secs.set_last source · line 511 · raw

@ss:List<&2, Sec> -> @+d:List<&2, String> -> List<&2, Sec>

def Spec.drop source · line 525 · raw

@s:Spec -> @fields:List<&2, String> -> Spec

Drops top-level fields (for example "data" and "stringData" of Secrets) from the objects of the related watch added last, before they are cached: a controller that only needs to know a referenced Secret changed then holds no Secret's data. Reconcile reads what it needs with Client.get.

def Secs.filter_last source · line 530 · raw

@ss:List<&2, Sec> -> @+ps:List<&2, Pred> -> List<&2, Sec>

def Secs.on_last source · line 539 · raw

@ss:List<&2, Sec> -> @+c:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> List<&2, Sec>

def Spec.watch_filter source · line 555 · raw

@s:Spec -> @ps:List<&2, Pred> -> Spec

Filters the related watch added last (kube-runtime's predicate_filter on a watches() stream): a change to one of its objects triggers its primaries only when what the predicates see differs from the cached object (or nothing is cached). Deletions, relists that drop an object, a new uid, the start of a deletion and a change of finalizers always pass, as for the primary. With no predicates (the default), every change triggers.

def Spec.watch_on source · line 568 · raw

@s:Spec -> @c:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> Spec

Runs the related watch added last against another cluster: c, not the controller's config. Its objects map to primaries as any related watch's do, and Ctx.cluster(ctx, n) hands the reconcile the same config. c keeps its rate limit (Kube.connect adds one) but not its connection pool: a pool holds connections to one server, so Kube.control gives each such config a pool of its own. Under leader election c also takes the controllers' leadership fence, so no request to any cluster outlives the lease.

def Spec.on source · line 576 · raw

@s:Spec -> @c:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> Spec

Watches the primary on another cluster: c, not the controller's config (which still holds the lease and serves Ctx.cfg). Ctx.cluster(ctx, 0) is c, fenced as Spec.watch_on says.

def Spec.timeout_or source · line 583 · raw

@s:Spec -> @+ms:U32 -> Spec

The reconcile timeout, ms (0 for none) a spec without its own takes (Opts.with_timeout): a spec's own timeout wins.

def Spec.cluster_of source · line 590 · raw

@s:Spec -> Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/config.Config>

def Sec.preds source · line 595 · raw

@s:Sec -> List<&2, Pred>

def Sec.cluster source · line 600 · raw

@s:Sec -> Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/config.Config>

def Cluster.of source · line 607 · raw

@+main:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> @m:Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/config.Config> -> 0x341d8c21d651622b4e114e45f1f37703/src/config.Config

The config a watch runs against: the controllers' own (main), or another cluster's, under main's leadership fence.

def Cluster.secs source · line 614 · raw

@ss:List<&2, Sec> -> @+main:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/config.Config>

def Spec.clusters source · line 623 · raw

@s:Spec -> @+main:0x341d8c21d651622b4e114e45f1f37703/src/config.Config -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/config.Config>

Every watch's config, the primary's first, then each related watch's in the order they were added.

def Out.trim.obj source · line 628 · raw

@fs:List<&2, String> -> @+x:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> 0x341d8c21d651622b4e114e45f1f37703/src/json.Json

def Out.trim source · line 635 · raw

@+fs:List<&2, String> -> @o:0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out -> 0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out

def Out.trim_all source · line 647 · raw

@+fs:List<&2, String> -> @os:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out> -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/watcher.Out>

A related watch's outputs with its dropped fields removed.

def Ctx.cfg source · line 680 · raw

@c:Ctx -> 0x341d8c21d651622b4e114e45f1f37703/src/config.Config

def Ctx.idx source · line 685 · raw

@c:Ctx -> U32

def Ctx.store source · line 690 · raw

@c:Ctx -> 0x341d8c21d651622b4e114e45f1f37703/src/store.Store

def Ctx.with_fails source · line 695 · raw

@c:Ctx -> @n:U32 -> Ctx

def Ctx.meter source · line 700 · raw

@c:Ctx -> Maybe<&2, Chan(Meter)>

def Ctx.fails source · line 705 · raw

@c:Ctx -> U32

def Ctx.cluster source · line 713 · raw

@c:Ctx -> @n:U32 -> 0x341d8c21d651622b4e114e45f1f37703/src/config.Config

The config of watch n: 0 the primary's, n the n-th related watch's (as Ctx.cache counts); the controller's own (Ctx.cfg) unless the spec put the watch on another cluster (Spec.on, Spec.watch_on).

def Ctx.get source · line 719 · raw

@c:Ctx -> @key:String -> Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json>

The cached primary under a key ("ns/name", or "name").

def Ctx.list source · line 723 · raw

@c:Ctx -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json>

Every cached primary.

def Ctx.nth source · line 726 · raw

@cs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/store.Store> -> @n:Nat -> 0x341d8c21d651622b4e114e45f1f37703/src/store.Store

def Ctx.cache source · line 736 · raw

@c:Ctx -> @n:U32 -> 0x341d8c21d651622b4e114e45f1f37703/src/store.Store

The cache of the n-th related watch (from 1); empty if there is none.

def Ctx.find source · line 742 · raw

@c:Ctx -> @n:U32 -> @key:String -> Maybe<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json>

A cached related object under a key.

def Ctx.all source · line 746 · raw

@c:Ctx -> @n:U32 -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json>

Every cached object of the n-th related watch.

def Owned.ctl source · line 749 · raw

@j:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> Bool

def Owned.uid.any source · line 756 · raw

@rs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+uid:String -> Bool

def Owned.by source · line 766 · raw

@+o:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @+uid:String -> Bool

Whether o's controller (the owner reference with controller: true) has this uid (metav1.IsControlledBy).

def Owned.keep source · line 769 · raw

@+x:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> @hit:Bool -> @rest:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json>

def Owned.pick source · line 776 · raw

@xs:List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json> -> @+uid:String -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json>

def Ctx.children source · line 785 · raw

@c:Ctx -> @n:U32 -> @+owner:0x341d8c21d651622b4e114e45f1f37703/src/json.Json -> List<&2, 0x341d8c21d651622b4e114e45f1f37703/src/json.Json>

The cached objects of the n-th related watch that owner controls (by uid, with controller: true).