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):
- Open
pkg/util/helper/binding.go (lines 336-383)
- Look at the
FetchResourceTemplatesByLabelSelector function
- When
objectList from cache is empty but not nil, and the function falls back
to the API server
- 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)
What happened:
The
FetchResourceTemplatesByLabelSelectorfunction inpkg/util/helper/binding.goreturns 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):
pkg/util/helper/binding.go(lines 336-383)FetchResourceTemplatesByLabelSelectorfunctionobjectListfrom cache is empty but not nil, and the function falls backto the API server
Anything else we need to know?:
The bug is in the control flow logic:
This impacts any code that relies on unique resource templates from this function.
Environment: