Skip to content

added basic asyncio support#2547

Merged
k8s-ci-robot merged 7 commits intokubernetes-client:masterfrom
yliaog:master
Apr 28, 2026
Merged

added basic asyncio support#2547
k8s-ci-robot merged 7 commits intokubernetes-client:masterfrom
yliaog:master

Conversation

@yliaog
Copy link
Copy Markdown
Contributor

@yliaog yliaog commented Apr 27, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

added basic asyncio support, still missing dynamic client, watch, stream etc

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


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 27, 2026
@k8s-ci-robot k8s-ci-robot requested a review from roycaihw April 27, 2026 04:36
@yliaog
Copy link
Copy Markdown
Contributor Author

yliaog commented Apr 27, 2026

/assign @roycaihw

@aojea
Copy link
Copy Markdown

aojea commented Apr 27, 2026

👏

Copy link
Copy Markdown
Member

@roycaihw roycaihw left a comment

Choose a reason for hiding this comment

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

One minor comment regarding README. LGTM otherwise.

+ # There is no hard-limit defined by k8s, but the etcd default
+ # maximum request size is 1.5MiB.
+ # https://github.com/kubernetes/kubernetes/issues/19781
+ read_bufsize=2**21
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Non blocking for this PR) Some of the patches like this seem to also apply to the syncio client.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i'm not sure this applies to synchronous client, the reason to have this patch is due to the use of aiohttp as the comment mentioned.

  •        # Watch events containing large resource objects can exceed
    
  •        # aiohttp's default read buffer size
    

# Validate the run can be executed on Windows
if type(asyncio.get_event_loop()).__name__ == '_WindowsSelectorEventLoop':
raise ConfigException(
'exec: _WindowsSelectorEventLoop does NOT support subprocesses, see README.md'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We also need to port some of the root README.md to this repo

@roycaihw
Copy link
Copy Markdown
Member

Test results look good.

/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 Apr 27, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: roycaihw, yliaog

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

The pull request process is described 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

@yliaog
Copy link
Copy Markdown
Contributor Author

yliaog commented Apr 28, 2026

/cc @tomplus

@k8s-ci-robot k8s-ci-robot requested a review from tomplus April 28, 2026 00:10
@k8s-ci-robot k8s-ci-robot merged commit 32db472 into kubernetes-client:master Apr 28, 2026
10 checks passed
@tomplus
Copy link
Copy Markdown
Member

tomplus commented Apr 28, 2026

I'm happy to see you are working on it.

I'm ready to help but to be honest I'm worried about upgrading the generator. I'm not sure if you are aware of this issue: tomplus/kubernetes_asyncio#293 So I decided to stick to the old version of generator in my async lib. I applied patches if needed, I developed typing as a set of *.pyi files generated from spec etc.

In addition, I'd suggest copying my entire lib into the kubernetes-client/python-asyncio. Could you consider this? I know, maintaining two libraries may be difficult, but I believe discrepancies between sync and async are inevitable and it wouldn't be any easier maintained in a single repo.

Thanks!

@yliaog
Copy link
Copy Markdown
Contributor Author

yliaog commented Apr 29, 2026

@tomplus it's great to have your help

I was not aware of the issue tomplus/kubernetes_asyncio#293. I did a couple of quick tests using this repo(the openapi generator was upgraded to v6.6.0).

~/prj/client-python$ cat kubernetes_asyncio/.openapi-generator/COMMIT
Requested Commit/Tag : v6.6.0
Actual Commit : 7f8b853f502d9039c9a0aac2614ce92871e895ed

~/prj/client-python$ time PYTHONPATH=. python -m kubernetes_asyncio.client.api_client
real 0m0.548s
user 0m0.440s
sys 0m0.108s

the result is 0.5s, not the 12s.

~/prj/client-python$ time PYTHONPATH=. python examples_asyncio/list_pods.py
... ... ...
... ... ...

real 0m1.883s
user 0m1.444s
sys 0m0.205s

the result is 1.8s.

I think these results are acceptable, lazy imports may help futher improve it. what do you think? did i miss anything?

@yliaog
Copy link
Copy Markdown
Contributor Author

yliaog commented Apr 29, 2026

In addition, I'd suggest copying my entire lib into the kubernetes-client/python-asyncio. Could you consider this? I know, maintaining two libraries may be difficult, but I believe discrepancies between sync and async are inevitable and it wouldn't be any easier maintained in a single repo.

the goal is to keep the synchronous and asyncio clients feature parity. Some features and bug fixes are available in synchronous client, but not in asyncio client, and vice versa. The major code lies in kubernetes/ and kubernetes_asyncio directories, i think keeping them in one repo is easier to ask contributors to fix bugs in both clients, and add features to both at the same time.

another goal is to share the code between the two clients as much as possible, ideally, the only differences between the two are the inevitable ones, like await, async. I think one repo also makes it easier to share. For exmaple, the config/in_cluster_config is almost identical. For now, I kept them separate, it may be refactored in the future to share one file.

$ diff kubernetes/config/incluster_config.py kubernetes_asyncio/config/incluster_config.py
18c18
from kubernetes.client import Configuration

from kubernetes_asyncio.client import Configuration

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/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

5 participants