Repository navigation
Restore submodule access through the deprecated kubernetes.client.apis package - #2727
Merged
kubernetes-prow[bot] merged 1 commit intoOct 8, 2026
Conversation
kubernetes.client.api now defines __all__ with class names only and loads its submodules lazily, so the deprecated alias's star import no longer brings in names such as core_v1_api and "from kubernetes.client.apis import core_v1_api" raises ImportError. Resolve submodule names on demand with a module-level __getattr__. The alias is hand-written and outside the generated tree, so the fix survives regeneration.
Contributor
|
/lgtm |
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: yliaog, yurnov The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
kubernetes-prow
Bot
merged commit Oct 8, 2026
ffba441
into
kubernetes-client:master
10 checks passed
Contributor
Author
|
Thanks @yliaog for the review. Can I request to cherry-pick it to the |
Contributor
|
Yes, that will done later today or early tomorrow. |
yurnov
added a commit
to yurnov/ansible-for-kubernetes-demo
that referenced
this pull request
Oct 9, 2026
Follow-up to #9 (#8). kubernetes Python client 37.0.1 fixes importing API submodules such as `core_v1_api` from the deprecated `kubernetes.client.apis` package (kubernetes-client/python#2727, [changelog](https://github.com/kubernetes-client/python/blob/release-37.0/CHANGELOG.md#v3701)). That is what broke `k8s_exec` in playbook 03. `requirements.txt` now excludes only the broken release: `kubernetes>=24.2.0,!=37.0.0`. Unlike the `<37.0.0` pin, this does not hold the canary back, so other 37.x breakage is no longer hidden and the exclusion can stay. The collection-side fix, ansible-collections/kubernetes.core#1274, is still open. The demo no longer depends on it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind bug
/kind regression
What this PR does / why we need it:
Since v37.0.0,
from kubernetes.client.apis import core_v1_apiraisesImportError, which breaks code that still uses the deprecated alias, for examplek8s_execin ansible-collections/kubernetes.core#1273. The alias star-importskubernetes.client.api, which now defines__all__with class names only and loads its submodules lazily (#2631, #2652), so the submodule names are no longer re-exported. This adds a module-level__getattr__(PEP 562) to the alias that resolves submodule names on demand, plus a regression test.Which issue(s) this PR fixes:
Fixes #2726
Special notes for your reviewer:
client/apis/__init__.pyis not listed in [kubernetes/.openapi-generator/FILES][files], and gen only removesclient/api,client/modelsanddocsbefore generating ([CLEANUP_DIRS][cleanup], [removed one by one withrm -rf][rm]). The file hasn't changed since 2019 and was kept through the v7.24.0 and v7.25.0 regenerations. The new test sits next to the other hand-written tests inkubernetes/test/.__getattr__rather than binding every submodule into the alias namespace with apkgutil.iter_modules()loop: it is what the issue proposed, it keeps the change small, and type checkers can see it. With this change mypy resolvesfrom kubernetes.client.apis import core_v1_apitoModuleType. Onmasterit reportsattr-defined, and dynamically bound names would still get that error.AttributeError, sofrom ... importraisesImportErrorandhasattr()returnsFalse. AModuleNotFoundErrorfor any other module, such as a missing dependency inside an API module, propagates unchanged. Private and non-identifier names are rejected without an import attempt, so probes like__wrapped__or the__all__lookup of a star import don't try to import anything.from kubernetes.client.apis import *does not export the submodule names, anddir(kubernetes.client.apis)does not list them. I left those as they are for a deprecated alias. Dotted imports (import kubernetes.client.apis.core_v1_api) didn't work in 36.x either.__getattr__ofkubernetes.client.api.master(test_from_import_submodule, all 66 subtests oftest_every_api_submodule_is_reachable, and the two tests for the new guards) and passes with the fix. Other unit test results are the same as onmaster. Tested on Python 3.10, 3.12 and 3.14.release-37.0for a 37.0.1? The commit applies cleanly there, and the new test passes on it.AI Disclosure
Parts of this PR (including complete unit tests) were generated using Anthropic Sonnet 5.5. All generated code has been manually reviewed, tested, and verified for accuracy.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
N/A