fix(k8s): alias apimachinery.pkg.apis.meta.v1 imports in 1.14 - 1.31 - #392
Merged
Conversation
Peefy
force-pushed
the
fix/k8s-meta-v1-imports
branch
from
August 24, 2026 06:33
07ddca5 to
d8f2862
Compare
KCL's auto-generated Kubernetes schema packages up to 1.31 imported the `apimachinery.pkg.apis.meta.v1` module without an alias, which causes schema resolution to fail whenever the parent package is imported via `as <alias>` (the relative-import resolver cannot fall back to the parent-package namespace). Fix by adding `as metav1` to every such import and rewriting in-file `v1.<TypeName>` references to `metav1.<TypeName>`. 1.32+ already uses this pattern and is unaffected. This unblocks downstream users on Windows / older k8s versions (e.g. konfig nginx-example pinned to 1.31.2) and resolves the failure reported in kcl-lang/kcl#2127. Affected: 3308 files across k8s 1.14 -> 1.31. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claude <claude@anthropic.com>
Extend TestK8sPackages to exercise every k8s package version touched by the bare `apimachinery.pkg.apis.meta.v1` import fix. The new networkpolicy case instantiates a NetworkPolicy that depends on both metav1.ObjectMeta (via `metadata`) and metav1.LabelSelector (via `spec.podSelector.matchLabels`), so any future regression on the `metav1` aliasing will surface as a compile or assertion failure. Per-case required-schema gates skip the ingress test for k8s 1.14 - 1.18 because networking.k8s.io/v1 Ingress was only promoted out of v1beta1 in 1.19. Local `go test ./...` reports 67 PASS / 5 SKIP across 20 versions. Signed-off-by: Claude <claude@anthropic.com>
Peefy
force-pushed
the
fix/k8s-meta-v1-imports
branch
from
August 24, 2026 06:37
d8f2862 to
cec4bfd
Compare
2 tasks
Peefy
added a commit
that referenced
this pull request
Aug 24, 2026
* fix(k8s): alias `apimachinery.pkg.apis.meta.v1` imports in 1.14 - 1.31 KCL's auto-generated Kubernetes schema packages up to 1.31 imported the `apimachinery.pkg.apis.meta.v1` module without an alias, which causes schema resolution to fail whenever the parent package is imported via `as <alias>` (the relative-import resolver cannot fall back to the parent-package namespace). Fix by adding `as metav1` to every such import and rewriting in-file `v1.<TypeName>` references to `metav1.<TypeName>`. 1.32+ already uses this pattern and is unaffected. This unblocks downstream users on Windows / older k8s versions (e.g. konfig nginx-example pinned to 1.31.2) and resolves the failure reported in kcl-lang/kcl#2127. Affected: 3308 files across k8s 1.14 -> 1.31. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claude <claude@anthropic.com> * test(k8s): cover metav1 alias fix across 1.14 - 1.33 Extend TestK8sPackages to exercise every k8s package version touched by the bare `apimachinery.pkg.apis.meta.v1` import fix. The new networkpolicy case instantiates a NetworkPolicy that depends on both metav1.ObjectMeta (via `metadata`) and metav1.LabelSelector (via `spec.podSelector.matchLabels`), so any future regression on the `metav1` aliasing will surface as a compile or assertion failure. Per-case required-schema gates skip the ingress test for k8s 1.14 - 1.18 because networking.k8s.io/v1 Ingress was only promoted out of v1beta1 in 1.19. Local `go test ./...` reports 67 PASS / 5 SKIP across 20 versions. Signed-off-by: Claude <claude@anthropic.com> * chore(k8s): bump patch versions for 1.14 - 1.31 PR #392 rewrote 3308 schema files to fix the bare `apimachinery.pkg.apis.meta.v1` import bug, but the kcl.mod files themselves were left at their old patch versions. Bump every affected package by one patch so users who pin a version (or rely on `kcl mod update`) actually pull the fix. - 1.14.1 -> 1.14.2 - ... - 1.28.1 -> 1.28.2 - 1.31.2 -> 1.31.3 1.32+ and 1.30.x unaffected paths are not touched. Signed-off-by: Claude <claude@anthropic.com> --------- Signed-off-by: Claude <claude@anthropic.com> Co-authored-by: Claude <claude@anthropic.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Up to and including k8s 1.31, the auto-generated KCL schema packages imported
apimachinery.pkg.apis.meta.v1without an alias:This breaks whenever the parent package is imported via
as <alias>(e.g.import k8s.api.networking.v1 as netv1), because the relative-import resolver does not fall back into the parent-package namespace. Symptom:This is the same class of bug that surfaced in discussion #2127 (the user hit it via
kcl_libon Windows withk8s/1.28), and it also blocks konfig'snginx-examplewhich pinsk8s = "1.31.2".Fix
Promote every
import apimachinery.pkg.apis.meta.v1toimport apimachinery.pkg.apis.meta.v1 as metav1, and rewrite in-filev1.<Type>references tometav1.<Type>. This matches the pattern already shipped in k8s 1.32+, so nothing breaks forward.Files touched:
Total: 3308 files, 10174 insertions(+), 10174 deletions(-) (one-line mechanical rewrite).
Verification
Tested locally with a fresh
kcl mod init+k8s = { path = "k8s/1.28" }dep:Compiles clean. Before the fix this fails with
attribute 'Condition' not found in 'module 'apimachinery.pkg.apis.meta.v1''.Note for the schema-generator side
The right long-term fix is in the upstream KCL schema generator — it should emit
as metav1(and any otherv1.Xaliases) by default. Until then, this PR keeps the publishedk8s/1.14-1.31modules usable.Related
kcl_lib)k8s = "1.31.2")