fix(test): register field indexer in controller test suite (#351) - #352
Conversation
The mapWorkloadToAgentCards test fails because suite_test.go creates a plain client.New() without a ctrl.Manager, so the field indexer for .spec.targetRef.name is never registered. Add a Manager in BeforeSuite to register the AgentCard targetRef index and expose indexedClient for tests that need field-indexed queries. Existing tests keep using the plain k8sClient unchanged. Fixes #351 Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: cwiklik <cwiklikj@gmail.com>
3690c81 to
addef85
Compare
huang195
left a comment
There was a problem hiding this comment.
Fix addresses root cause of #351: test suite's client.New() bypassed ctrl.Manager, so the AgentCard.spec.targetRef.name field indexer was never registered, breaking mapWorkloadToAgentCards. This PR adds a Manager in BeforeSuite, registers the indexer, and exposes indexedClient for tests that need field-indexed queries. Existing tests stay on plain k8sClient — minimal blast radius. Dobra robota.
Areas reviewed: Go test setup
Commits: 1, signed-off ✓, Assisted-By footer ✓
CI: all 15 checks green (E2E, Integration, Unit, Lint, CodeQL, Trivy)
| defer GinkgoRecover() | ||
| Expect(mgr.Start(ctx)).To(Succeed()) | ||
| }() | ||
|
|
There was a problem hiding this comment.
Non-blocking suggestion: after starting the manager in a goroutine, the cache-backed client from mgr.GetClient() isn't guaranteed ready. Consider adding Expect(mgr.GetCache().WaitForCacheSync(ctx)).To(BeTrue()) before assigning indexedClient — would prevent flakes if future tests query immediately after suite setup. CI is green today so not blocking.
Ladas
left a comment
There was a problem hiding this comment.
Looks good!
@huang195 one question, how did you get your agent giving Dobra robota in review? ("good work" in Czech and I guess some Slavic languages?). I know some models/agents started to use Chinese for internal thinking, to have less token usage. But I wonder what is Slavic good for, that it got in? 😄
Summary
AgentCard.spec.targetRef.namefield indexer in the controller test suite'sBeforeSuiteclient.New()with actrl.Manager-backed client that has the indexer registeredmapWorkloadToAgentCardstest that fails withfield label not supported: .spec.targetRef.nameFixes #351
Root Cause
suite_test.gocreated a plainclient.New(cfg, ...)without actrl.Manager. ThemapWorkloadToAgentCardsfunction queries withclient.MatchingFields{".spec.targetRef.name": ...}which requires the field indexer registered byRegisterAgentCardTargetRefIndex(mgr). In production, the three controllers all register this inSetupWithManager, but the test suite skipped it.Changes
internal/controller/suite_test.goctrl.Manager, registerAgentCardTargetRefIndex, start manager, usemgr.GetClient()Test Results
All 5
mapWorkloadToAgentCardsspecs pass (previously 1 failed):Assisted-By: Claude Code