Skip to content

Codebase review 2026-09-15: phased fix plan (correctness, races, binary size, tests, dead code, docs) #772

Closed

Description

@bpalermo

Umbrella for the fixes coming out of the 2026-09-15 five-way review of main @ 3c8f9c7 (stale docs, dead code, dependency tree, test consolidation, races/locks). Each phase is one or more independently mergeable PRs; order within a phase is the recommended order. Standing rules apply: any charts/ change bumps Chart.yaml; anything touching the data path or the supervisor gets a hitless-rollout validation on talos-main before it is called done; --config=race results and file:line evidence are in the review reports (kept locally with the session; ask for them).

Phase A — correctness (do first; each PR is small)

  • A1 build/CI/chart hazards (no Go): chart: proxy.authzSidecar.failureMode is compared with a raw string equality, so any spelling variance silently selects fail-closed #770 (failureMode normalisation + schema/enum + template test); tools/buildid/BUILD.bazel:36-45 add //prober/cmd/prober to the build-id collision guard; delete Makefile:113-120 publish (references //charts/agent, //charts/registrar — neither exists — after push-all has already pushed images) and push-proxy-image; drop the ignored --set spire.trustDomain= from e2e/multicluster_{replicator,waypoint}.sh; fix the .github/workflows/main.yaml:29 comment claiming e2e.yaml covers main pushes (it is workflow_dispatch + schedule only); bazel/img/go_multi_arch_image.bzl:69-77 stop declaring additional_layer when image_tars_layer is unset (four dangling targets).
  • A2 the race the detector caught + CI race gate: registry/internal/etcd/etcd.go:569/:200 — Close cancels the watch ctx then nils client/watchCancel without waiting for watchLoop; add a done channel closed by watchLoop, wait on it in Close, never nil client (or atomic.Pointer), guard double Close. Fix the three test-only races that fail deterministically under --config=race: registrar/internal/server/server_test.go:26 (mutex on the fake stream + snapshot() accessor), prober/internal/prober/prober_test.go:312 (NewUnstartedServer, set ConnState, Start), common/xds/callbacks_test.go:23 (atomic.Bool). cni/internal/util/watcher.go:80 blocking send with no ctx/quit case (the one select loop with no stop path). Then add a race job to ci.yaml: bazel test --config=race over the whole tree (169 s measured) plus --runs_per_test=3 on the 19 concurrency-heavy packages, in the ci fan-in.
  • A3 shared-cache mutation: agent/storage hands out cached protos whose RWMutex guards the map, not the values — cni/server/termination.go:114 and liveness.go:95 mutate them in place. Either GetAll/Get return proto.Cloned values (simplest, measure the cost — the CNI server's pod table is small) or the type documents immutability and the two call sites copy-on-write. Same class in registry/internal/registrar.go:377/397 vs :921/:935: cached endpoint slices escape the lock and are appended/mutated by consumers (xds/cache/cluster.go) → return copies. Add -race tests that interleave the goroutines involved (the detector only finds what a test exercises).
  • A4 determinism (fix(agent): make cluster/CLA protos deterministic to stop spurious CDS churn #135 redux on RDS): agent/internal/xds/cache/cluster.go:93 and capture.go:484/535 build the cap_http / aether_outbound virtual hosts in map-iteration order; l4route.go picks the UDP primary cluster by map order. sort.Slice per builder, plus a determinism test in the style of the fix(agent): make cluster/CLA protos deterministic to stop spurious CDS churn #135 fix (build twice from shuffled inputs, compare bytes). Validate: xDS push counters/RDS version churn should drop on talos.
  • A5 supervisor: proxy-supervisor: shutdown admin probe runs on the already-cancelled ctx, so SIGTERM may never drain Envoy (needs reproduction) #771 — reproduce first (unit + delete-pod on talos), then fix the probe ctx and the missing deadline, then the four epoch-bookkeeping findings and the tmp-file/fsync item. Own PR, hitless-rollout + delete-pod validation, coordinate the cluster window.
  • A6 lock-scope and ordering fixes (split by blast radius):
  • A7 flaky: replicator e2e — endpoint withdrawal >30s when the designed path is watch-speed (sub-second) #597 replicator flake: TestReplicator_LeaseHandoffKeepsMirrorAlive watches through the predecessor's TTL expiry with a 6.7–10 s margin while startReplicator never sets DialTimeout (default 5 s) — set a 500 ms DialTimeout in the test, do the lease hop in a single clientv3.Txn, and gate the watch loop on the synced revision. Close flaky: replicator e2e — endpoint withdrawal >30s when the designed path is watch-speed (sub-second) #597 on 20/20 green runs.
  • A8 duplicated production code: buildL4Backends exists twice (agent/internal/l4route/reconciler.go:466, agent/internal/edge/gatewayapi/reconciler.go:946) with duplicated tests; unify in common/gammaproject (or a new common/l4project), then the tests collapse. Data path → hitless validation.

Phase B — binary size (independent of A except B2)

  • B1 cni/cmd/cni-install/main.go:6 and prober/cmd/prober/main.go:7 import controller-runtime only for ctrl.SetupSignalHandler(); replace with signal.NotifyContext (pattern at agent/cmd/mesh-dns/main.go:133, incl. the exit-on-second-signal behaviour), optionally hoisted to common/signals. Move prober/internal/cmd/root.go:8 off controller-runtime/pkg/log/zap onto common/log (slog; prober.New takes *slog.Logger). Expected: cni-install 25 → ~7 MiB (66 → 10 modules), prober 40 → ~16 MiB (79 → ~23). Check LogsQL/alert rules that grep prober log lines before merging (JSON keys change).
  • B2 split agent proxy-supervisor into //agent/cmd/proxy-supervisor (the proxy pod runs the 65 MiB agent to supervise a child; the hot-restart code needs 22 modules, the only coupling is agent/internal/cmd/supervisor.go:56 manager.SetupLogging). Precedent: proxy readiness probe re-execs the whole agent binary every 2s: >=31% of supervisor CPU is Go package init #673 carved out proxy-ready. Chart change (image/command), hitless validation. Do after A5.
  • B3 later, lower value: common/xds → common/xds/envoyxds so plain gRPC servers (registrar) stop linking go-control-plane; CNI plugin telemetry via the agent's UDS RPC instead of an OTLP gRPC pipeline per ADD/DEL (255 → 198 packages, and CNI ADD latency).

Phase C — tests

  • C1 delete //agent/internal/cni/server:server_integration_test and //agent/internal/xds/server:server_integration_test (strict subsets of the sibling :server_test; they run twice and schedule the integration CI runner for nothing); guard registry/internal/etcd/etcd_test.go:21 TestMain with testing.Short() before starting the container; rename/delete the misnamed agent/internal/xds/proxy/edge_test.go:859; replace the 11 time.Sleep in registrar/internal/server/sync_test.go with require.Eventually.
  • C2 shared helpers: common/telemetry/telemetrytest (ManualReader install + Sum/Gauge/HistogramCount/SumByAttr; replaces 20 copies in 11 packages, ~310 LOC — never a package-level singleton provider), common/log/logtest (locked buffer + Records/Find/Level, 5 copies), registrytest.Fake (nil-embedded registry.Registry + ListAllFunc, keeping the cache test's tcpAware scoping as an explicit option), and run registrytest.RequireNamespaceQualifiedKeys + RequireProtocolDisjoint from the etcd and registrar tests (today only kubernetes runs the contract).
  • C3 smaller: common/readymarker/readymarkertest (per-binary ceilings and forbidden lists stay), registry/etcdtest bootstrap (one image pin), a variadic scheme builder for the 14 NewScheme+AddToScheme sites, k8s.io/utils/ptr instead of 11 local ptr helpers, default container_test.yaml in the image macro (agent keeps its override), cmdtest.RequireFlagsRetired.
  • C4 delete e2e/config/ (543 lines, unreferenced since Jan 2026) and the svc-0..3 half of e2e/Makefile:generate-certs; decide whether e2e/multicluster_config.sh (the only 026 harness, never run by CI) gets an e2e.yaml job.
  • Explicitly not consolidating: container-sharing across test targets, cache/edge_test ↔ proxy/edge_test, common/spire ↔ agent/internal/spire assertions, the *-ready:deps_test targets, Go e2e ↔ shell harnesses, inline discard loggers, endpoint literals, splitting the big cache/proxy targets.

Phase D — dead code (~250–300 LOC total)

  • D1 agent/internal/xds/proxy/projection.go ToConfigProjection/gammaRouteToProto/headerMutationToProto — a second GammaRoute→proto encoder that shadows common/gammaproject; nothing in production calls it and its round-trip test guards a path nobody takes. Remove and rewrite projection_test.go to round-trip the real gammaproject output. Plus edge/gatewayapi/attachment/refs.go:178 firstBackendService (+4 test assertions) and externalHTTPSPort.
  • D2 common/spire/tls.go NewSource:65, ServerTLSConfig:112, SourceTimeout — unreachable since agent: startup is fatally coupled to the SPIRE Workload API — a 25 s SVID wait exits the process (2–4 restarts per node on every cold boot; #662 family) #740's WaitingSource; separate PR because it is the identity path.
  • Keep: meshdns.WithInstanceID (documented test seam), meshdns.NewServer (2-line wrapper), Http1ProtocolOptions (needs-check), the two --readiness-check compat flags (product decision; add cobra MarkDeprecated so they warn).

Phase E — docs (~135 lines / 16 files)

  • E1 wrong facts (~40 lines, trivial): agent/internal/meshdns/server.go:1-6 name shape + forwarding attribution; common/constants/annotations/annotations.go:23 retired --capture-redirect-all; docs/proposals/035:3 and 021:3 status lines; controller/internal/podmutate/mutator.go:14 ndots "opt-in"; registry/internal/k8s/kubernetes.go:103,108 port 15008 / "ddb"; CLAUDE.md:11 Go 1.26.x, :61 "under cmd/", the registry/internal/ddb mention; charts/README.md:46,88-91 versions; agent/internal/gamma/reconciler.go:1-5; AGENTS.md:81 controller SPIRE default; docs/observability/README.md:12-20 missing alert; proxy/README.md:55 → proxy-release.yml; docs/conformance/gateway-api-features.md:11 "0.41.0".
  • E2 document what shipped (~95 lines, needs a decision on depth): docs/configuration.md prober section, --lame-duck-max, --spire-wait-warn-after, the 28 undocumented values keys (14 are edge.config.*); CLAUDE.md/AGENTS.md: prober/cmd/prober, agent/cmd/proxy-ready, agent/cmd/mesh-dns-ready, common/spire, controller/internal/nodetaint + agent/internal/node, agent/internal/cniconflist, registrar/internal/replicator, agent/internal/identity, nogo, the deps-audit and race CI jobs.

Suggested sequencing

Week 1: A1, A2, E1 (all small, no cluster risk) and the #771 reproduction. Week 2: A3, A4, A6b/c/d, C1, D1/D2, B1. Then the cluster-validated set one at a time: A5, A6a, A8, B2. C2–C4 and E2 whenever convenient. Each PR references this issue and the sub-issue where one exists (#770, #771, #597).

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Activity

  1. added
    enhancement
    on Sep 15, 2026
  2. 5 remaining items

  3. bpalermo commented on Sep 16, 2026

    @bpalermo
    OwnerAuthor

    All phases executed and deployed (rev214 = 0.92.22-a607a04 on talos-main, 2026-09-16).

    Merged: A1 #774 (closes #770) · A2 #776 · A3/A6b #782 · A3/A6d #781 · A4 #780 · A5 #785 (closes #771) · A6a #784 · A6c #779 · A7 #778 (#597 stays open: it is about the e2e harness) · A8 #783 · B1 #777 · B2 #790 · C1 #788 · D #775 · E1 #773 · E2 #787 · follow-ups #789 (CI control_plane filter, proven by throwaway #792) and #793 (test ordering).

    Deploy validation: roll hitless (0 prober errors fleet-wide, 0 restarts, 0 ERROR lines, 5/5 hot restarts, lame duck 5/5 successor, #638/SDS counters flat, xDS churn settled, #770 fail-closed end-to-end, images −35%/−48%/−64%). Two findings tracked separately: #795 (delete-pod/drain/eviction now costs ~8 s on the node because #785 removed the accidental successor wait — fix in progress) and #796 (roll wedge on a CPU-saturated node: edge maxSurge → proxy preemption → CNI DEL fails without the agent socket). Not exercised: L4 TCP/TLS/UDP paths (no routes deployed, no CI e2e) — see #783.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions