python sdk kcl_lib 有直接运行示例应用nginx-example的方法吗?我这样配置直接报错! #2127
Replies: 5 comments 9 replies
|
Hi! I tried to reproduce your two errors with the same vendored Root causeE2L23 — "the name 'v1' is defined multiple times" Your You can confirm by reading the next error: it says E2G22 — "'TypedLocalObjectReference' not found in 'k8s.apimachinery.pkg.apis.meta.v1'" In the canonical KCL Kubernetes schema (the one published under For reference, this is what the upstream file looks like ( import api.core.v1 as corev1 # aliased to avoid the v1 collision
schema IngressBackend:
...
resource?: corev1.TypedLocalObjectReferenceTwo key things: it uses Recommended fix — use the official
|
|
Quick follow-up after digging deeper into the modules repo: I went to look at the source and the picture is more nuanced than what I wrote above. Your But the same class of bug exists in 157 other files in import apimachinery.pkg.apis.meta.v1
...
conditions?: [v1.Condition] # <-- resolves to "apimachinery.pkg.apis.meta.v1" but the
# schema lookup fails because the import path
# isn't aliasedWhenever you This is the same compiler behavior that blocked konfig's I've opened a PR that does the mechanical rewrite for every affected file: What it does:
Verified locally against If you (or anyone else on Windows) is stuck on a vendored 1.28, you can also just bump to |
|
Just a quick status update: the fix is now merged into the modules repo. PR: kcl-lang/modules#392 (merged at f36e5838) What landed:
For your case (Windows + vendored 1.28): pull the updated modules and your If anything still blows up on your side after re-pulling, drop the new error here and I will dig in. |
I pulled the module into the project directory using However, an error occurs when I add an Error traceback: 在konfig\models\kube\render\render.k 这个文件渲染之后的结果才是真正的部署yaml, 那才是我想要的结果,有这个功能吗? |
|
Quick follow-up on adding Short answer: yes, that is the intended way to get the actual deployment YAML — But there are two real bugs in the konfig repo that bite you the moment you try this. I just reproduced both locally with 1.
|
| Position | Type |
|---|---|
volume_patch.k:5 lambda's volumes parameter |
models.kube.frontend.volume.Volume (konfig's frontend schema) |
config.volumes at the call site |
also models.kube.frontend.volume.Volume per frontend.Job.volumes declaration |
If the types look identical on paper but the compiler still rejects them, the issue is almost always that the same Volume schema is being reached through two different module paths and KCL is comparing by full pkgpath, not by name. When base.k is in the program and pulls in konfig.models.kube.frontend.*, while render.k imports models.kube.frontend.* directly, KCL keeps them as distinct identities.
The error is on the lambda parameter — that parameter is being inferred with whatever pkgpath was used at the lambda definition site (models.kube.frontend.volume.Volume), but config.volumes flows through frontend.Job whose volumes field was bound through the konfig.models.kube.frontend.volume.Volume pkgpath, so the two collide.
The fix is the same as fix #1: make every file agree on the import path. Once render.k uses konfig.models.kube.frontend.* (option A above), the lambda's volume.Volume parameter and config.volumes resolve through the same pkgpath and the E2G22 should disappear.
If after that fix the E2G22 is still there, it's a genuine konfig logic bug and I will dig into volume_patch / to_kube_volume separately.
What I am doing about it
I've forked kcl-lang/konfig and will open a PR with the option A fix to render.k. Once it lands, your k_filename_list = [base/base.k, dev/main.k, konfig/models/kube/render/render.k] should drop clean YAML straight to stdout (or into result.yaml_result from the Python SDK).
Will report back here with the PR link once it's open and CI green.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
D:\MyPythonProject\k8s-app-deployer.venv\Scripts\python.exe D:\MyPythonProject\k8s-app-deployer\prase_kcl_tpl.py
Traceback (most recent call last):
File "D:\MyPythonProject\k8s-app-deployer\prase_kcl_tpl.py", line 95, in
print(exclude_progra_with_mod().yaml_result)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\MyPythonProject\k8s-app-deployer\prase_kcl_tpl.py", line 83, in exclude_progra_with_mod
result = api_client.exec_program(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\MyPythonProject\k8s-app-deployer.venv\Lib\site-packages\kcl_lib\api\service.py", line 140, in exec_program
return self.call("KclService.ExecProgram", args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\MyPythonProject\k8s-app-deployer.venv\Lib\site-packages\kcl_lib\api\service.py", line 667, in call
raise Exception(result.decode(encoding="utf-8").removeprefix("ERROR:"))
Exception:
error[E2L23]: CompileError
--> D:\MyPythonProject\k8s-app-deployer\k8s\1.28\api\networking\v1\ingress_backend.k:6:1
|
6 | import api.core.v1
| ^ the name 'v1' is defined multiple times, 'v1' must be defined only once
|
error[E2G22]: TypeError
--> D:\MyPythonProject\k8s-app-deployer\k8s\1.28\api\networking\v1\ingress_backend.k:22:16
|
22 | resource?: v1.TypedLocalObjectReference
| ^ attribute 'TypedLocalObjectReference' not found in 'module 'k8s.apimachinery.pkg.apis.meta.v1''
|
All reactions