-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: ensure status updates are not skipped due to stale cache #7077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @zhy76, 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 bug where status updates could be inadvertently skipped if the cached object appeared semantically identical to the new status, even when the underlying resource might be out of sync. By transitioning from a full update with an equality check to a direct patch operation, the system now guarantees that all status changes are propagated, effectively preventing inconsistencies caused by stale cache data and improving the reliability of status reporting. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request addresses an issue where status updates could be skipped due to a stale cache. The fix involves removing the equality check before a status update and instead always using a Patch operation. This ensures that status changes, even those that might appear as no-ops to a client with a stale cache (like LastTransitionTime updates), are correctly persisted. The implementation is sound, and the accompanying test changes are excellent, including a major refactoring for better test case generalization and a specific test to cover the bug fix. I have one suggestion to further improve the new test's verification logic.
| verify: func(t *testing.T, c client.Client) { | ||
| work := &workv1alpha1.Work{} | ||
| assert.NoError(t, c.Get(context.TODO(), types.NamespacedName{Name: "test-work", Namespace: "default"}, work)) | ||
|
|
||
| cond := meta.FindStatusCondition(work.Status.Conditions, workv1alpha1.WorkApplied) | ||
| assert.NotNil(t, cond) | ||
| assert.Equal(t, metav1.ConditionTrue, cond.Status) | ||
| assert.Equal(t, "AppliedSuccessful", cond.Reason) | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The verification for this test case is good, but it could be made stronger. The test case update with same WorkApplied condition, should still update (issue #6858) is designed to ensure an update occurs even if only LastTransitionTime changes. The current verify function confirms the condition's Status and Reason, but doesn't check if LastTransitionTime was actually updated.
To make the test more robust and explicitly verify the intended behavior, you could add an assertion to check that LastTransitionTime has been updated to a recent time. Given the initial time is set to one hour in the past, checking that the new time is recent is a safe and effective way to confirm the update.
verify: func(t *testing.T, c client.Client) {
work := &workv1alpha1.Work{}
assert.NoError(t, c.Get(context.TODO(), types.NamespacedName{Name: "test-work", Namespace: "default"}, work))
cond := meta.FindStatusCondition(work.Status.Conditions, workv1alpha1.WorkApplied)
assert.NotNil(t, cond)
assert.Equal(t, metav1.ConditionTrue, cond.Status)
assert.Equal(t, "AppliedSuccessful", cond.Reason)
assert.True(t, time.Since(cond.LastTransitionTime.Time) < time.Minute, "LastTransitionTime should have been updated")
},There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The judgment of time differences is somewhat unreliable, and LastTransitionTime is not a key focus of testing. Therefore, it is not recommended to introduce this modification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, removed LastTransitionTime.
24eed85 to
72cbbd4
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7077 +/- ##
==========================================
- Coverage 46.56% 46.54% -0.02%
==========================================
Files 700 700
Lines 48089 48087 -2
==========================================
- Hits 22391 22383 -8
- Misses 24016 24021 +5
- Partials 1682 1683 +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:
|
|
/retest |
|
lgtm |
|
Thanks~ |
XiShanYongYe-Chang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks~
/lgtm
Ask @whitewindmills to help take a review.
cc @whitewindmills
| verify: func(t *testing.T, c client.Client) { | ||
| work := &workv1alpha1.Work{} | ||
| assert.NoError(t, c.Get(context.TODO(), types.NamespacedName{Name: "test-work", Namespace: "default"}, work)) | ||
|
|
||
| cond := meta.FindStatusCondition(work.Status.Conditions, workv1alpha1.WorkApplied) | ||
| assert.NotNil(t, cond) | ||
| assert.Equal(t, metav1.ConditionTrue, cond.Status) | ||
| assert.Equal(t, "AppliedSuccessful", cond.Reason) | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The judgment of time differences is somewhat unreliable, and LastTransitionTime is not a key focus of testing. Therefore, it is not recommended to introduce this modification.
|
Hi @zhy76, can you help add the release note? |
Signed-off-by: 浩韵 <[email protected]>
|
[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 |
Done |
|
/retest |
|
/lgtm |
| // even if the content appears unchanged. This avoids issues where stale cache data might cause | ||
| // updates to be skipped incorrectly. | ||
| // FYI: https://github.com/karmada-io/karmada/issues/6858 | ||
| if err := c.Status().Patch(ctx, obj, client.MergeFrom(oldObj)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhy76 thanks for your work, but I think theres‘s no different from the original. if the cached data is expired, I don't think client.MergeFrom(oldObj) can create a meaningful patch. maybe it looks like {}?
therefore, I mean we need to generate a hard-coded patch, or still use the Update method, which may encounter conflicts, but we can use the Retry framework to handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you mean. The obj currently passed as input might be outdated, and using it to generate a patch is unreliable.
Fixes #6858
fix: ensure status updates are not skipped due to stale cache
What type of PR is this?
/kind bug
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #6858
Special notes for your reviewer:
Does this PR introduce a user-facing change?: