Problem
The mapWorkloadToAgentCards test case ("when a Sandbox workload has agent labels and matching AgentCard exists") fails in CI with:
Failed to list AgentCards for mapping {"error": "field label not supported: .spec.targetRef.name"}
Expected
<[]reconcile.Request | len:0, cap:0>: nil
to have length 1
Unit Tests are failing on main:
| Run |
Conclusion |
| 25571428211 |
failure |
| 25571405507 |
failure |
Root Cause
The test suite in suite_test.go creates a plain client.New(cfg, ...) without a ctrl.Manager, so the field indexer for .spec.targetRef.name is never registered. The mapWorkloadToAgentCards function queries with client.MatchingFields{TargetRefNameIndex: ...} which requires this indexer.
In production, the three controllers (agentcard, agentcardsync, networkpolicy) all call RegisterAgentCardTargetRefIndex(mgr) in their SetupWithManager methods — but the test setup skips this.
The earlier tests in the same file (no-labels, wrong-label) pass because isAgentWorkload() returns false before the List call, so they never hit the missing index.
Introduced By
1a1c259 — Kevin Cogan added indexers.go with RegisterAgentCardTargetRefIndex
2910322 — added the failing test but missed wiring the indexer into the test suite
Suggested Fix
In suite_test.go, create a ctrl.Manager backed by the envtest config, call RegisterAgentCardTargetRefIndex(mgr), start the manager, and use mgr.GetClient() for tests that need field indexing.
Files
kagenti-operator/internal/controller/suite_test.go — test setup (needs manager + indexer)
kagenti-operator/internal/controller/indexers_test.go:90-115 — failing test
kagenti-operator/internal/controller/indexers.go:41-63 — indexer registration
Problem
The
mapWorkloadToAgentCardstest case ("when a Sandbox workload has agent labels and matching AgentCard exists") fails in CI with:Unit Tests are failing on
main:Root Cause
The test suite in
suite_test.gocreates a plainclient.New(cfg, ...)without actrl.Manager, so the field indexer for.spec.targetRef.nameis never registered. ThemapWorkloadToAgentCardsfunction queries withclient.MatchingFields{TargetRefNameIndex: ...}which requires this indexer.In production, the three controllers (
agentcard,agentcardsync,networkpolicy) all callRegisterAgentCardTargetRefIndex(mgr)in theirSetupWithManagermethods — but the test setup skips this.The earlier tests in the same file (no-labels, wrong-label) pass because
isAgentWorkload()returnsfalsebefore theListcall, so they never hit the missing index.Introduced By
1a1c259— Kevin Cogan addedindexers.gowithRegisterAgentCardTargetRefIndex2910322— added the failing test but missed wiring the indexer into the test suiteSuggested Fix
In
suite_test.go, create actrl.Managerbacked by theenvtestconfig, callRegisterAgentCardTargetRefIndex(mgr), start the manager, and usemgr.GetClient()for tests that need field indexing.Files
kagenti-operator/internal/controller/suite_test.go— test setup (needs manager + indexer)kagenti-operator/internal/controller/indexers_test.go:90-115— failing testkagenti-operator/internal/controller/indexers.go:41-63— indexer registration