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

Clarify retry.RetryOnConflict docs #82284

Merged
merged 2 commits into from Sep 12, 2019

Conversation

danwinship
Copy link
Contributor

What this PR does / why we need it:
The documentation for retry.RetryOnConflict is both incomplete and misleading. Especially, the example code is not even using the function correctly, and is equivalent to not using RetryOnConflict at all (in that, if it does not succeed on the first try, it will not succeed on any of the retries either).

Also, #80402 moved most of the RetryOnConflict documentation to the new OnError function, but I think it makes sense to thoroughly document RetryOnConflict itself, since it is the more commonly-used function, and because many of the details of how it needs to be used are specific to conflict errors.

NONE

/kind documentation
/priority important-soon

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/documentation Categorizes issue or PR as related to documentation. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. size/M Denotes a PR that changes 30-99 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 Sep 3, 2019
@k8s-ci-robot k8s-ci-robot added 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 Sep 3, 2019
@fedebongio
Copy link
Contributor

/assign @caesarxuchao

// RetryOnConflict is used to make an update to a resource when you have to worry about
// conflicts caused by other code making unrelated updates to the resource at the same
// time. fn should fetch the resource to be modified, make appropriate changes to it, try
// to update it, and return (unmodified) the result from the update function. On a
Copy link
Member

Choose a reason for hiding this comment

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

(unmodified) the result

The "result" is the "error" returned by the update, right? If so, can we just say the "the (unmodified) error" to be more specific?

// ...
//
// OnError is an abstraction of RetryOnConflict, which allows the caller to control which
// errors will result in a retry.
// TODO: Make Backoff an interface?
func OnError(backoff wait.Backoff, errorFunc func(error) bool, fn func() error) error {
var lastConflictErr error
Copy link
Member

Choose a reason for hiding this comment

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

Since you are here, could you rename this variable? It shouldn't have "conflict" in the name.

// }
// ...
//
// OnError is an abstraction of RetryOnConflict, which allows the caller to control which
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need to mention "OnError is an abstraction of RetryOnConflict".

How about:

I will just say OnError allows caller to retry fn in case the error returned by fn is retriable according to errorFunc. backoff defines the maximum retries and the wait interval between two retries.

// ...
//
// OnError is an abstraction of RetryOnConflict, which allows the caller to control which
// errors will result in a retry.
// TODO: Make Backoff an interface?
func OnError(backoff wait.Backoff, errorFunc func(error) bool, fn func() error) error {
Copy link
Member

Choose a reason for hiding this comment

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

Since you are here, can you rename errorFunc to retriable to be meaningful?

@danwinship
Copy link
Contributor Author

@caesarxuchao updated

@caesarxuchao
Copy link
Member

/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 Sep 11, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: caesarxuchao, danwinship

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 Sep 11, 2019
@caesarxuchao
Copy link
Member

Please squash if you can make it.

@k8s-ci-robot k8s-ci-robot merged commit 8d24762 into kubernetes:master Sep 12, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.17 milestone Sep 12, 2019
@danwinship danwinship deleted the retry-on-conflict-docs branch May 30, 2020 21:31
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/documentation Categorizes issue or PR as related to documentation. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants