Skip to content
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

Merged
merged 3 commits into from
Apr 23, 2024

Conversation

opencmit2
Copy link
Contributor

…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

@kruise-bot kruise-bot requested review from FillZpp and furykerry April 16, 2024 04:01
@kruise-bot
Copy link

Welcome @opencmit2! It looks like this is your first PR to openkruise/kruise 🎉

@kruise-bot kruise-bot added the size/XS size/XS: 0-9 label Apr 16, 2024
Copy link

codecov bot commented Apr 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 48.52%. Comparing base (0d0031a) to head (0fa5f26).
Report is 19 commits behind head on master.

Files Patch % Lines
pkg/control/pubcontrol/pub_control_utils.go 0.00% 5 Missing ⚠️
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              
Flag Coverage Δ
unittests 48.52% <0.00%> (+0.60%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -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) {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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)

Copy link
Contributor Author

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
                        }
                }

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Member

@furykerry furykerry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@zmberg
Copy link
Member

zmberg commented Apr 23, 2024

/approve

@kruise-bot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kruise-bot kruise-bot merged commit 2da1b90 into openkruise:master Apr 23, 2024
33 of 34 checks passed
ABNER-1 pushed a commit to ABNER-1/kruise that referenced this pull request Apr 29, 2024
…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]>
@opencmit2 opencmit2 deleted the devel_1567 branch June 6, 2024 01:14
furykerry pushed a commit to furykerry/kruise that referenced this pull request Feb 8, 2025
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] pub webhooks unexpectedly return error when PUB is NOT FOUND
5 participants