Skip to content

Migrate synchronous Python client generation to OpenAPI Generator v7 - #305

Merged
kubernetes-prow[bot] merged 2 commits into
kubernetes-client:masterfrom
tamird:prototype/python-modern-generator
Jul 28, 2026
Merged

Migrate synchronous Python client generation to OpenAPI Generator v7#305
kubernetes-prow[bot] merged 2 commits into
kubernetes-client:masterfrom
tamird:prototype/python-modern-generator

Conversation

@tamird

@tamird tamird commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

OpenAPI Generator v7 removed python-legacy, the backend used by the synchronous Kubernetes Python client. OpenAPITools/openapi-generator#24402 introduces standard-library lazy imports, removing the third-party lazy-imports dependency without eagerly importing the generated API and models.

Generate the synchronous client from merged source commit 830e9d156960bb7f51a5337f31636a7e73226474. Centralize the Python schema, discovery, authentication, PATCH, and postprocessing corrections needed by kubernetes-client/python#2652 and the independently proposed asyncio migration in #306.

The pinned generator identifies itself as 7.25.0-SNAPSHOT; 7.25.0 has not been released.

@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 20, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from yliaog and yue9944882 July 20, 2026 23:03
@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 20, 2026
@kubernetes-prow

Copy link
Copy Markdown

Welcome @tamird!

It looks like this is your first PR to kubernetes-client/gen 🎉. 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/gen 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 20, 2026
@tamird
tamird marked this pull request as ready for review July 20, 2026 23:55
@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 20, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from brendandburns July 20, 2026 23:55
@tamird
tamird force-pushed the prototype/python-modern-generator branch 3 times, most recently from f9cf540 to ad0715f Compare July 21, 2026 22:36
@kubernetes-prow kubernetes-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 21, 2026
@tamird
tamird force-pushed the prototype/python-modern-generator branch from ad0715f to c3b3c7d Compare July 22, 2026 01:40
OpenAPI Generator v7 removed python-legacy. Select the modern Python
generator with legacy compatibility, independent implicit clients, lazy
package imports, and explicit name mappings so the synchronous client
keeps its public API without eagerly loading every model and API.

Preprocess the Kubernetes Swagger document to preserve exec arguments,
port-forward ports, custom-object patch media types, bearer-token
aliases, Namespace-delete responses, and the missing GroupVersionKind
definition. Namespace deletion can return a Namespace or Status, so
leave its successful response as a parsed object instead of validating
it against the wrong model.

Replace the broad shell rewrites with focused Python post-processing
that preserves prose, qualifies package references, accepts Kubernetes
IntOrString and CRD JSON-schema unions without invalid coercion, accepts
JSON Patch operation lists and generated model instances in PATCH
methods, defers eager Pydantic call validators, preserves importlib
metadata on lazy packages, and normalizes generated whitespace.
@tamird
tamird force-pushed the prototype/python-modern-generator branch from c3b3c7d to 31aa737 Compare July 22, 2026 16:06
@tamird

tamird commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@yliaog I guess you need to merge this, yeah?

@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 23, 2026
@tamird

tamird commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

/assign @yliaog

@yliaog yliaog left a comment

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.

could you please keep the sync and async commits in separate PR? we can merge the PR for sync client first.

Comment thread openapi/python-asyncio.sh
@tamird
tamird force-pushed the prototype/python-modern-generator branch from fc5b727 to d38e3aa Compare July 23, 2026 04:42
@tamird tamird changed the title Migrate Python client generation to v7.24.0 Migrate synchronous Python client generation to v7.24.0 Jul 23, 2026
@tamird

tamird commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@yliaog Split as requested. This PR is the original synchronous-only 31aa737; the independently master-targeted asyncio generator and its required postprocessing are in #306. openapi/python-asyncio.sh is unchanged, so the synchronous PR can land first.

GitHub is waiting for a repository maintainer to approve the current generator runs: https://github.com/kubernetes-client/gen/actions/runs/29980454288 and https://github.com/kubernetes-client/gen/actions/runs/29980478522. The exact synchronous commit already has a passing run at https://github.com/kubernetes-client/gen/actions/runs/29936513495. The generated client also needs maintainer approval for validation and real-cluster end-to-end tests: https://github.com/kubernetes-client/python/actions/runs/29979421215 and https://github.com/kubernetes-client/python/actions/runs/29979421210.

— tamirdex

@tamird
tamird force-pushed the prototype/python-modern-generator branch from 7f74c6d to 31aa737 Compare July 23, 2026 04:47
@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 23, 2026
@yliaog

yliaog commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

i took a look at the PR, it looks good.

Let's discuss kubernetes-client/python#2631 (comment)
reach a consenus there first.

@tamird

tamird commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@yliaog The consensus you were waiting for is now explicit in kubernetes-client/python#2631 (comment). The corresponding dependency-free generator fix is OpenAPITools/openapi-generator#24402, and all 25 Python sample checks are passing.

Once that fix lands, this synchronous migration can consume it independently of the asynchronous migration in #306.

— tamirdex

@yliaog

yliaog commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

let's wait for OpenAPITools/openapi-generator#24402 to merge. I think this PR needs modification after it merges.

@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 27, 2026
@tamird tamird changed the title Migrate synchronous Python client generation to v7.24.0 Migrate synchronous Python client generation to OpenAPI Generator v7 Jul 27, 2026
@tamird

tamird commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@yliaog OpenAPITools/openapi-generator#24402 has merged. This PR now pins its exact 830e9d156 source and contains the shared Python schema, discovery, authentication, PATCH, and postprocessing fixes. #306 independently changes only the Kubernetes aio entrypoint and its dedicated XML; both the external python-asyncio.sh and its v6 XML are byte-for-byte unchanged.

The regenerated synchronous client is kubernetes-client/python#2652 and the asyncio client is kubernetes-client/python#2647. Each records 7.25.0-SNAPSHOT rather than claiming a release.

GitHub requires maintainer approval for the exact generator runs https://github.com/kubernetes-client/gen/actions/runs/30281344413 and https://github.com/kubernetes-client/gen/actions/runs/30281335564, and the client validation and end-to-end runs https://github.com/kubernetes-client/python/actions/runs/30282192543, https://github.com/kubernetes-client/python/actions/runs/30282192475, https://github.com/kubernetes-client/python/actions/runs/30281290930, and https://github.com/kubernetes-client/python/actions/runs/30281291447. Could you approve the runs and review this synchronous generator first?

[tamirdex]

Comment thread openapi/python.sh
source "${SCRIPT_ROOT}/openapi-generator/client-generator.sh"
source "${SETTING_FILE}"
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v7.24.0}"
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-830e9d156960bb7f51a5337f31636a7e73226474}"

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.

ok for now, later let's change it to v7.25.0

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.

Agreed. v7.24.0 is still the latest published release, so this currently pins the exact merged upstream commit containing the dependency-free lazy import fix. Once v7.25.0 is actually published, we can replace that immutable commit pin with the release tag and regenerate both clients.

[tamirdex]

Comment thread openapi/python.xml
<packageName>${generator.package.name}</packageName>
<packageVersion>${generator.client.version}</packageVersion>
<sortParamsByRequiredFlag>true</sortParamsByRequiredFlag>
<lazyImports>true</lazyImports>

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.

is this still needed?

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.

Yes. OpenAPI Generator v7 defaults lazyImports to false: https://github.com/OpenAPITools/openapi-generator/blob/830e9d156960bb7f51a5337f31636a7e73226474/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java#L215. OpenAPITools/openapi-generator#24402 replaced the old third-party lazy-imports implementation with the standard library; it did not change that default.

Without this option, importing the client eagerly imports all 768 generated model exports and 65 API exports. Keeping it enabled selects the new dependency-free lazy path, avoiding that startup regression while removing lazy-imports from the distribution.

[tamirdex]

@yliaog

yliaog commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

could you move this commit to the PR that migrates asyncio? then this PR would focus just on sync client gen.

Share Python client generation across sync and asyncio

@tamird
tamird force-pushed the prototype/python-modern-generator branch from d74116f to 6282bad Compare July 28, 2026 02:45
@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 28, 2026
@tamird

tamird commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@yliaog Done. This PR now contains only synchronous client generation at 6282bad. The shared 78ccac4 commit and asyncio-specific generation are in #306, so the synchronous change can land first.

[tamirdex]

@yliaog

yliaog commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

thanks for the PR

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 28, 2026
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tamird, 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

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit fa1b9c8 into kubernetes-client:master Jul 28, 2026
3 checks passed
@tamird
tamird deleted the prototype/python-modern-generator branch July 28, 2026 07:08
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

2 participants