Skip to content

Prune stale go.sum entries and unused/misclassified Go requires (post-DynamoDB cleanup) #767

Closed

Description

@bpalermo

Why

After #764 (DynamoDB removal) and the upgrade stack, go.mod/go.sum carry residue that go mod tidy would normally clear. But go mod tidy is structurally unusable here (verified 2026-09-13): the generated proto packages aethermesh.dev/api/aether/{cni,config,registry,registrar,agent}/v1 exist only as Bazel outputs, so the Go tool fails with "no matching versions for query latest" on every import of them, and go mod tidy -e strips modules only generated code needs and breaks the gazelle_overrides (bazel mod tidy then fails). The cleanup therefore has to be driven from the module graph and the Bazel graph, not from go mod tidy.

Measured state (main @ e871c26)

what value
go.mod requires 103 (75 direct, 28 indirect)
module build list (bazel run @rules_go//go -- list -m all, works from go.mod alone) 318 modules
go.sum 1,458 lines / 277 modules
go.sum modules not in the build list (stale) 27 modules / 243 lines — the whole AWS SDK tree, smithy-go, protoc-gen-dynamo, protoc-gen-star, jennifer, testcontainers dynamodb, …
direct requires with zero Go imports anywhere in the repo 24: golang.org/x/crypto, golang.org/x/time, github.com/go-jose/go-jose/v4, github.com/go-openapi/swag + its 11 sub-modules, github.com/moby/spdystream, github.com/mxk/go-flowrate, github.com/zeebo/errs, github.com/blang/semver/v4, k8s.io/component-base, github.com/vladimirvivien/gexe, go.etcd.io/etcd/server/v3
unused modules (no import in any .go, no BUILD/.bzl reference) go.etcd.io/etcd/server/v3 and go.etcd.io/raft/v3 (added with the original etcd backend #20, the embed server was never used; both still have gazelle_override blocks in MODULE.bazel). They drag ~23 indirect requires that nothing else needs: bbolt, etcd/pkg/v3, cmux, probing, grpc-websocket-proxy, golang-jwt/v5, groupcache, btree, go-humanize, gogo/protobuf, clockwork, afero, go-strcase, vtprotobuf, morikuni/aec, pkg/errors, cel-go (google), go-cmp, easyjson, intern, go-grpc-middleware v1 + providers/prometheus
Bazel-only direct requires (referenced from BUILD/.bzl, never imported) github.com/pseudomuto/protoc-gen-doc, github.com/pseudomuto/protokit (//website API docs), github.com/uudashr/gocognit (lint aspect), buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go (proto compiler dep) — must stay direct
Dependabot open github.com/moby/go-archive high (indirect via testcontainers-go), pymdown-extensions high+medium (website/requirements_lock.txt)

Note //test/e2e:e2e_test is manual (run by ci.yaml directly), so sigs.k8s.io/e2e-framework and its deps (gexe, spdystream, go-flowrate, component-base) are legitimately used even though deps(//...) does not see them — any "unused" analysis must include manual targets.

Plan (one PR for Go deps, one for the website lock)

0. Repeatable audit first — scripts/go-deps-audit.sh + make deps-audit:

  • build list: bazel run @rules_go//go -- list -m all (needs GOPROXY=https://proxy.golang.org,direct in the environment; --repo_env does not reach the go subprocess);
  • stale go.sum = go.sum modules ∉ build list (print module + line count);
  • direct requires with zero .go imports (grep "<module>(/|")" over the repo minus bazel-*) and zero BUILD/.bzl references;
  • Bazel-reachable module set from bazel query 'deps(//... + //test/e2e:e2e_test + //website:all)' (include manual targets) for the unused check.
    Exit non-zero on stale go.sum or unused requires; wire it as a deps-audit job in ci.yaml (cheap: no build).

1. go.sum prune — delete every line whose module is not in the build list (−243 lines). Verify: bazel build //... //test/e2e:e2e_test (gazelle's go_deps verifies every module it fetches against go.sum, so a wrongly removed h1: fails loudly; add back with go mod download <mod> if so), bazel mod tidy idempotent, //website:site_test.

2. Remove the unused modules — bazel run @rules_go//go -- get go.etcd.io/etcd/server/v3@none go.etcd.io/raft/v3@none, delete their two go_deps.gazelle_override blocks in MODULE.bazel, make tidy, make gazelle. Expect the ~23 indirects above to disappear and use_repo(go_deps, …) to shrink (io_etcd_go_etcd_server_v3). registry/internal/etcd and the testcontainers etcd module use only client/v3 + api/v3 — the etcd integration test must still pass. Re-run step 1 afterwards (the pruned modules leave go.sum lines behind).

3. Reclassify, don't drop, the pinned-but-unimported direct requires — x/crypto, x/time, go-jose/v4, swag ×12, spdystream, go-flowrate, zeebo/errs, blang/semver/v4, component-base, gexe become // indirect (they exist to force CVE-clean versions through MVS; the pin survives, only the directness changes). bazel mod tidy then drops their use_repo entries. Keep the four Bazel-only tools direct and mark them with a // bazel-only: referenced from BUILD/.bzl comment in go.mod so the next audit (and the next human) knows why go mod tidy -e must never be trusted on them. (A //go:build tools anchor file was considered and rejected: it would make Gazelle generate a target for it and adds nothing Bazel needs.)

4. Dependabot — moby/go-archive high: bump testcontainers-go to the first release that lifts it, else go get github.com/moby/go-archive@<fixed>; pymdown-extensions: bump in website/requirements.in and regenerate the lock with the uv pip compile line from its header (separate PR, //website:site_test is the gate).

5. Docs — runbook: why go mod tidy is forbidden (generated packages), the audit command, and the "reclassify, don't drop" rule for version pins.

Verification bar for the Go PR: build + full test (incl. //test/e2e:e2e_test build, the etcd testcontainers test, and the website targets), make format-check, make lint, make gazelle no churn, bazel mod tidy idempotent, scripts/go-deps-audit.sh clean, and the audit job green in CI. Expected outcome: go.mod ≈ 75–80 requires (from 103), go.sum ≈ 1,100 lines (from 1,458), two gazelle_overrides fewer.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Activity

  1. added
    enhancement
    on Sep 13, 2026
  2. bpalermo commented on Sep 13, 2026

    @bpalermo
    OwnerAuthor

    Done in two PRs:

    Net: go.mod 207 → 183 requires (75 → 53 direct), use_repo 75 → 53, gazelle_overrides 6 → 4. Two corrections to the plan recorded in #769: go get @none downgrades dependants (used go mod edit -droprequire), and protoc-gen-doc/protokit are real Go imports via bazel/protodoc, not Bazel-only.

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