Skip to content

fix(server): keep nginx-example replicas defined on first run - #38

Merged
Peefy merged 1 commit into
mainfrom
cursor/fix-nginx-example-replicas-c082
Nov 25, 2026
Merged

Peefy merged 1 commit into
mainfrom
cursor/fix-nginx-example-replicas-c082

Conversation

@Peefy

@Peefy Peefy commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Fixes the first-run failure reported in https://github.com/orgs/kcl-lang/discussions/2126.

kcl run in examples/appops/nginx-example/dev failed on KCL 0.12.8 (the CLI a new user had on 2026-08-23) with:

invalid value 'UndefinedType' to load attribute 'replicas'

at models/kube/backend/server_backend.k.

Root cause

Server.replicas already defaults to option("replicas") or 1. The value is not missing. ServerBackend was reading config.replicas inside the same dict literal as MetadataBuilder(config) | {...}. On KCL 0.12.8 that pattern makes the sibling attribute load return Undefined (kcl-lang/kcl#2130), and the Kubernetes Deployment schema rejects Undefined for replicas. The same pattern in ServiceMixin can fail the same way on config.workloadType.

KCL 0.12.10 fixed the evaluator, and konfig #37 dropped the isolation workaround. That brought the discussion failure back for anyone still on 0.12.8. Current main plus the KCL the docs install today (0.13.3) fails earlier for a second reason: 0.13.1+ treats a leading underscore as module-private (kcl-lang/kcl#1576), so metadata.__META_* cannot be read from other konfig modules and the documented kcl run -D appenv=dev never renders.

Change

  • Build the workload spec in its own _spec value, then reference it from the dict that merges MetadataBuilder.
  • Precompute len(config.services) and config.workloadType in ServiceMixin before that merge.
  • Rename the cross-module metadata constants to META_APP_NAME, META_APP_NAMESPACE, META_ENV_TYPE_NAME, and META_CLUSTER_NAME.
  • scripts/test.sh now requires replicas: 1 in the nginx-example output.

Verified with KCL 0.12.8 (kcl run, the discussion command) and KCL 0.13.3 (kcl mod update then kcl run -D appenv=dev, the documented flow). Both emit a Deployment with replicas: 1, plus the Namespace and Service. All 20 examples in scripts/test.sh pass on both versions.

Open in Web Open in Cursor 

KCL 0.12.8 evaluates config.replicas as Undefined when that read sits
in the same dict literal as MetadataBuilder(config) | {...}, so the
default nginx-example fails while loading Deployment.spec.replicas
(kcl-lang/kcl discussion 2126, kcl#2130). Build the workload spec
outside that dict, and read service-mixin config the same way.

KCL 0.13.1+ treats a leading underscore as module-private, which
rejects metadata.__META_* from other konfig modules and stops the
documented kcl run before it can render. Publish those constants.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Peefy <Peefy@users.noreply.github.com>
@Peefy
Peefy merged commit dc7f6a7 into main Nov 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants