kcl-lang / kcl-lang.io

KCL Website and Documentation Repo: https://kcl-lang.io
https://kcl-lang.github.io
Apache License 2.0
13 stars 35 forks source link

[Example Issue] kcllang/kcl:latest docker image has problems processing variables. #302

Closed cr7258 closed 6 months ago

cr7258 commented 6 months ago

Bug Report

I'm practicing the tutorial according to this guide: Implement GitOps with KCL and ArgoCD. However, the deployment manifest can't be applied to the cluster properly with the following error:

image

After checking the YAML, I found that the container name variable was not rendered correctly. The expected output was name: guestbook instead of guestbook: guestbook.

image

It seems the kcllang/kcl:latest docker image has problems processing variables or is outdated.

1. Minimal reproduce step (Required)

https://github.com/kcl-lang/kcl-lang.io.git
cd kcl-lang.io/examples/gitops/config

Run locally:

kcl run
image

Using kcllang/kcl:latest docker image:

docker run -v $(PWD):/config -w /config kcllang/kcl:latest kcl run
image

2. What did you expect to see? (Required)

The variable should be rendered as name: guestbook when use the kcllang/kcl:latest docker image.

3. What did you see instead (Required)

4. What is your KCL components version? (Required)

KCL local version v0.7.5 KCL docker version v0.8.0-beta.1

Peefy commented 6 months ago

Good Catch! This is as expected, as fixing this issue in the latest version (KCL v0.8) resulted in https://github.com/kcl-lang/kcl/issues/1061 Therefore, in version 0.8 of kcl, we should appropriately fix the configuration code. PRs welcome! ❤️

            template.spec.containers = [
                {
                    "name" = name # Quote the name attribute instead of name = name
Peefy commented 6 months ago

Or we can change this code like this and add a unit test case for the kubernetes_render.k file and ensure the container name attribute must be name and its value must equal to guest book.

image

Peefy commented 6 months ago

I've opened a PR #304 to fix this. Could you help review it? Thank you!