Namespace label filters incorrectly hide multicluster services
perfloop-oss/coredns · Unsound pruning
https://perfloop.ai/t/oss/case_45dds8yb3a
Verdict
VERIFIED · settled 2026-11-20 · pull request opened as coredns/coredns#8813
What happened: The check fails before this change and passes with it.
Hypothesis
Enabling namespace_labels can remove multicluster service records even when the service's namespace matches the configured filter. The cache applies the namespace's label condition to ServiceImport objects too. Imports are not required to repeat their namespace's labels, so eligible records can disappear. Deployment prevalence is unknown; a small native fixture reproduces the missing record.
The README distinguishes namespace_labels, which selects Kubernetes namespaces, from labels, which selects Kubernetes objects (plugin/kubernetes/README.md:71–80). It also documents multicluster ServiceImport discovery at 117–121. Kubernetes.InitKubeCache converts the namespace selector at kubernetes.go:278–285 and passes its options to newdnsController at 310. That constructor correctly applies dns.namespaceSelector to Namespace requests, but also passes it to serviceImportListFunc and serviceImportWatchFunc at controller.go:239–240. Those helpers send it as the ServiceImport request's LabelSelector. Namespace visibility is already checked separately by Kubernetes.namespaceExposed before findMultiClusterServices reads the import index.
The new native test TestPerfloopNamespaceLabelsServiceImport exhaustively covered namespace filtering off/on crossed with the import's matching label absent/present. Every fixture contained one Namespace labeled team=one and one ClusterSetIP ServiceImport with one IP and one port. No object-label filter was configured. The real controller synchronized against the repository's fake Kubernetes and MCS clients, with a two-second virtual synchronization bound, then the normal multicluster record lookup ran. Both unfiltered controls and the label-bearing import control returned the expected IP. Only namespace filtering with an unlabeled import failed: `namespace_exposed=true cached_imports=0 records=0 error=no items found`.
The matrix ran with `go test ./plugin/kubernetes -run '^TestPerfloopNamespaceLabelsServiceImport$' -count=1 -v -timeout=60s`. The reduced deterministic replay, `go test ./plugin/kubernetes -run '^TestPerfloopNamespaceLabelsServiceImport$/^namespace_filter=true$/^import_label=false$' -count=1 -v -timeout=60s`, exited 1 with the same missing-record result instead of one 10.0.0.1 record. The check ran through bash, stopped its controller, and removed its temporary test file. This is complete only for the four stated initial-cache fixtures, not for arbitrary watch histories.
The next useful proof is that namespace and object selectors retain their separate meanings for both initial lists and watch updates, including multicluster lookup results. A finite reference-model fixture is a provisional checking method, not a required test layout. No API extension or change to namespace exposure semantics is requested.
The open-PR scan found no matching selector correction. The inspected controller.go implementation in https://github.com/coredns/coredns/pull/8067 adds build tags only; the shared-file changes in https://github.com/coredns/coredns/pull/8414 and https://github.com/coredns/coredns/pull/8374 concern record-key construction instead. Contribution documentation names GitHub PR review. Recent merged file history remains a gap because the checkout is shallow and the bounded remote history read was refused. Targeted prior searches for ServiceImport namespace and kubernetes namespaceSelector returned no matches; this does not prove novelty.
Change to test: Keep namespace selection separate from object selection when building the multicluster cache. Use the object-label selector for ServiceImport list/watch requests and retain namespace visibility checks against the selected Namespace objects.
Where it lives
Evidence
The check fails before this change and passes with it: `For the fixed ClusterSetIP fixtures with default, namespace-only, object-only, combined, excluded-object, and excluded-namespace filters, Kubernetes.Records returns the imported IP after the initial list and an IP-only watch update exactly when the namespace and object independently satisfy their configured selectors.`
Checks: 2 of 2 passed. Verification: no defect found.
Timeline
2026-11-20· Case opened2026-11-20· PR opened