Skip to content

bug: indexers_test.go mapWorkloadToAgentCards fails — missing field indexer in test suite #351

Description

@cwiklik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions