fix: invalidate stale informer cache on cluster re-registration#7152
fix: invalidate stale informer cache on cluster re-registration#7152goyalpalak18 wants to merge 1 commit intokarmada-io:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello @goyalpalak18, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue where the system could serve stale informer cache data when a cluster was unregistered and then a new physical cluster was registered with the same name. By introducing UID tracking for clusters within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a critical race condition by introducing UID tracking for cluster informer managers, preventing stale cache issues when cluster names are reused. The implementation is well-structured and applied consistently across both generic and typed informer managers. I've identified a critical issue in the new IsManagerExistWithUID function that could undermine the fix, particularly during an upgrade. I've also suggested a minor performance improvement to avoid unnecessary client creation. Overall, this is a solid improvement for Karmada's reliability.
|
Hi @XiShanYongYe-Chang @RainbowMango , I’ve addressed the stale cache issue by implementing UID tracking for the informer manager. This ensures we don't hit silent propagation failures or data corruption when a cluster name is reused. Ready for your review! |
Add UID tracking to MultiClusterInformerManager to detect when a cluster is re-registered with the same name but different identity. This prevents stale cache issues that could cause cross-cluster resource corruption. Signed-off-by: goyalpalak18 <goyalpalak1806@gmail.com>
79559ed to
ba85cc3
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7152 +/- ##
==========================================
- Coverage 46.55% 46.50% -0.05%
==========================================
Files 700 700
Lines 48139 48206 +67
==========================================
+ Hits 22409 22418 +9
- Misses 24044 24103 +59
+ Partials 1686 1685 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@goyalpalak18 Can this issue be reproduced with these steps? Just out of curiosity, how do you find this? |
Hey @RainbowMango, thanks for the review! Yes, those reproduction steps definitely work. As for how I found it—I was actually just digging through the MultiClusterInformerManager code to understand the lifecycle better. I noticed that ForCluster strictly checks for the existence of the cluster name in the map. It occurred to me that if a cluster gets unregistered and immediately re-registered with the same name (which happens in some of our DR scenarios), we'd just silently hand back the old, stale manager because the name matches. Since the UID is unique even if the name is reused, tracking that seemed like the safest way to force a cache refresh. |
|
Thanks for the clarification. I will take a look and try to reproduce it on my side. But it may take some time. |
Sounds good. Thanks for looking into it. |
Description
This PR addresses a critical race condition and cache invalidation issue where reusing a cluster name (common in disaster recovery, GitOps, or cloud auto-provisioning) caused the
InformerManagerto serve stale cache data from the previous cluster.The Problem
Previously, the
MultiClusterInformerManageridentified clusters solely by their name. If a cluster was unregistered and immediately a new physical cluster was registered with the same name, the system would return the existing (stopped or stale) informer manager.This resulted in:
Solution
I have updated the
InformerManagerlogic to track the Cluster UID alongside the cluster name to ensure identity verification.Key Implementation Details:
clusterUIDsmap toMultiClusterInformerManagerto track the active UID for every registered cluster name.ForClusterWithUID. When requested, it checks if the cached manager matches the provided UID.WorkStatusControllerandClusterStatusControllerto useIsManagerExistWithUIDandForClusterWithUID, ensuring they never operate on a stale client.Impact
This fix significantly improves reliability in dynamic multi-cluster environments. It ensures that Karmada correctly distinguishes between different physical clusters that share a name, preventing cross-cluster status corruption and ensuring accurate resource propagation.
Testing
work_status_controller_test.goandcluster_status_controller_test.goto mock UID changes and verify that the manager is correctly refreshed.cluster-a.cluster-a.cluster-a.cluster-a(different IP/UID).