Repository navigation
fix(render): align render.k imports with the rest of konfig - #36
Merged
Merged
Conversation
Peefy
force-pushed
the
fix/render-issues
branch
from
August 24, 2026 09:29
2f75a33 to
2425879
Compare
Two changes:
1. Convert render.k and server_backend.k to use the
`konfig.models.kube.frontend` package-qualified import path
so that the Server / Volume types referenced inside konfig carry
the same pkgpath that user code sees when it imports the package.
Without this, the same short name (`frontend`) or schema name
(`Server` / `Volume`) registers under two different pkgpaths
depending on whether the importer uses the relative or the
absolute form, and KCL's import-name dedup and structural type
checker raise E2L23 / E2G22.
2. Pre-compute `config.replicas` into `_replicas` before the
`workloadAttributes` dict literal. Reading `config.replicas`
inside the same dict literal that calls
`utils.MetadataBuilder(config) | {...}` (the metadata key is set
first via a lambda+merge) triggers an evaluator quirk where the
attribute is resolved to `Undefined`. Pre-computing into a local
variable avoids the bad read.
Tested locally: `kcl run` succeeds for the nginx-example stack
(Deployment / Namespace / Service emitted as YAML).
Closes #2127 (konfig-side half).
Signed-off-by: Peefy <xpf6677@163.com>
The previous commit fixed `replicas` by pre-computing it to `_replicas`.
But the same evaluator quirk hits every `config.X` read inside a dict
literal that also contains `MetadataBuilder(config) | {...}` — CI
failed on `config.useBuiltInSelector` next.
Extract the whole spec sub-dict into its own `_spec` variable so all
`config.X` reads sit outside the dict-with-merge pattern. Then
`workloadAttributes` only references the already-built `_spec`.
Signed-off-by: Peefy <xpf6677@163.com>
Peefy
force-pushed
the
fix/render-issues
branch
from
August 24, 2026 09:31
8716155 to
555800b
Compare
The bare `config?.labels` (no `or` fallback) returns Undefined when
the attribute is absent. With kcl 0.12.x, an Undefined value leaking
out of a lambda call placed inside a dict literal breaks sibling
key reads: any subsequent `something.X` in the same dict literal
resolves to Undefined.
Example failure surface: server_backend.k:67 (config.replicas),
service_mixin.k:15 (len(config.services)), and other call sites of
`MetadataBuilder(_x) | {...}`.
Return `{}` instead of Undefined for labels/annotations. This matches
K8s semantics (labels/annotations should be a map, never None) and
removes the root cause for every caller, so individual workarounds
in server_backend.k become unnecessary.
Signed-off-by: Peefy <xpf6677@163.com>
Apply targeted workarounds for the evaluator regression where a
dict literal that contains both `MetadataBuilder(_) | {...}` and
sibling-key `config.X` reads (or `something?.X or (...config.Y...)`)
resolves the bare attribute access to `Undefined`.
- service_mixin.k: pre-compute `_singleService` outside the
metadata override so `len(config.services)` isn't evaluated
in the broken pattern.
- job_backend.k: convert relative imports to package-qualified
`konfig.*` (same E2G22/E2L23 fix as server_backend.k) and extract
the `spec` dict to its own statement so `config.X` reads are not
co-located with the `MetadataBuilder(config) | {...}` key.
Server-side fix at MetadataBuilder level alone was insufficient
because the override-dict's value expression also triggers the bug.
A complete root-cause fix needs the KCL evaluator; this commit
keeps konfig green across both kcl 0.11.x and 0.12.x.
Signed-off-by: Peefy <xpf6677@163.com>
…dict
In kcl 0.12.x, evaluating `_s?.selector or kubernetes?[config.workloadType]?...`
inside the Service spec dict (which is a sibling key of
`metadata = MetadataBuilder(_) | {...}`) resolves `config` itself
to Undefined. Pre-computing `config.workloadType` into `_workloadType`
before the dict avoids the bad read.
Signed-off-by: Peefy <xpf6677@163.com>
2 tasks
Peefy
added a commit
to Peefy/konfig-1
that referenced
this pull request
Aug 24, 2026
Now that kcl-lang/kcl#2130 is fixed upstream (commit 703b8ead: "fix(evaluator): restore local_vars after call, don't extend"), the workarounds introduced in PR kcl-lang#36 to keep the runtime usable against that bug are no longer required. Removes: - the inline `{}` fallback on labels/annotations in `models.kube/utils/metadata_builder.k` - the pre-computed `_singleService`/`_workloadType` locals in `models/kube/mixins/service_mixin.k` - the isolated `_spec` dict extraction in `models/kube/backend/server_backend.k` This restores the simpler, native dict-literal/merge-operator code that the library was originally written against. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Peefy <xpf6677@163.com>
Peefy
added a commit
that referenced
this pull request
Aug 29, 2026
Now that kcl-lang/kcl#2130 is fixed upstream (commit 703b8ead: "fix(evaluator): restore local_vars after call, don't extend"), the workarounds introduced in PR #36 to keep the runtime usable against that bug are no longer required. Removes: - the inline `{}` fallback on labels/annotations in `models.kube/utils/metadata_builder.k` - the pre-computed `_singleService`/`_workloadType` locals in `models/kube/mixins/service_mixin.k` - the isolated `_spec` dict extraction in `models/kube/backend/server_backend.k` This restores the simpler, native dict-literal/merge-operator code that the library was originally written against. Signed-off-by: Peefy <xpf6677@163.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.
Closes the second-half of https://github.com/orgs/kcl-lang/discussions/2127 — once PR kcl-lang/modules#392 lands, konfig users on
k8s 1.14 - 1.31are unblocked on the import aliasing side, but addingrender.kto thek_filename_liststill fails with two new errors that live entirely in this repo.What fails today
Why
crates/sema/src/resolver/import.rs:139does a literal-string comparison on the import path — there is no normalization. The example files all write:import konfig.models.kube.frontendwhile
render.kwrites:import models.kube.frontendBoth resolve to the same module, but the literal strings differ, so the check raises
E2L23. Worse, the duplicatefrontendsymbol with two different pkgpaths keeps the renderer from consolidatingVolumetypes — KCL compares types by full pkgpath, somodels.kube.frontend.volume.Volume(reached viarender.k) andkonfig.models.kube.frontend.volume.Volume(reached viabase.k → frontend.Job.volumes) become distinct identities, andE2G22fires onvolume_patch.Fix
Align
render.kwith the rest of the repo:import manifestsis left alone — it is a KCL built-in pseudo-module (manifests.yaml_streamis registered as a built-in incrates/sema/src/builtin/system_module.rs), not a real package on disk.Verification
Reproduced with
kcl 0.12.3against the konfig checkout (the latest version where the example harness still passes):guestbook/dev,guestbook/prod,guestbook/testall render multi-doc YAML as well.About the CI
Example testsfailureThe
Example testsjob fails on every single example directory on bothmainand this branch when running onkcl 0.12.8:Verified locally with
kcl v0.12.8downloaded fromkcl-lang/cli:git checkout mainand run./scripts/test.sh→ all 20 examples FAIL with the sameUndefinedTypeerrorgit checkout fix/render-issues→ identical failure./scripts/test.shpasses all 20 examples onkcl v0.12.3Root cause is in the KCL compiler, not konfig —
frontend.Server.replicasis declared asreplicas: int = option(\"replicas\") or 1, andkcl 0.12.8is no longer evaluating theor 1default whenconfig.replicasis accessed through the backend rule pipeline. Fixing that is a separate concern that belongs inkcl-lang/kcl, not in this PR. Happy to file an upstream issue / PR if helpful, or to open a follow-up PR here that pins CI tokcl 0.12.3until the regression is fixed upstream.