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

Webhook: handle error when calling wait.ExponentialBackoff #95874

Merged
merged 1 commit into from
Oct 27, 2020

Conversation

tkashem
Copy link
Contributor

@tkashem tkashem commented Oct 26, 2020

What type of PR is this?

/kind bug

What this PR does / why we need it:

Inside WithExponentialBackoff function, handle error returned by wait.ExponentialBackoff

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 26, 2020
@k8s-ci-robot
Copy link
Contributor

@tkashem: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 26, 2020
@tkashem
Copy link
Contributor Author

tkashem commented Oct 26, 2020

/assign @deads2k

@tkashem
Copy link
Contributor Author

tkashem commented Oct 26, 2020

/retest

3 similar comments
@tkashem
Copy link
Contributor Author

tkashem commented Oct 26, 2020

/retest

@tkashem
Copy link
Contributor Author

tkashem commented Oct 26, 2020

/retest

@tkashem
Copy link
Contributor Author

tkashem commented Oct 26, 2020

/retest

if ctx.Err() != nil {
// we timed out or were cancelled, we should not retry
return true, err
return true, webhookErr
Copy link
Contributor

Choose a reason for hiding this comment

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

if the context fails, the webhookErr could be nil and we would still want to fail, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, if context fails, we should return ctx.Err()

@tkashem
Copy link
Contributor Author

tkashem commented Oct 26, 2020

/retest

}
return true, nil
})
return err

Copy link
Contributor

Choose a reason for hiding this comment

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

switch{
// if we have a webhook error, it's the most important
case webhookErr != nil:
  return webhookErr

// if we have a deadline exceeded or cancelled, then that 's got priority over timeouts.
case ctx.Err() != nil:
  return ctx.Err()

// if the wait returned an error, but we didn't get a webhook error, it should be timeout and return that
case err != nil:
  return err

// if nothing had an error, then return nil
default:
  return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@deads2k If the context gets canceled or times out then wait.ExponentialBackoff returns the context error to us via err. So either ctx error or wait.Timeout error is returned. I don't think we need to check for ctx.Err() != nil in the switch.

I added the switch statement as suggested.

Also, in the current implementation, we call the webhookFn first and then check for ctx.Error. I think checking if the context has timed out first before calling the webhookFn function is more correct.

err := wait.ExponentialBackoff(backoff, func() (bool, error) {		
		if ctx.Err() != nil {
			// we timed out or were cancelled, we should not retry
			return true, ctx.Err()
		}
                webhookErr = webhookFn()

I added two unit tests to verify:

  • webhookErr is more important than ctx.Err()
  • If the context is already canceled, there is no need to call the webhookFn function.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 26, 2020
@tkashem
Copy link
Contributor Author

tkashem commented Oct 26, 2020

/retest

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 27, 2020
return true, err
}
if shouldRetry(err) {
var webhookErr error
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a comment for future generations

// having a webhook error allows us to track the last actual webhook error for requests that are later cancelled or time out

@deads2k
Copy link
Contributor

deads2k commented Oct 27, 2020

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 27, 2020
@deads2k
Copy link
Contributor

deads2k commented Oct 27, 2020

/hold

let's get that nit on that comment. It may be not be super obvious.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 27, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, tkashem

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 27, 2020
- Inside WithExponentialBackoff function, handle error returned
by wait.ExponentialBackoff.
- Ensure that the wait time is bound to the given context.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 27, 2020
@deads2k
Copy link
Contributor

deads2k commented Oct 27, 2020

/lgtm
/hold cancel

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Oct 27, 2020
@sttts sttts added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Oct 27, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Oct 27, 2020
@sttts sttts added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 27, 2020
@tkashem
Copy link
Contributor Author

tkashem commented Oct 27, 2020

/priority important-soon

@tkashem
Copy link
Contributor Author

tkashem commented Oct 27, 2020

/retest

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Oct 27, 2020

@tkashem: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-kubernetes-e2e-kind-ipv6 f8e35de link /test pull-kubernetes-e2e-kind-ipv6

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@tkashem
Copy link
Contributor Author

tkashem commented Oct 27, 2020

/retest

@k8s-ci-robot k8s-ci-robot merged commit 56069e4 into kubernetes:master Oct 27, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.20 milestone Oct 27, 2020
@tkashem tkashem deleted the webhook-handle-error branch October 27, 2020 18:45
k8s-ci-robot added a commit that referenced this pull request Jan 20, 2021
…4-upstream-release-1.19

Automated cherry pick of #95874: Webhook: handle error when calling wait.ExponentialBackoff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants