Skip to content

FetchResourceTemplatesByLabelSelector returns duplicate objects #7670

Description

@barbierajput378-pixel

What happened:
The FetchResourceTemplatesByLabelSelector function in pkg/util/helper/binding.go
returns duplicate resource templates when the informer cache fails and the function
falls back to the API server.

What you expected to happen:
The function should return a deduplicated list of resource templates - either from
cache OR from API server fallback, not both combined.

How to reproduce it (as minimally and precisely as possible):

  1. Open pkg/util/helper/binding.go (lines 336-383)
  2. Look at the FetchResourceTemplatesByLabelSelector function
  3. When objectList from cache is empty but not nil, and the function falls back
    to the API server
  4. The function appends both the fallback results AND processes the empty cache list

Anything else we need to know?:
The bug is in the control flow logic:

  • Line ~360: Gets objects from cache
  • Line ~361-369: If cache fails/empty, uses API server fallback and appends results
  • Line ~372-382: THEN it STILL loops through objectList and appends to objects
  • This causes duplicates

This impacts any code that relies on unique resource templates from this function.

Environment:

  • Karmada version: main/latest
  • Others: pkg/util/helper/binding.go (lines 336-383)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/cleanupCategorizes issue or PR as related to cleaning up code, process, or technical debt.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions