Skip to content

refactor(components): run xmc-bridge as a controller-runtime controller - #1224

Merged
VLukiantsev merged 4 commits into
fix/components-crd-lifecycle-b548436300from
refactor/components-bridge-controller-runtime-b548436300
Oct 15, 2026
Merged

VLukiantsev merged 4 commits into
fix/components-crd-lifecycle-b548436300from
refactor/components-bridge-controller-runtime-b548436300

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replaces the xmc-bridge namespace sweep, which listed and reconciled every Component on each probe interval, with a controller-runtime manager and a per-Component ComponentController. Status writes and the Reconciler are unchanged; only scheduling changes.

Motivation & Context

The ticker sweep did N passes for a dependency chain of N, had no per-item backoff, and re-read every Component each interval. The ownership layers later in this stack need controller primitives (uncached reads, RequeueAfter, channel sources, leader-elected runnables), so the controller foundation lands first.

Key Changes

  • Manager cache limited to the Components of --namespace; unstructured Gets and Lists are served from it (CacheOptions.Unstructured), so no Component read reaches the API server after cache sync.
  • Reconcile on generation, label or annotation change or deletion start, plus --probe-interval requeues to observe workload health. The existing PROBE_TIMEOUT keeps bounding a pass in this layer; the separate RECONCILE_TIMEOUT is fix(components): make bridge reconcile timeout and concurrency configurable #1272.
  • Dependents watch (mapDependents) enqueues Components that list a dependency when it is created, deleted, changes generation, or changes readiness. Status writes that keep readiness do not re-enqueue, so timestamp refreshes cannot loop.
  • NewComponentRateLimiter: per-item exponential backoff 5s→300s with ±10% jitter; a failed pass persists status and returns its error (a single failure unwrapped).
  • KinD harness runs one real manager per test namespace instead of hand-driven passes.
  • Tests: unit tests for Reconcile, gating, mapDependents, predicates and the rate limiter; an envtest for dependents-watch activation, deletion-event finalizer release, and no API-server Component reads after sync.

Stack Position

Assumptions

  • Size exception: 321 prod / 740 test = 1061 total lines, 61 over the 1000-line total threshold (prod well under 400). The envtest and the KinD harness move to the real manager are needed to prove the scheduling change and cannot ship separately, and the single-failure fix corrects code this layer introduces. The repo owner approved the earlier 1013-line exception and the split plan that leaves this residual — if reviewers still prefer a split, the dependents Watches can move to its own layer.
  • The in-process KinD harness does not exercise the Deployment or the real ServiceAccount — those are covered by the live checkpoint — impact if wrong: a Deployment-only regression would surface only on a live cluster.
  • Backoff parameters (5s base, 300s max, ±10% jitter) follow the design doc — if wrong, only retry cadence changes.
  • The live GKE evidence still applies to this revision — it was collected before the last rebases onto main, and git range-diff shows no behavioral change — if wrong, the checkpoint must be re-run before merge.

Verification & Testing

  • Commands Executed: bazel test //pkg/components/... //cmd/xmc_bridge/... //cmd/experiment_state_server/... //cmd/actuator/... //test/e2e:kind_3p_harness_unit_test and the //test/helm py tests at this layer's tip; golangci-lint run (v1.64.6); gofmt -l.
  • Coverage & Test Status: all pass, including the controller envtest.
  • KinD E2E: //test/e2e:components_lifecycle_test passed with the whole stack applied.
  • Diff size (tools/analyze_diff_size.py): 321 prod / 740 test / 1061 total / 26 doc lines (see Assumptions).

Live Deployment & Manual Testing

  • Deployment Target: Live GKE development environment (enable_components: true, Spanner-backed CMS), upgraded with the dev-environment upgrade script.
  • Cluster Health: Environment verification passed (5/5, 16/16 pods Ready) before and after the checkpoint.
  • Checkpoint: CP1, run with the stack deployed up to refactor(components): track CMS sync and deactivation rechecks in memory #1229 (wave A).
  • Revision note: the live evidence was collected before the latest rebases onto main and before the split; no behavioral change in this layer.
Scenario Result Observation
Event-driven controller-runtime reconciliation ✅ PASS Creating, patching (spec.version, spec.deletionProtection, metadata.finalizers) and deleting Component CRs reconciles immediately via the watch, without namespace-wide polling.
Dependents watch activation (mapDependents) ✅ PASS mt-cp1-dep, created before its dependency mt-cp1-prereq, reported Ready=False/DependenciesNotReady. Creating mt-cp1-prereq enqueued it immediately and it became Ready=True/ComponentHealthy with DependenciesReady=True/AllDependenciesReady.
Work-queue exponential backoff recovery ✅ PASS After scaling the experiment state server to 0 and back, failed CRs retried via NewComponentRateLimiter and converged to Synced=True/CMSSynced.

Related Issues / Bugs

Bug: 548436300

TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c


Stack created with GitHub Stacks CLI • Give Feedback 💬

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the xmc_bridge controller to use controller-runtime instead of a custom reconciliation loop, introducing a new ComponentController and a jittered exponential backoff rate limiter. The feedback suggests two improvements to component_controller.go: conditionally joining errors in Reconcile to avoid unnecessary wrapping when only one error is present, and adding a defensive nil check in dependencyUnreadyReason to prevent a potential nil pointer dereference panic.

@VLukiantsev
VLukiantsev added this pull request to stack #1245 October 13, 2026 07:27
@VLukiantsev
VLukiantsev force-pushed the refactor/components-bridge-controller-runtime-b548436300 branch 2 times, most recently from 00d25cc to 66b91e8 Compare October 14, 2026 09:37
@VLukiantsev
VLukiantsev force-pushed the refactor/components-bridge-controller-runtime-b548436300 branch 2 times, most recently from a8fa007 to 01e5b45 Compare October 14, 2026 11:58
@VLukiantsev
VLukiantsev removed this pull request from stack #1245 October 14, 2026 13:31
@VLukiantsev
VLukiantsev added this pull request to stack #1277 October 14, 2026 13:32
@VLukiantsev
VLukiantsev force-pushed the refactor/components-bridge-controller-runtime-b548436300 branch from 01e5b45 to 486d12a Compare October 14, 2026 14:22
Replace the xmc-bridge namespace sweep, which listed and reconciled every
Component each probe interval, with a controller-runtime manager and a
per-Component ComponentController.

- The manager cache watches the Components of --namespace only, and the
  manager's client serves unstructured Gets and Lists from it
  (CacheOptions.Unstructured), so Reconcile and the dependents watch never
  read Components from the API server.
- A Component is reconciled when its generation, labels or annotations
  change or its deletion starts, and --probe-interval after each pass that
  does not release its finalizer, to observe workload health.
- A dependents watch enqueues the Components that list a dependency in
  spec.dependencies when it is created, deleted, changes generation, or
  changes readiness as a dependency. Status writes that keep its
  readiness do not re-enqueue its dependents, so condition timestamp
  refreshes cannot loop.
- A failed pass still persists its status, then returns its error so the
  work queue retries the Component with exponential backoff from 5s to
  300s with +/-10% jitter (NewComponentRateLimiter).
- The KinD harness runs one manager per test namespace instead of hand-
  driven passes; the finalizer cleanup scenario waits for the Component
  to be gone and then checks that CMS no longer has it.

Tests: unit tests for Reconcile, dependency gating, mapDependents, the
predicates and the rate limiter; an envtest that activates a dependent
created before its dependency through the dependents watch alone and
checks that a dependent's pass does not re-enqueue its dependency, that a
deletion event alone releases the finalizer, and that no Component GET or
LIST reaches the API server after the cache syncs; the KinD
components_lifecycle_test.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
Join the Reconciler pass error and the result persistence error only when
both are set, and treat a typed-nil object as not a Component in the
dependency readiness predicate.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
…ayer

CMS now fails closed without an authorizer (#1219), so in-process servers built by the
tests in this layer pass WithAuthorizer(NewDisabledAuthorizer()), as main's own tests do.

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
…envtest file

Bug: 548436300
TAG=agy
CONV=d833b0e6-4821-48f6-8576-776d53f55a5c
@VLukiantsev
VLukiantsev force-pushed the refactor/components-bridge-controller-runtime-b548436300 branch from 486d12a to 4008060 Compare October 14, 2026 14:48
@VLukiantsev
VLukiantsev marked this pull request as ready for review October 14, 2026 14:49
@github-actions
github-actions Bot requested a review from andrzejfudro October 14, 2026 14:50
@VLukiantsev
VLukiantsev added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 344018a Oct 15, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants