Coder Social home page Coder Social logo

cli's People

Contributors

dependabot[bot] avatar ekirmayer avatar fossabot avatar liangyuanpeng avatar peefy avatar zong-zhe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cli's Issues

bug: `kcl mod add k8s` panic

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Screenshot 2023-12-22 at 11 56 01

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

kcl mod add k8s should add the dependency k8s:1.29 successfully.

3. What did you see instead (Required)

It panic.

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

The main branch of KCL CLI installed by go install kcl-lang.io/cli/cmd/kcl@main.

Enhancement: `kcl mod add` supports add the dependeny for oci by oci url

Enhancement

Currently, the following commands in kcl mod add are supported to add dependencies.

# Add the module dependency named "k8s"
kcl mod add k8s

# Add the module dependency named "k8s" with the version "1.28"
kcl mod add k8s:1.28

# Add the module dependency from the GitHub
kcl mod add --git https://github.com/kcl-lang/konfig --tag v0.4.0

# Add a local dependency
kcl mod add /path/to/another_module`

For KCL packages from OCI, the command kcl mod add k8s can only use the default OCI registry, which is not flexible enough, so we decided to add the OCI Url to support downloading third-party dependencies from different OCI registries.

At the same time, align the kcl mod add command with the kcl mod run command style. The adjusted commands for adding git and oci dependencies are shown as follows.

# For oci 
kcl mod add oci://ghcr.io/kcl-lang/helloworld

# For git
kcl mod add git://ghcr.io/kcl-lang/helloworld

Can not push package to ghcr.io since v0.9.2

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

$ kcl mod push oci://ghcr.io/liangyuanpeng/kcl/kind
package 'kind' will be pushed
failed to push 'ghcr.io/liangyuanpeng/kcl/kind'
GET "https://ghcr.io/v2/liangyuanpeng/kcl/kind/blobs/uploads/": response status code 405: unsupported: The operation is unsupported.

Once i use v0.9.1 and it's working for me.

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

3. What did you see instead (Required)

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

kcl mod init support flag of version

Feature Request

Is your feature request related to a problem? Please describe:

I want to work for it, assign to me please.

Add version option at kcl-lang/kpm#276

Describe the feature you'd like:

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

Bug: the diagnostic for `kcl vet` show an invalid file path

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

The test.json

{
    "name": 10,
    "age": 18,
    "message": "This is Alice"
}

The main.k

schema User:
    name: str
    age: int
    message?: str

The command

kcl vet test.json main.k

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

error[E2G22]: TypeError
 --> test.json:2:5
  |
2 |     "name": 10,
  |     ^ expected str, got int(10)
  |

 --> main.k:2:5
  |
2 |     name: str
  |     ^ variable is defined here, its type is str, but got int(10)
  |

3. What did you see instead (Required)

error[E2G22]: TypeError
 --> /var/folders/yt/9fs5v0ls7_q4kn7dq3k6nz3h0000gp/T/.tmpbX6kWB:2:5.  # The invalid file path
  |
2 |     "name": 10,
  |     ^ expected str, got int(10)
  |

 --> main.k:2:5
  |
2 |     name: str
  |     ^ variable is defined here, its type is str, but got int(10)
  |

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

The main branch

`kcl mod add k8s` returns 403

Bug Report

I am testing kcl and was just trying out the examples in https://www.kcl-lang.io/docs/user_docs/guides/working-with-k8s/generate-k8s-manifests#3-get-the-kubernetes-modules-from-registry

I can access https://ghcr.io/v2/kcl-lang/k8s/tags/list via xh

# get token
xh "https://ghcr.io/token?scope=repository%3Akcl-lang%2Fk8s%3Apull&service=ghcr.io"

# show tags
xh https://ghcr.io/v2/kcl-lang/k8s/tags/list "Authorization:Bearer <token>"

1. Minimal reproduce step (Required)

kcl mod add k8s

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

Some success message? I do not know, what I should expect to see...

3. What did you see instead (Required)

adding dependency 'k8s'
failed to select latest version from 'ghcr.io/kcl-lang/k8s'
GET "https://ghcr.io/v2/kcl-lang/k8s/tags/list": GET "https://ghcr.io/token?scope=repository%3Akcl-lang%2Fk8s%3Apull&service=ghcr.io": response status code 403: denied: denied

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

kclvm: 0.8.4
kclvm_cli: 0.8.4
kcl: 0.8.4

Since I am using nixos I created my own derivations like this: https://github.com/diefans/kcl-nix

kcl installs the incorrect build of kclvm_cli/libkclvm_cli_cdylib.so

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. On a non-x86_64 system (e.g. Raspberry Pi), install kcl via go install or downloading a release archive from GitHub.
  2. Run echo a = 1 | kcl -

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

kcl should compile the program and produce YAML output

a: 1

3. What did you see instead (Required)

Init kcl runtime failed, path:  /root/go
Tip: Have you used a binary version of KCL in your PATH that is not consistent with the KCL Go SDK? You can upgrade or reduce the KCL version or delete the KCL in your PATH
If not, you can run `rm -r /root/go/bin` to fix this issue
panic: unexpected EOF: stderr = qemu-x86_64-static: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory


goroutine 1 [running]:
kcl-lang.io/kcl-go/pkg/kclvm_runtime.initRuntime(0x40001c5668?)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kclvm_runtime/init.go:72 +0x640
kcl-lang.io/kcl-go/pkg/kclvm_runtime.GetRuntime.func1()
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kclvm_runtime/init.go:29 +0x20
sync.(*Once).doSlow(0x40001c5788?, 0x1c554?)
	/opt/hostedtoolcache/go/1.19.13/x64/src/sync/once.go:74 +0x104
sync.(*Once).Do(...)
	/opt/hostedtoolcache/go/1.19.13/x64/src/sync/once.go:65
kcl-lang.io/kcl-go/pkg/kclvm_runtime.GetRuntime()
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kclvm_runtime/init.go:29 +0x3c
kcl-lang.io/kcl-go/pkg/service.NewKclvmServiceClient()
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/service/client_kclvm_service.go:21 +0x1c
kcl-lang.io/kcl-go/pkg/kcl.run({0x40001c5868?, 0x40001c5a60?, 0x1?}, {0x40001c5998?, 0x40003c8360?, 0x0?})
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/api.go:242 +0x6c
kcl-lang.io/kcl-go/pkg/kcl.RunWithOpts(...)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/api.go:181
kcl-lang.io/kpm/pkg/api.RunWithOpt(0x40000ba880)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/api/kpm_run.go:84 +0x29c
kcl-lang.io/cli/pkg/options.(*RunOptions).Run(0x40003c42a0)
	/home/runner/work/cli/cli/pkg/options/run.go:102 +0x210
kcl-lang.io/cli/cmd/kcl/commands.NewRunCmd.func1(0x40003fcc00?, {0x40002b83f0?, 0x1?, 0x1?})
	/home/runner/work/cli/cli/cmd/kcl/commands/run.go:46 +0x70
github.com/spf13/cobra.(*Command).execute(0x40003fcc00, {0x400004c070, 0x1, 0x1})
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:940 +0x5e0
github.com/spf13/cobra.(*Command).ExecuteC(0x40003fcc00)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x368
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:992
kcl-lang.io/cli/cmd/kcl/commands.executeRunCmd({0x400004c070, 0x1, 0x1})
	/home/runner/work/cli/cli/cmd/kcl/commands/plugin.go:17 +0x68
kcl-lang.io/cli/cmd/kcl/commands.bootstrapCmdPlugin(0x40003c2000?, {0x1cbafb8, 0x40000c10c8})
	/home/runner/work/cli/cli/cmd/kcl/commands/plugin.go:38 +0x148
kcl-lang.io/cli/cmd/kcl/commands.New()
	/home/runner/work/cli/cli/cmd/kcl/commands/root.go:126 +0x2c8
main.main()
	/home/runner/work/cli/cli/cmd/kcl/main.go:14 +0x1c

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

kcl version 0.7.2

[root@caf32d738cd0 /]# readelf -h /root/go/bin/kcl | grep Machine
  Machine:                           AArch64
[root@caf32d738cd0 /]# readelf -h /root/go/bin/kclvm_cli | grep Machine
  Machine:                           Advanced Micro Devices X86-64
[root@caf32d738cd0 /]# readelf -h /root/go/bin/libkclvm_cli_cdylib.so | grep Machine
  Machine:                           Advanced Micro Devices X86-64

v0.9.3 is showing the version to v0.9.2

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

$ wget -q https://kcl-lang.io/script/install-cli.sh -O - | /bin/bash
Getting the latest KCL ...
Your system is linux_amd64 

KCL is detected:
Error: failed to compile the kcl package
No input KCL files

Reinstalling KCL into /usr/local/bin/kcl ...

Find the latest KCL version v0.9.3 
Downloading https://github.com/kcl-lang/cli/releases/download/v0.9.3/kcl-v0.9.3-linux-amd64.tar.gz ... 
Scucessful to download https://github.com/kcl-lang/cli/releases/download/v0.9.3/kcl-v0.9.3-linux-amd64.tar.gz 
Copy the kcl temp folder /tmp/kcl-install-4Rh8l4 into the target installation directory /usr/local/bin 
Editing user profile (/home/runner/.bashrc) with the profile install dir /usr/local/bin 
The KCLVM PATH string is 
      export PATH="/usr/local/bin/bin:$PATH"
    Finished kcl installed into /usr/local/bin successfully.
Error: No input KCL files

Please add /usr/local/bin into your PATH
Remeber run the command source ~/.bash_profile or source ~/.bashrc to ensure your PATH is effective
Reopen a terminal and execute the kcl --help command to ensure successful installation

To get started with KCL, please visit https://kcl-lang.io/docs/user_docs/getting-started/kcl-quick-start
$ kcl version
0.9.2-linux-amd64

cc @Peefy

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

3. What did you see instead (Required)

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

unknown flag: --path

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

lan$ kcl mod add --path ../modules/kubeadm/
unknown flag: --path

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

can use arg of path for kcl mod add

...
  # Add a local dependency by flag
  kcl mod add --path /path/to/another_module

i can open a PR for it.
/cc @Peefy

3. What did you see instead (Required)

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

Enhancement: add e2e test for kcl cli and the dev guide for add test cases

Add e2e test

1. Quick Start

We have prepared the e2e-init command to help you initialize an empty e2e test case. The command format is as follows:

make e2e-init TS=<test suite name>

<test suite name> is the name of the test case.

For example, to add a test case named test_kcl_mod_init_1 to test the output of the kcl mod init command in a KCL package directory, you can use the following command:

1.1. Create an empty test case

make e2e-init TS=test_kcl_mod_init

You will get the following result:

Test suite created successfully in ./test/e2e/test_suites/test_kcl_mod_init_1.

By this command, we can see that a new test case test_kcl_mod_init_1 has been created in the test/e2e/test_suites directory of the project.

$ tree test/e2e/test_suites/test_kcl_mod_init_1
test_kcl_mod_init_1
├── input # The input of the test case
├── stderr # The expected output in stderr
├── stdout # The expected output in stdout
└── test_space # The test space is a empty directory and the `input` will run in this directory

1.2. Add the test environment to the test_space directory.

For test_kcl_mod_init_1, we need to create a KCL package directory in the test_space directory. The directory structure is as follows:

$tree test/e2e/test_suites/test_kcl_mod_init_1/test_space
test_space
├── kcl.mod
├── kcl.mod.lock
└── main.k

1.3. Add the command to be tested to the input file.

The content of the input file is as follows:

kcl mod init

1.4. The expected output

stderr is empty, and the content in stdout is as follows:

creating new :<workspace>/test_space/kcl.mod
'<workspace>/test_space/kcl.mod' already exists
creating new :<workspace>/test_space/kcl.mod.lock
'<workspace>/test_space/kcl.mod.lock' already exists
creating new :<workspace>/main.k
'<workspace>/main.k' already exists
package 'test_space' init finished

In the content of the stdout file, <workspace> is a variable that will be replaced with the absolute path of the test_space in the test process.

1.5. Start test

After completing these steps, run make e2e to start the test process.

The test results will be displayed as follows:

Ran 3 of 3 Specs in 0.102 seconds
SUCCESS! -- 3 Passed | 0 Failed | 0 Pending | 0 Skipped

2. Adjust the execution path of the tested command

By default, the command in the input file is executed in the test_space directory. However, in some more complex cases, we may want to execute the command in a subdirectory of test_space. We can use the conf.json file to specify the directory in which the command is executed.

Take test_kcl_mod_add_local as an example to show the process. In this test case, we want to test the process of adding a KCL package in the local directory as a third-party dependency through the kcl mod add command.

2.1. Use e2e-init to create a test case

make e2e-init TS=test_kcl_mod_add_local

2.2. Prepare the test environment

In the test_space directory, prepare two KCL packages. The pkg package will add the dep package as a dependency through the kcl mod add command.

test_space
├── dep
│   ├── kcl.mod
│   ├── kcl.mod.lock
│   └── main.k
└── pkg
    ├── kcl.mod
    ├── kcl.mod.lock
    └── main.k

2.3. Configure the execution directory

Add a conf.json file to the test_kcl_mod_add_local directory to specify the execution directory of the command.

{
    "cwd": “test_space/pkg"
}

2.4. Add the command to be tested to the input file

The content of the input file is as follows:

kcl mod add <workspace>/dep

2.5. Add the expected output

Add the expected output to the stdout file.

 adding dependency 'dep'
 add dependency 'dep:0.0.1' successfully

KCL panics when trying to write files that are being watched

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

I have tilt watching files and reapplying them to kubernetes. When I try to regenerate those files with KCL, I get a race condition sometimes where KCL panics and crashes. Simply rerunning enough times will get past the panic.

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

no errors

3. What did you see instead (Required)

panic: {"code":-32603,"message":"write |1: file already closed"}

goroutine 1 [running]:
kcl-lang.io/kcl-go/pkg/runtime.initRuntime(0x0?)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/runtime/init.go:57 +0x3a4
kcl-lang.io/kcl-go/pkg/runtime.GetRuntime.func1()
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/runtime/init.go:26 +0x20
sync.(*Once).doSlow(0x1?, 0x1049b0438?)
	/opt/hostedtoolcache/go/1.22.5/x64/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
	/opt/hostedtoolcache/go/1.22.5/x64/src/sync/once.go:65
kcl-lang.io/kcl-go/pkg/runtime.GetRuntime()
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/runtime/init.go:26 +0x40
kcl-lang.io/kcl-go/pkg/service.NewKclvmServiceClient(...)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/service/client_kclvm_service.go:22
kcl-lang.io/kcl-go/pkg/kcl.Service(...)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/service.go:12
kcl-lang.io/kcl-go/pkg/kcl.runWithHooks({0x14000af5658, 0x0, 0x0}, {0x10cf60cc0, 0x1, 0x1}, {0x14000af5728, 0x1, 0x1})
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/api.go:436 +0xf8
kcl-lang.io/kcl-go/pkg/kcl.run(...)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/api.go:445
kcl-lang.io/kcl-go/pkg/kcl.RunWithOpts({0x14000af5728?, 0x14000160240?, 0x0?})
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/kcl/api.go:372 +0x50
kcl-lang.io/kpm/pkg/client.(*KpmClient).Run.func1(0x14000160240)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/client/run.go:542 +0x2c4
kcl-lang.io/kpm/pkg/client.(*PkgVisitor).Visit(0x1400012a1e8, 0x0?, 0x140006beed0)
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/client/visitor.go:52 +0x70
kcl-lang.io/kpm/pkg/client.(*KpmClient).Run(0x14000460ea0, {0x14000af5aa0, 0xd, 0x14000128a80?})
	/home/runner/go/pkg/mod/kcl-lang.io/[email protected]/pkg/client/run.go:517 +0x214
kcl-lang.io/cli/pkg/options.(*RunOptions).Run(0x14000002ea0)
	/home/runner/work/cli/cli/pkg/options/run.go:117 +0x368
kcl-lang.io/cli/cmd/kcl/commands.NewRunCmd.func1(0x14000141b00?, {0x14000128a70?, 0x4?, 0x10633bc45?})
	/home/runner/work/cli/cli/cmd/kcl/commands/run.go:58 +0x4c
github.com/spf13/cobra.(*Command).execute(0x140006d5208, {0x1400004e110, 0x1, 0x1})
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:985 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x140006d5208)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041
kcl-lang.io/cli/cmd/kcl/commands.executeRunCmd({0x1400004e110, 0x1, 0x1})
	/home/runner/work/cli/cli/cmd/kcl/commands/plugin.go:17 +0x6c
kcl-lang.io/cli/cmd/kcl/commands.bootstrapCmdPlugin(0x140005d4308?, {0x1071f0550, 0x14000172930})
	/home/runner/work/cli/cli/cmd/kcl/commands/plugin.go:67 +0x414
kcl-lang.io/cli/cmd/kcl/commands.New()
	/home/runner/work/cli/cli/cmd/kcl/commands/root.go:126 +0x36c
main.main()
	/home/runner/work/cli/cli/cmd/kcl/main.go:14 +0x1c
make: *** [generate] Error 2

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

0.9.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.