0
0
three fixes found after roll one: 0007:fence from pin, bus link load wait, ssh gateway requester wait
docs/acceptance/0007-bidder-termination.md+7−4
| @@ -125,13 +125,14 @@ sha256 asked for. The old binary records nothing, so a guest of any earlier rele | ||
| ||
Test: `tests/compositions/0007` entry `upgrade`; staging only, exclusive (every bidder changes binary). The from binary is | ||
`SWC_UPGRADE_FROM`, else `SWC_COMPAT_REQUESTER` (the previous rc); any earlier release binary will do. The host | ||
call `bidder.upgrade {name, binary: from|test, stopFirst}` puts that one binary at `/var/tmp/swc-upgrade-<sha256>` on the | ||
call `bidder.upgrade {name, binary: from|test, from, stopFirst}` (`from`: the from binary's spec, else that env) puts that one binary at `/var/tmp/swc-upgrade-<sha256>` on the | ||
bidder's host, checked against its sha256: kept there, else copied from the install's own `bin/<sha256>/` (the binary | ||
under test is there: the bidder was installed with it), else fetched by the bidder host itself from its public URL | ||
(`sha:`, `local:`, `release:`: the bucket, 20 min at most), else (a `path:` binary of a hand run) copied over ssh, which | ||
stops after 30 s when its rate would not finish inside 20 min; then it runs | ||
`<state>/bin/current/socialweb-computer upgrade --binary <file> --sha256 <sum> --state-dir <state>` as the bidder's account | ||
(docs/ci-debug.md step 5d); the cleanup upgrades every bidder it moved back to the binary under test. Steps and asserts: | ||
(docs/ci-debug.md step 5d); the cleanup upgrades every bidder it moved back to the binary under test (with the from spec it | ||
was moved by). Steps and asserts: | ||
| ||
- every bidder is upgraded to the from binary (it runs `bin/<from sha256>/`) and is ready (`bidder_guest_image_ready`) | ||
- `run request --guest-tools socialweb-computer --hold --exec -- id`; the first new ComputeVM on any bidder: that bidder's core | ||
| @@ -156,8 +157,10 @@ host's own address on the target's forwarded port, 31000-31999) was dropped (doc | ||
93fd8c11 ROOT CAUSE"). | ||
| ||
Test: `tests/compositions/0007` entry `fence`; staging only (it upgrades a bidder under a running guest), exclusive. The | ||
from binary is `SWC_UPGRADE_FROM`, else `SWC_COMPAT_REQUESTER`; it must be one without decision 54's rule (688c2105 or | ||
older), else the entry ends `unmet`. Host calls: `bidder.upgrade` (above), `bidder.guestNft {name, vm, owner, op}` (as | ||
from binary is the entry's own, `release:v0.0.0-rc186` (main 688c2105, the last release without decision 54's rule; | ||
`FROM` in tests/modules/acc-0007/src/fence.rs, passed as `bidder.upgrade`'s `from`), not the previous rc: its subject is | ||
the migration from a release without the rule, whatever rc the network follows (no env names it). It ends `unmet` if that | ||
binary is the binary under test or loads the rule. Host calls: `bidder.upgrade` (above), `bidder.guestNft {name, vm, owner, op}` (as | ||
root on the bidder VM, `nsenter -n nft` in the VMM's network namespace: `list` the product table; `probe` a test-only | ||
table `bridge swcprobe` of two counters with no verdict for UDP from the guest's tap to the host's own IPv4 addresses on | ||
31000-31999, chain `sent` at priority -301 before `swcguest` and chain `passed` at -299 after it; `counters`; `unprobe`), | ||
docs/plans/0040-findings.md+80−0
| @@ -3364,6 +3364,86 @@ Each: what was seen (with the log), the cause, the fix, its proof. | ||
TWO: hat-7's old bidder process logged `releasefollow_failed` "upgrading to v0.0.1-rc3: ... the start job did not | ||
finish" at 07:33:51Z, 7 s before the new process's reload line: the upgrade did complete (heartbeat 394445f3); the | ||
lead's reading, not traced in code: the process that asked for the restart logs the failure as it is replaced. | ||
- 0007:FENCE NAMES ITS OWN FROM BINARY (branch fence-from, 2026-11-21): after roll one, channel rc points at 324f69a1 | ||
(v0.0.1-rc3), which has decision 54's rule and decision 75's reload, so `scripts/release-prev-rc.sh` gives every CI | ||
`test` compat sha:324f69a1 and 0007:fence (from binary SWC_UPGRADE_FROM, else SWC_COMPAT_REQUESTER) ended `unmet: the | ||
from binary ... already loads decision 54's accept`, a FAIL. The entry's subject is the migration from the last | ||
release without the rule, not the previous rc: fence.rs `FROM = release:v0.0.0-rc186` (public records, no credential: | ||
main/688c2105, sha256 d4933943; `sha:688c2105` resolves to the same file; `release:` names the release), passed as | ||
`bidder.upgrade`'s new optional `from`; the host keeps each upgraded bidder's spec for the cleanup. 0007:upgrade stays | ||
on the previous rc. PROOF on held network stg-657455 (binary under test local:b6e278af, 9adce4c0; compat sha:324f69a1, | ||
CI's value; `~/.tmp/fence-from/proof/`): main's test host (tests/f4524ae0) 0007:fence FAIL 113 s with that unmet (the | ||
defect, through the gate, shard 3/47); this branch's (tests/b371f699): 0007:fence PASS 367 s (compat set) and 318 s (no | ||
compat env), probe 16/0 then 54/38 and 55/39, reload 11.1 and 11.7 s after the upgrade; 0007:upgrade PASS 110 s from | ||
324f69a1; a fence run killed after B was on rc186 (env unset): its cleanup put B back on the binary under test (no | ||
cleanup error). SEEN, NOT THIS CHANGE: the first 0007:upgrade there FAILED 155 s on 4 startup ERRORs of bob3's core of | ||
the binary under test, 9 s into its start while adopting the just-placed guest: `bus: link denied` for EventStream, | ||
PdsAccount, LocalRepo, AtprotoSession, GuestControlPlane (reading, not traced: their reconcilers called before the | ||
ComponentLinks were in `exposure.LinkPolicy`), retried and gone by 09:19:17; on no other core start of the network (12 | ||
upgrades of bob2 by the fence runs); the rerun passed. Open: a startup race of the product, not a test defect. | ||
- BUS LINKS LOADED BEFORE A CALL IS JUDGED (branch link-load, 2026-11-21). SEEN: on held network stg-657455 (branch | ||
fence-from) the first 0007:upgrade FAILED 155 s on 4 startup ERRORs of bob3's core of the binary under test, 9 s into a | ||
start that adopted a guest placed 3 s earlier: WARN `bus: link denied` for EventStream, PdsAccount, LocalRepo, | ||
AtprotoSession and GuestControlPlane, each reconcile then `Reconciler error` (ERROR, controller-runtime); retried and | ||
gone by 09:19:17; GuestControlPlane/guest-kcp "service exited" right after its own denial and served again 1.3 s later | ||
(same cause). 0006:run and 0008:run assert the same startup count, so one transient could fail three entries. | ||
CAUSE: every core start begins with an empty link table (componentcore `NewLinkPolicy` -> `SetLinks(nil)`); the | ||
componentlink controller refilled it one reconcile at a time (one worker, each a `policy.Set` then a status apply to | ||
kcp), while a caller waited at most `bus.LinkSettle` (5 s) for its link, then `ErrLinkDenied`. Under load (kcp writes | ||
slow) the links came later than 5 s. Code unchanged since 81915d4c (2026-10-23): not decision 75. FIX (ordering; no | ||
decision of the link policy changes): `runtime.Manager.Engaged` runs a func per engaged cluster of an APIExport; the | ||
componentlink controller's `load` waits for the ComponentLink informer of that workspace (bounded by | ||
`CacheSyncTimeout`, an error retries with backoff), lists, compiles like Reconcile and calls `LinkPolicy.Load` (sets | ||
only names no reconcile has set or removed yet, so a deletion is never undone), which publishes and calls | ||
`bus.LinksLoaded(workspace)`. `authorizeCaller`, for a complete non-system caller whose call the table does not allow | ||
yet, waits for that workspace's mark (only workspaces in the controller's own Scope; a nil Scope is refused), its | ||
ctx, or the bound: `bus.CacheSyncTimeout` (2 min, controller-runtime's default, now the one definition the manager | ||
uses too) counted from the workspace's first wait; then the unchanged settle and deny. When the bound runs out: one | ||
WARN per workspace, every waiter goes on, later calls to it do not wait. In memory only; nothing persisted. PROOF | ||
(hat-8, test-0001 market network `ll`, `dev restart ll-bidder-1 core` 10 times per binary, kcp and kine pinned to CPU | ||
3 with 6 busy loops and a dsync dd writer; `~/.tmp/link-load/proof/`, trial.sh there): | ||
| ||
| binary | load | starts with `link denied` | `link denied` | `Reconciler error` | ERROR | | ||
|---|---|---|---|---|---| | ||
| main 0b1aab87 | none | 0 of 2 | 0 | 0 | 0 | | ||
| main 0b1aab87 | pinned | 10 of 10 | 57 | 47 | 62 | | ||
| link-load c4e837b6 | pinned | 0 of 10 | 0 | 0 | 0 | | ||
| ||
Each fixed start logged "the ComponentLinks of a workspace are loaded" (root:bidder-1 47 links, root:bidder-1:app 0) | ||
and no bound WARN. NOT PROVEN: the bound on a workspace that never loads, and the first-wait bound (argued from code, | ||
not provoked live); staging entries on the stack build (0006:run, 0008:run, 0007:restart, 0007:upgrade, 0007:fence, | ||
0002:run) run on the ssh-requester-await agent's held network. | ||
- 0002:RUN "YOUR REQUESTER IS NOT AVAILABLE" (staging stg-453104, 2026-11-21 09:53Z, alice3, roll-stack d607d044; evidence | ||
`~/.tmp/rc-0002-reg/`, proof `~/.tmp/ssh-await/logs/`). SEEN: `transient command: exit 1 ... ssh gateway error: your | ||
requester is not available: ... componentcore: the Requester root/requester-9ebeef60eacc7824 is not registered` 15 s | ||
into the entry. The gateway's core.log: `sshserver_account_signed_in` 09:52:50.03, `requester_registered` 55.05 (the | ||
bus handler, not the component registry), `session_started` and `sshserver_account_requester_unavailable` 55.954, | ||
`requester_started` 56.03: the command came 79 ms before the account's new Requester was Ready. CAUSE: an old race of | ||
the product, not that tree's help commit (the Requester runs in the core's own component runtime and execs nothing). | ||
Sign-in (`sshserver/signin.go`) records the session owner and returns; the sshgateway composer then declares the | ||
per-account Requester and its link (`app/sshgateway/sshgateway.go:545-567`); the runtime puts the service into the | ||
registry only once it signals Ready (`component/runtime.go` awaitReady, register). The ssh session resolved it with one | ||
registry lookup (`componentcore/providers.go`) and failed at once on a miss. acc-0002 runs its command when | ||
`page.signin` (`scripts/oauth-signin.ts`, fixed pauses: about 5.9 s after the callback) and `ssh.tempKey` return; that | ||
day the gateway's kcp answered in 0.5 to 1.3 s (17 slow traces, only in that minute), so the start took 6.0 s. Without | ||
load the margin is about 5.5 s (stg-803264: Requester started 1.25 s after the sign-in). FIX (ssh-requester-await | ||
9e9051be): a signed-in session may run a command at once; the gateway waits for its own requester. The Requester | ||
provider awaits the service (`runtime.AwaitDeclared`) on the runtime's change broadcast while the key's instance is | ||
starting or not created yet (the caller holds an accepted link: the composer declared it), bounded by the session's | ||
context and `component.ReadyTimeout`; an instance that is Failed, suspended or deleting fails at once with today's | ||
error; an account with no link is refused by `bus.Resolve` before the provider, as before (after the bus's 5 s | ||
LinkSettle). Logs `sshserver_account_requester_ready waitedMs=` and `waitedMs` on `requester_unavailable`. PROOF | ||
(held network stg-803264, binary under test local:e1207601 = fix-stack: main + fence-from + link-load + this; the ssh | ||
gateway's kcp and kine pinned to one CPU with six busy loops and a dsync writer; each trial a fresh per-account | ||
Requester: sign-in with no pause, POST /keys and the ssh command (LC_POLICY=none: the requester answers without a VM) | ||
0.3 to 0.4 s after the callback, then sign-out, which prunes it): the gateway core on main 324f69a1: 10 of 10 FAIL (8 | ||
`requester_unavailable`, 2 "sign in first", see unproven); on the stack: 10 of 10 reached the requester, waitedMs 2669 to | ||
3305. A Failed Requester (alice3: a spec field its composer does not manage made its build fail; the composer reverted | ||
it 180 ms later): of 16 sessions, the 2 in the Failed window failed at once with today's text (waitedMs 0), the one in | ||
the restart waited 35 ms and ran. A key whose account signed out: today's "sign in first" after the 5 s LinkSettle. | ||
0002:run PASS 487 s on the stack. UNPROVEN, open: the link lag. When the composer applies the account's link later than | ||
LinkSettle after the sign-in (2 of 10 trials on main's core under that load; 0 of 10 on the stack), a signed-in account | ||
is still told to sign in first: the ssh path judges "signed in" by the link, not by the recorded session owner. | ||
- A BIDDER GOES DEAF OVER IROH WHEN ITS STORED DUMBPIPE PATH CHANGES (found by the full hand cycle of `final-stack` | ||
d7019477, network stg-065007, 2026-11-21 13:56Z; evidence `~/.tmp/rollback-hazard/`, `~/.tmp/cycle-final/saved/ | ||
rollback-hazard/`). SEEN: 0007:upgrade moved both bidders from the binary under test (dumbpipe v0.40.1, runtime tree | ||
docs/plans/0040-release-pipeline.md+18−2
| @@ -3,7 +3,7 @@ | ||
Status: the only plan in flight (owner, 2026-11-17); docs/plans/0001-0039 and NEXT.yaml are history. How to run, hold | ||
and debug CI by hand: `docs/ci-debug.md`. The state before this work: main e39097c2 (2026-11-12). | ||
| ||
State (2026-11-21 08:45Z; updated by the lead): | ||
State (2026-11-21 16:40Z; updated by the lead): | ||
| ||
- Main: CI in series on four home bidders (decision 43), the fixes of promote 11's cycle, the kcp docs, the site | ||
from the repo (`site/`), the protocol docs. | ||
| @@ -87,7 +87,23 @@ State (2026-11-21 08:45Z; updated by the lead): | ||
v0.0.1. On hat-7 the new bidder logged `guest_rules_reloaded` for the promote's own VM | ||
(`fc-gmlkrhimouee-8b06f638`) at 07:33:58Z. Logs: `knotless run list $U --commit 324f69a10b6c --workflow | ||
<test|promote> --log`. | ||
- Now: roll two: `cli-help` (decision 74), run by hand first (a full hand staging cycle), then its pull. | ||
- After roll one, before any pull, three things that would have broken the next rolls were found and fixed | ||
(Findings has each): 0007:fence took its from binary from the previous rc and so failed for ever once its own | ||
roll was green (now pinned to `release:v0.0.0-rc186`; tests only); every core start began with an empty bus link | ||
table and callers were denied after 5 s under load (`bus: link denied`, ERROR lines; 0007:upgrade, 0006:run, | ||
0008:run assert a clean start): the bus now waits for a workspace's ComponentLinks to be loaded once, bounded; | ||
the ssh gateway failed a command issued before the account's requester was ready (0002:run): the session now | ||
waits for its own requester, bounded. Each reproduced first (old 10 of 10 failing, fixed 0 of 10) and reviewed. | ||
- Left out on purpose: the dumbpipe v0.40.1 bump (branch `dumbpipe-0401`): the full hand cycle with it found both | ||
bidders deaf over iroh after a switch between binaries with different dumbpipe paths, in both directions | ||
(Findings: a prod outage at a roll and at its rollback); its fix needs two releases, after this plan. | ||
- Hand cycle of the tree to land (`stack3` 2ea5fa6e = main + the three fixes, fresh network stg-134498, | ||
14:27-16:28Z): `gate: staging: 47 of 47 PASS`, 47 RESULT lines PASS, wall 7158 s; 0 `bus: link denied` on every | ||
layer; gateway `requester_ready` 3, `requester_unavailable` 0; no capacity leak (0 VM units at the end) | ||
(`~/.tmp/cycle-stack3/saved/final/`). Hand survey of `cli-help` on the same morning's base: 46 of 47 (the fail: | ||
0002:run, the sign-in race, fixed here). | ||
- Now: the pull of `stack3` = roll two (tests and product fixes); then `cli-help` (decision 74) = roll three: with | ||
roll two it is the pair of Done when 3 (only help text between them). | ||
- Relay (deployed by hand, not in the pipeline): 97bba4a7 then e7251bbc on xrpc.fedproxy.com; takeover refused on | ||
the live relay with throwaway identities; requests fell from about 290/s to under 1/s. | ||
- Landed without CI (docs, site): the site from `site/` with `/install.sh`, white pages, build-time highlighting, | ||
docs/ci-debug.md+2−1
| @@ -137,7 +137,8 @@ its from binary is the previous rc (`SWC_COMPAT_REQUESTER`, `scripts/release-pre | ||
then the binary under test, and the entry ends `unmet: the from binary (...) is the binary under test: channel rc | ||
already points at this commit ...`, a FAIL. A normal cycle runs `test` before promote moves rc, so it never meets this; | ||
by hand, give that rerun an earlier release (`sha:<its commit>`) as the input's `compat`, or as `SWC_UPGRADE_FROM` for | ||
the entry run alone (step 5b). | ||
the entry run alone (step 5b). `0007:fence` reads neither: its from binary is its own (`release:v0.0.0-rc186`, the last | ||
release without decision 54's rule), whatever channel rc points at. | ||
| ||
## One cycle: release, then test | ||
| ||
internal/bus/handlers.go+10−0
| @@ -49,6 +49,8 @@ type Bus struct { | ||
| ||
denials denials | ||
| ||
loads linkLoads | ||
| ||
root context.Context | ||
cancel context.CancelFunc | ||
closed bool | ||
| @@ -815,6 +817,14 @@ func (r *Bus) authorize(ctx context.Context, to commonv1.ObjectRef, c Capability | ||
} | ||
| ||
func (r *Bus) authorizeCaller(ctx context.Context, from Caller, to commonv1.ObjectRef, c Capability) error { | ||
if !from.System() && from.Complete() { | ||
r.mu.RLock() | ||
links := r.links | ||
r.mu.RUnlock() | ||
if !allowed(links, from, to, c) { | ||
r.awaitLinks(ctx, to.Workspace) | ||
} | ||
} | ||
wait := time.NewTimer(LinkSettle) | ||
defer wait.Stop() | ||
for { | ||
internal/bus/linkload.gonew+115−0
| @@ -0,0 +1,115 @@ | ||
package bus | ||
| ||
import ( | ||
"context" | ||
"log/slog" | ||
"strings" | ||
"sync" | ||
"time" | ||
) | ||
| ||
const CacheSyncTimeout = 2 * time.Minute | ||
| ||
type linkLoads struct { | ||
mu sync.Mutex | ||
| ||
expect func(workspace string) bool | ||
| ||
loaded map[string]bool | ||
| ||
ready map[string]chan struct{} | ||
| ||
since map[string]time.Time | ||
| ||
warned map[string]bool | ||
} | ||
| ||
func (r *Bus) ExpectLinks(expect func(workspace string) bool) { | ||
if r == nil { | ||
return | ||
} | ||
r.loads.mu.Lock() | ||
r.loads.expect = expect | ||
r.loads.mu.Unlock() | ||
} | ||
| ||
func (r *Bus) LinksLoaded(workspace string) { | ||
if r == nil { | ||
return | ||
} | ||
workspace = strings.TrimSpace(workspace) | ||
r.loads.mu.Lock() | ||
defer r.loads.mu.Unlock() | ||
if r.loads.loaded == nil { | ||
r.loads.loaded = map[string]bool{} | ||
} | ||
r.loads.loaded[workspace] = true | ||
if ch, ok := r.loads.ready[workspace]; ok { | ||
close(ch) | ||
delete(r.loads.ready, workspace) | ||
delete(r.loads.since, workspace) | ||
} | ||
} | ||
| ||
func (r *Bus) awaitLinks(ctx context.Context, workspace string) { | ||
workspace = strings.TrimSpace(workspace) | ||
r.loads.mu.Lock() | ||
expect, done := r.loads.expect, r.loads.loaded[workspace] || r.loads.warned[workspace] | ||
r.loads.mu.Unlock() | ||
if done || expect == nil || workspace == "" || !expect(workspace) { | ||
return | ||
} | ||
r.loads.mu.Lock() | ||
if r.loads.loaded[workspace] || r.loads.warned[workspace] { | ||
r.loads.mu.Unlock() | ||
return | ||
} | ||
ch, ok := r.loads.ready[workspace] | ||
if !ok { | ||
if r.loads.ready == nil { | ||
r.loads.ready, r.loads.since = map[string]chan struct{}{}, map[string]time.Time{} | ||
} | ||
ch = make(chan struct{}) | ||
r.loads.ready[workspace], r.loads.since[workspace] = ch, time.Now() | ||
} | ||
left := time.Until(r.loads.since[workspace].Add(CacheSyncTimeout)) | ||
r.loads.mu.Unlock() | ||
if left > 0 { | ||
bound := time.NewTimer(left) | ||
defer bound.Stop() | ||
select { | ||
case <-ch: | ||
return | ||
case <-ctx.Done(): | ||
return | ||
case <-bound.C: | ||
} | ||
} | ||
r.boundLinks(workspace) | ||
} | ||
| ||
func (r *Bus) boundLinks(workspace string) { | ||
r.loads.mu.Lock() | ||
first := !r.loads.warned[workspace] && !r.loads.loaded[workspace] | ||
if first { | ||
if r.loads.warned == nil { | ||
r.loads.warned = map[string]bool{} | ||
} | ||
r.loads.warned[workspace] = true | ||
if waiting, ok := r.loads.ready[workspace]; ok { | ||
close(waiting) | ||
delete(r.loads.ready, workspace) | ||
delete(r.loads.since, workspace) | ||
} | ||
} | ||
r.loads.mu.Unlock() | ||
if !first { | ||
return | ||
} | ||
log := r.denials.log.Load() | ||
if log == nil { | ||
log = slog.Default() | ||
} | ||
log.Warn("bus: the ComponentLinks of a workspace are not loaded; its calls go on to the link check", "workspace", workspace, | ||
"after", CacheSyncTimeout.String()) | ||
} | ||
internal/component/runtime.go+17−6
| @@ -364,6 +364,14 @@ func (r *Runtime) forget(inst *instance) { | ||
} | ||
| ||
func (r *Runtime) Await(ctx context.Context, key Key, serves func(Service) bool) (Service, bool) { | ||
return r.await(ctx, key, serves, false) | ||
} | ||
| ||
func (r *Runtime) AwaitDeclared(ctx context.Context, key Key, serves func(Service) bool) (Service, bool) { | ||
return r.await(ctx, key, serves, true) | ||
} | ||
| ||
func (r *Runtime) await(ctx context.Context, key Key, serves func(Service) bool, declared bool) (Service, bool) { | ||
if r == nil || r.registry == nil { | ||
return nil, false | ||
} | ||
| @@ -374,7 +382,8 @@ func (r *Runtime) Await(ctx context.Context, key Key, serves func(Service) bool) | ||
if svc, ok := r.registry.Service(key.Workspace, key.Kind, key.Name); ok && (serves == nil || serves(svc)) { | ||
return svc, true | ||
} | ||
if !r.pending(key) { | ||
known, coming := r.pending(key) | ||
if !coming && (known || !declared) { | ||
return nil, false | ||
} | ||
select { | ||
| @@ -387,7 +396,7 @@ func (r *Runtime) Await(ctx context.Context, key Key, serves func(Service) bool) | ||
} | ||
} | ||
| ||
func (r *Runtime) pending(key Key) bool { | ||
func (r *Runtime) pending(key Key) (known, coming bool) { | ||
r.mu.Lock() | ||
insts := make([]*instance, 0, len(r.instances)) | ||
for _, inst := range r.instances { | ||
| @@ -396,13 +405,15 @@ func (r *Runtime) pending(key Key) bool { | ||
r.mu.Unlock() | ||
for _, inst := range insts { | ||
inst.mu.Lock() | ||
coming := inst.key == key && !inst.spec.Suspend && !inst.spec.Deleting && inst.status.Phase != PhaseFailed | ||
same := inst.key == key | ||
up := same && !inst.spec.Suspend && !inst.spec.Deleting && inst.status.Phase != PhaseFailed | ||
inst.mu.Unlock() | ||
if coming { | ||
return true | ||
if up { | ||
return true, true | ||
} | ||
known = known || same | ||
} | ||
return false | ||
return known, false | ||
} | ||
| ||
func (r *Runtime) changes() <-chan struct{} { | ||
internal/controllers/componentlink/controller.go+40−3
| @@ -50,6 +50,8 @@ type Controller struct { | ||
targets *binding.Table[struct{}] | ||
| ||
events *ctlruntime.Queue | ||
| ||
scope func(workspace string) bool | ||
} | ||
| ||
func New(opts Options) (*Controller, error) { | ||
| @@ -76,16 +78,51 @@ func Register(m *ctlruntime.Manager, opts Options) (*Controller, error) { | ||
if err != nil { | ||
return nil, fmt.Errorf("%s: forwarding component changes: %w", Name, err) | ||
} | ||
options := []ctlruntime.Option{ctlruntime.Export(Export), ctlruntime.Events(events), ctlruntime.Gone(ctl.gone)} | ||
if opts.Scope != nil { | ||
options = append(options, ctlruntime.InWorkspaces(opts.Scope)) | ||
if opts.Scope == nil { | ||
return nil, errors.New("componentlink: a workspace scope is required: the ComponentLinks it loads are those its reconciles handle") | ||
} | ||
options := []ctlruntime.Option{ctlruntime.Export(Export), ctlruntime.Events(events), ctlruntime.Gone(ctl.gone), ctlruntime.InWorkspaces(opts.Scope)} | ||
if err := ctlruntime.For[*exposurev1alpha1.ComponentLink](m, Name, ctl, options...); err != nil { | ||
return nil, fmt.Errorf("componentlink: registering the ComponentLink controller: %w", err) | ||
} | ||
ctl.scope = opts.Scope | ||
if err := m.Engaged(Export, ctl.load); err != nil { | ||
return nil, fmt.Errorf("componentlink: loading the ComponentLinks of each engaged workspace: %w", err) | ||
} | ||
ctl.policy.Expect(opts.Scope) | ||
return ctl, nil | ||
} | ||
| ||
func (c *Controller) load(ctx context.Context, e ctlruntime.Engagement) error { | ||
if !c.scope(e.Workspace) { | ||
c.policy.Load(e.Workspace, nil) | ||
return nil | ||
} | ||
synced, cancel := context.WithTimeout(ctx, ctlruntime.CacheSyncTimeout) | ||
_, err := e.Cache.GetInformer(synced, &exposurev1alpha1.ComponentLink{}) | ||
cancel() | ||
if err != nil { | ||
return fmt.Errorf("componentlink: the ComponentLink cache of %s: %w", e.Workspace, err) | ||
} | ||
var list exposurev1alpha1.ComponentLinkList | ||
if err := e.Cache.List(ctx, &list); err != nil { | ||
return fmt.Errorf("componentlink: listing the ComponentLinks of %s: %w", e.Workspace, err) | ||
} | ||
links := map[string]bus.Link{} | ||
for i := range list.Items { | ||
object := &list.Items[i] | ||
if !object.DeletionTimestamp.IsZero() || object.Spec.Suspend { | ||
continue | ||
} | ||
if compiled, _, err := compileLink(e.Workspace, object.Name, object.Spec); err == nil { | ||
links[object.Name] = compiled | ||
} | ||
} | ||
c.policy.Load(e.Workspace, links) | ||
c.log.Info("the ComponentLinks of a workspace are loaded", "workspace", e.Workspace, "links", len(links), "listed", len(list.Items)) | ||
return nil | ||
} | ||
| ||
func (c *Controller) ComponentChanged(key component.Key) { | ||
for _, t := range c.targets.Users(binding.Key(key.Workspace, key.Kind, key.Name)) { | ||
c.events.Add(ctlruntime.Request{Cluster: t.Cluster, Workspace: t.Workspace, Name: t.Name}) | ||
internal/controllers/runtime/engage.gonew+98−0
| @@ -0,0 +1,98 @@ | ||
package runtime | ||
| ||
import ( | ||
"context" | ||
"errors" | ||
"log/slog" | ||
"strings" | ||
"sync" | ||
"time" | ||
| ||
"github.com/johnandersen777/socialweb-computer-kcp/internal/bus" | ||
"sigs.k8s.io/controller-runtime/pkg/cache" | ||
"sigs.k8s.io/controller-runtime/pkg/cluster" | ||
"sigs.k8s.io/multicluster-runtime/pkg/multicluster" | ||
) | ||
| ||
const CacheSyncTimeout = bus.CacheSyncTimeout | ||
| ||
type Engagement struct { | ||
Cluster string | ||
| ||
Workspace string | ||
| ||
Cache cache.Cache | ||
} | ||
| ||
func (m *Manager) Engaged(export string, fn func(ctx context.Context, e Engagement) error) error { | ||
export = strings.TrimSpace(export) | ||
if m == nil || export == "" || fn == nil { | ||
return errors.New("runtime: an engagement needs a manager, an APIExport and a func") | ||
} | ||
return m.mgr.Add(&engaged{m: m, export: export, fn: fn, log: m.log.With("export", export), clusters: map[string]cluster.Cluster{}}) | ||
} | ||
| ||
type engaged struct { | ||
m *Manager | ||
| ||
export string | ||
| ||
fn func(ctx context.Context, e Engagement) error | ||
| ||
log *slog.Logger | ||
| ||
mu sync.Mutex | ||
| ||
clusters map[string]cluster.Cluster | ||
} | ||
| ||
func (e *engaged) Start(ctx context.Context) error { | ||
<-ctx.Done() | ||
return nil | ||
} | ||
| ||
func (e *engaged) Engage(ctx context.Context, name multicluster.ClusterName, cl cluster.Cluster) error { | ||
export, lc := splitCluster(string(name)) | ||
if export != e.export || cl == nil { | ||
return nil | ||
} | ||
e.mu.Lock() | ||
if e.clusters[lc] == cl { | ||
e.mu.Unlock() | ||
return nil | ||
} | ||
e.clusters[lc] = cl | ||
e.mu.Unlock() | ||
e.m.sourcesWG.Go(func() { | ||
e.run(ctx, lc, cl) | ||
e.mu.Lock() | ||
if e.clusters[lc] == cl { | ||
delete(e.clusters, lc) | ||
} | ||
e.mu.Unlock() | ||
}) | ||
return nil | ||
} | ||
| ||
func (e *engaged) run(ctx context.Context, lc string, cl cluster.Cluster) { | ||
retry := newBackoff(ExportRetryFirst, DefaultBackoffMax) | ||
for failures := 0; ctx.Err() == nil; failures++ { | ||
workspace, err := e.m.path(ctx, lc) | ||
if err == nil { | ||
err = e.fn(ctx, Engagement{Cluster: lc, Workspace: workspace, Cache: cl.GetCache()}) | ||
} | ||
if err == nil || ctx.Err() != nil { | ||
return | ||
} | ||
retryIn := retry.delay(failures) | ||
e.log.Warn("the engagement of a workspace failed; it retries with backoff", "cluster", lc, "failures", failures+1, | ||
"retryIn", retryIn.String(), "err", err.Error()) | ||
timer := time.NewTimer(retryIn) | ||
select { | ||
case <-ctx.Done(): | ||
timer.Stop() | ||
return | ||
case <-timer.C: | ||
} | ||
} | ||
} | ||
internal/controllers/runtime/manager.go+1−1
| @@ -123,7 +123,7 @@ func NewManager(cfg Config) (*Manager, error) { | ||
Scheme: scheme, | ||
Logger: logger, | ||
Metrics: metricsserver.Options{BindAddress: "0"}, | ||
Controller: config.Controller{SkipNameValidation: new(true)}, | ||
Controller: config.Controller{SkipNameValidation: new(true), CacheSyncTimeout: CacheSyncTimeout}, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("runtime: the multicluster manager: %w", err) | ||