-
Notifications
You must be signed in to change notification settings - Fork 776
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
Fixed an issue where pub webhooks unexpectedly return error when PUB is NOT FOUND #1579
Conversation
…is NOT FOUND Signed-off-by: JinXinWang <[email protected]>
Welcome @opencmit2! It looks like this is your first PR to openkruise/kruise 🎉 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1579 +/- ##
==========================================
+ Coverage 47.91% 48.52% +0.60%
==========================================
Files 162 163 +1
Lines 23491 18903 -4588
==========================================
- Hits 11256 9172 -2084
+ Misses 11014 8510 -2504
Partials 1221 1221
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -102,7 +102,7 @@ func PodUnavailableBudgetValidatePod(pod *corev1.Pod, operation policyv1alpha1.P | |||
if refresh { | |||
pubClone, err = kubeClient.GetGenericClient().KruiseClient.PolicyV1alpha1(). | |||
PodUnavailableBudgets(pub.Namespace).Get(context.TODO(), pub.Name, metav1.GetOptions{}) | |||
if err != nil { | |||
if err != nil && !errors.IsNotFound(err) { |
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.
if errors.IsNotFound(err), code will goes to the else clause, can the code just return so as to avoid unnecessary and potentially problematic code?
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.
Do you mean to return nil directly?
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.
We also should check error returned in pub status updating, just ingore error if NotFound error retured.
err = kclient.Status().Update(context.TODO(), pubClone) |
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.
@Spground
Adding this feels a bit redundant since PUB exits without being discovered and does not continue running kclient.Status().Update
If you need to add it, is the following suitable?
err = kclient.Status().Update(context.TODO(), pubClone)
costOfUpdate += time.Since(start)
if err == nil {
if err = util.GlobalCache.Add(pubClone); err != nil {
klog.ErrorS(err, "Failed to add cache for podUnavailableBudget", "pub", klog.KObj(pub))
}
return nil
} else {
if errors.IsNotFound(err) {
return 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.
@Spground Adding this feels a bit redundant since PUB exits without being discovered and does not continue running kclient.Status().Update
If you need to add it, is the following suitable?
err = kclient.Status().Update(context.TODO(), pubClone) costOfUpdate += time.Since(start) if err == nil { if err = util.GlobalCache.Add(pubClone); err != nil { klog.ErrorS(err, "Failed to add cache for podUnavailableBudget", "pub", klog.KObj(pub)) } return nil } else { if errors.IsNotFound(err) { return nil } }
It's not exactly. PUB can be deleted anytime, e.g, before you UPDATE Status and after GET pub.
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.
@Spground ok,IsNotFound has been added to both locations. Do I still need get informerCached to make IsNotFound judgment?
…is NOT FOUND Signed-off-by: JinXinWang <[email protected]>
…is NOT FOUND Signed-off-by: JinXinWang <[email protected]>
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.
/lgtm
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: zmberg The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…is NOT FOUND (openkruise#1579) * Fixed an issue where pub webhooks unexpectedly return error when PUB is NOT FOUND Signed-off-by: JinXinWang <[email protected]> * Fixed an issue where pub webhooks unexpectedly return error when PUB is NOT FOUND Signed-off-by: JinXinWang <[email protected]> * Fixed an issue where pub webhooks unexpectedly return error when PUB is NOT FOUND Signed-off-by: JinXinWang <[email protected]> --------- Signed-off-by: JinXinWang <[email protected]>
…is NOT FOUND (openkruise#1579) * Fixed an issue where pub webhooks unexpectedly return error when PUB is NOT FOUND Signed-off-by: JinXinWang <[email protected]> * Fixed an issue where pub webhooks unexpectedly return error when PUB is NOT FOUND Signed-off-by: JinXinWang <[email protected]> * Fixed an issue where pub webhooks unexpectedly return error when PUB is NOT FOUND Signed-off-by: JinXinWang <[email protected]> --------- Signed-off-by: JinXinWang <[email protected]>
…is NOT FOUND
Ⅰ. Describe what this PR does
Fixed an issue #1567 where pub webhooks unexpectedly return error when PUB is NOT FOUND
Ⅱ. Does this pull request fix one issue?
fixes #1567
Ⅲ. Describe how to verify it
Ⅳ. Special notes for reviews