Skip to content

client: add Kubernetes-aware retry helpers#2634

Open
sttts wants to merge 3 commits into
kubernetes-client:masterfrom
sttts:agent/kubernetes-retry-utils
Open

client: add Kubernetes-aware retry helpers#2634
sttts wants to merge 3 commits into
kubernetes-client:masterfrom
sttts:agent/kubernetes-retry-utils

Conversation

@sttts

@sttts sttts commented Jul 15, 2026

Copy link
Copy Markdown

Summary

Add client-go-style retry helper APIs for the sync and AIO Python clients.

  • Shared primitives live in kubernetes/base/retry.py.
  • Public sync helpers live in kubernetes.utils.retry.
  • Public AIO helpers live in kubernetes.aio.utils.retry.
  • Helpers cover 409 conflict retries for writes and Retry-After/backoff behavior for later generated read retry wiring.
  • AIO utils are included in both setup-asyncio.py and the combined setup-release.py package list.

The generated REST/Configuration wiring is intentionally separate and follows in kubernetes-client/gen#304.

Validation

  • .venv/bin/python -m unittest kubernetes.utils.retry_test kubernetes.aio.utils.retry_test
  • .venv/bin/python -m pytest -q kubernetes/utils/retry_test.py kubernetes/aio/utils/retry_test.py
  • .venv/bin/python -m pycodestyle ... for retry helpers, exports, and setup-release.py
  • setup.py, setup-asyncio.py, and setup-release.py build_py checks confirmed symlinked helper files are copied as regular files
  • git diff --check
Add Kubernetes-aware retry helper APIs for Python clients, modeled on client-go retry behavior.

@kubernetes-prow kubernetes-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 15, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @sttts!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 15, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog July 15, 2026 14:53
@sttts sttts changed the title utils: add Kubernetes retry helpers client: add Kubernetes-aware retry helpers Jul 15, 2026
@kubernetes-prow kubernetes-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 15, 2026
@sttts
sttts marked this pull request as ready for review July 15, 2026 15:09
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2026
@sttts
sttts marked this pull request as draft July 15, 2026 15:16
@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2026
@sttts
sttts marked this pull request as ready for review July 15, 2026 15:18
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2026
@sttts
sttts marked this pull request as draft July 15, 2026 15:25
@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2026
@sttts
sttts marked this pull request as ready for review July 15, 2026 15:57
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2026
@kubernetes-prow kubernetes-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 15, 2026
@sttts
sttts force-pushed the agent/kubernetes-retry-utils branch from ee00eac to ec56a76 Compare July 15, 2026 16:58
Comment thread kubernetes/utils/retry.py Outdated
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

kuberentes/utils/ is for synchronous version of the client

kubernetes/aio/utils is for asynchronous version of the client

this file should not use asyncio, i think.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it's for the default of the sleep func. But yes, I agree it should be the inverse.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated. Looks a lot better now: shared backoffs in base, linked into the sync and async variants. The aio helper implemented on-top. I.e. no duplicated code.

@roycaihw

Copy link
Copy Markdown
Member

/assign @yliaog

@sttts
sttts force-pushed the agent/kubernetes-retry-utils branch from ec56a76 to 50d8aed Compare July 17, 2026 07:00
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sttts
Once this PR has been reviewed and has the lgtm label, please ask for approval from yliaog. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details 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

@kubernetes-prow kubernetes-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 17, 2026
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
@sttts
sttts force-pushed the agent/kubernetes-retry-utils branch from 50d8aed to 3e89602 Compare July 17, 2026 07:20
sttts added 2 commits July 17, 2026 14:08
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
@sttts

sttts commented Jul 21, 2026

Copy link
Copy Markdown
Author

Fixed in the latest push: setup-release.py now includes kubernetes.aio.utils, so the combined release package includes the new AIO retry helpers.

I also verified setup-release.py build_py copies kubernetes/aio/utils/retry.py, kubernetes/aio/utils/_retry_base.py, and kubernetes/aio/utils/retry_test.py into the combined release build output, and updated the PR description with that validation.

@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 21, 2026
# Kubernetes Go retry algorithms used by client-go:
# - https://github.com/kubernetes/client-go/blob/master/util/retry/util.go
# - https://github.com/kubernetes/client-go/blob/master/rest/with_retry.go
async def async_on_error(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need async_ prefix in the function name? the function is under aio/utils, so it should be async to users. WDYT?

raise last_error


async def async_retry_on_conflict(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto

backoff, is_conflict, fn, sleep_func, random_func)


async def async_on_retry_after_error(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants