Skip to content

client: add Kubernetes-aware retry helpers#2634

Open
sttts wants to merge 1 commit into
kubernetes-client:masterfrom
sttts:agent/kubernetes-retry-utils
Open

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

Conversation

@sttts

@sttts sttts commented Jul 15, 2026

Copy link
Copy Markdown

What

Add Kubernetes-aware retry helper modules modeled after k8s.io/client-go/util/retry and the client-go REST Retry-After behavior.

This PR provides only the non-generated helper surface:

  • kubernetes.utils.retry with sync retry helpers: Backoff, DEFAULT_BACKOFF, DEFAULT_RETRY, on_error(...), retry_on_conflict(...), on_retry_after_error(...), and Retry-After helpers
  • kubernetes.aio.utils.retry with the same helper surface for the separately packaged AIO client, source-linked to the sync helper module so the wheel gets an independent copy at build time
  • exports from kubernetes.utils and kubernetes.aio.utils
  • setup-asyncio.py packaging for kubernetes.aio.utils
  • helper-level tests for sync and AIO retry behavior

The generated REST/Configuration integration is intentionally not part of this PR. That follows in kubernetes-client/gen#304 after these helper modules exist.

Why

The generated Python client exposes transport-level urllib3 retries, but it does not provide Kubernetes-aware retry helpers equivalent to client-go. Transport retries cannot re-read objects before retrying a write after a 409 conflict, and callers currently have to duplicate retry/backoff behavior.

For writes, this PR provides explicit helpers so callers can re-read the object inside the retry function before submitting an update or patch after a 409 conflict.

The helper semantics follow client-go retry behavior closely, including wait.Backoff step/cap behavior and Retry-After delay selection helpers for the later generated REST integration.

Follow-up

Tests

  • .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 kubernetes/utils/retry.py kubernetes/aio/utils/retry.py kubernetes/utils/retry_test.py kubernetes/aio/utils/retry_test.py kubernetes/utils/__init__.py kubernetes/aio/utils/__init__.py
  • setup-asyncio.py build_py check confirmed kubernetes/aio/utils/retry.py is copied as a regular file, not a symlink, in the build output
  • git diff --check

@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
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

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-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added 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
@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 assign yliaog for approval. 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

@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
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
@sttts sttts force-pushed the agent/kubernetes-retry-utils branch from ee00eac to ec56a76 Compare July 15, 2026 16:58
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. 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant