Kubernetes cache clients ignore configured API request limits

perfloop-oss/coredns · Uncatalogued correctness

https://perfloop.ai/t/oss/case_6mjxvzmrvs

Verdict

VERIFIED · settled 2026-11-21 · pull request opened as coredns/coredns#8818

What happened: The check fails before this change and passes with it.

Hypothesis

Kubernetes discovery constructs its API clients before applying the documented request limits. With ordinary client configurations, nondefault limits therefore do not reach the clients that synchronize the discovery cache. This defeats an operator's API traffic controls. Deployment exposure, API-server load and synchronization-time effects remain unmeasured.

At revision 996a30df7f5cca79a3bb34078f8897f673ac74dd, Kubernetes.InitKubeCache constructs kubeClient at lines 256–259 and the optional mcsClient at 261–267. Only afterward does it assign config.QPS, config.Burst and config.WrapTransport at 287–303. newdnsController stores those already-created clients and uses them for its service, namespace, pod, EndpointSlice and ServiceImport list/watch functions. The contract is explicit in plugin/kubernetes/README.md:63–68. Configurations supplying their own rate limiter need separate precedence analysis; the demonstrated failure uses constructor-created limiters.

The new native test TestPerfloopInitKubeCacheQPS exhaustively checked integer QPS values 0–2 with multicluster disabled and enabled, one initialization per combination and no network requests. The command `go test ./plugin/kubernetes -run '^TestPerfloopInitKubeCacheQPS$' -count=1 -v -timeout=60s` failed for both positive QPS values on both clients; QPS zero controls passed. The reduced deterministic replay, `go test ./plugin/kubernetes -run '^TestPerfloopInitKubeCacheQPS$/^qps=1$/^mcs=false$' -count=1 -v -timeout=60s`, exited 1 with `core client QPS = 5, want 1`. The check ran through bash and its temporary test file was removed. Burst and transport limits have the same late-configuration cause in source; their actual request behavior is not established by this QPS-only check.

The next useful proof is to establish that the configured controls reach both clients and govern their actual list/watch requests, with defaults, existing wrapper composition and cache synchronization/shutdown as regression controls. A local API fixture is a provisional proof method, not an additional required implementation. This is a correctness request, not a claim of measured production savings.

The current open-PR listing was followed to its end. The inspected implementation hunks in https://github.com/coredns/coredns/pull/8414, https://github.com/coredns/coredns/pull/8374, https://github.com/coredns/coredns/pull/8451 and https://github.com/coredns/coredns/pull/8067 change zone paths, endpoint names, PTR options or build tags, not this initialization ordering. The contribution guide identifies GitHub PRs as the review venue. Recent merged file history remains an evidence gap: the checkout is shallow and the bounded remote commit-history read returned HTTP 403. Targeted prior-finding searches for InitKubeCache and apiserver returned no matches; that is not proof of novelty.

Change to test: Make the documented QPS, burst and in-flight settings govern the core and optional multicluster discovery clients. Prepare their configuration before constructing them, preserving defaults, existing transport wrappers and cache lifecycle behavior.

Where it lives

perfloop-oss/coredns

Evidence

The check fails before this change and passes with it: `When InitKubeCache creates core and multicluster discovery clients without a supplied rate limiter, positive QPS and burst settings reach both clients, the in-flight setting limits concurrent list/watch dispatch across them, and zero settings preserve client defaults.`

The check fails before this change and passes with it: `When the caller supplies no rate limiter, configured positive QPS or burst limits govern core and multicluster watch requests after list requests consume their allowance, while zero-valued settings preserve the default watch-rate behavior.`

Checks: 4 of 4 passed. Verification: no defect found.

Timeline