diff --git a/blog/2024-01-04-biweekly-newsletter/index.md b/blog/2024-01-04-biweekly-newsletter/index.md index aab7f338..d06b12fc 100644 --- a/blog/2024-01-04-biweekly-newsletter/index.md +++ b/blog/2024-01-04-biweekly-newsletter/index.md @@ -24,7 +24,7 @@ Thank you to all contributors for their outstanding work over the past two weeks **Package Management Tool Update** -- Adds support for automatic translation of external package names containing the - symbol to an underscore _ that KCL recognizes, such as set-annotation -> set_annotation +- Adds support for automatic translation of external package names containing the - symbol to an underscore \_ that KCL recognizes, such as set-annotation -> set_annotation - Fixes a null pointer error caused when kcl mod add encounters a mismatch between the Registry package version and the version of the package already present locally **💻 IDE Update** @@ -53,9 +53,9 @@ Crossplane and its XRs allow developers to create higher-level abstractions that Combining KCL with Composition Functions offers several benefits: -+ **Simplification of Complex Configurations**: KCL provides a more concise syntax and structure as a DSL, reducing the complexity of configurations. When combined with Crossplane’s composite resources, you can create more intuitive and easy-to-understand configuration templates with loop and condition features, simplifying the definition and maintenance of resources instead of duplicate YAML and Go code snippets. -+ **Reusability and Modularity**: KCL supports modularity and code reuse through OCI Registry, which means you can create reusable configuration components. Combined with Crossplane, this promotes the modularity of composite resources, increases the reuse of configurations, and reduces errors. -+ **Automation and Policy-Driven**: You can use KCL’s powerful features to write policies and constraints that, combined with Crossplane’s declarative resource management, can be automatically enforced, ensuring compliance within the cloud environment. +- **Simplification of Complex Configurations**: KCL provides a more concise syntax and structure as a DSL, reducing the complexity of configurations. When combined with Crossplane’s composite resources, you can create more intuitive and easy-to-understand configuration templates with loop and condition features, simplifying the definition and maintenance of resources instead of duplicate YAML and Go code snippets. +- **Reusability and Modularity**: KCL supports modularity and code reuse through OCI Registry, which means you can create reusable configuration components. Combined with Crossplane, this promotes the modularity of composite resources, increases the reuse of configurations, and reduces errors. +- **Automation and Policy-Driven**: You can use KCL’s powerful features to write policies and constraints that, combined with Crossplane’s declarative resource management, can be automatically enforced, ensuring compliance within the cloud environment. Additionally, you can refer to [here](https://kcl-lang.io/docs/user_docs/getting-started/intro#how-to-choose) to learn about the differences between KCL and other configuration formats or DSLs. @@ -204,14 +204,14 @@ EOF ##### 5. Verify the Generated Managed Resources -+ VPC +- VPC ```shell kubectl get VPC -o yaml | grep network-id networks.meta.fn.crossplane.io/network-id: network-test-functions ``` -+ InternetGateway +- InternetGateway ```shell kubectl get InternetGateway -o yaml | grep network-id diff --git a/blog/2024-01-18-biweekly-newsletter/index.md b/blog/2024-01-18-biweekly-newsletter/index.md index 038f4063..3f98cfdf 100644 --- a/blog/2024-01-18-biweekly-newsletter/index.md +++ b/blog/2024-01-18-biweekly-newsletter/index.md @@ -26,15 +26,17 @@ Thank you to all contributors for their outstanding work over the past two weeks **🎁 API Update** -- Added APIs for syntax and semantic analysis +- Added APIs for syntax and semantic analysis **🔧 Toolchain Update** - **kcl-go sdk update** + - KCL Doc tool supports output in OpenAPI format. - Added Parsing related APIs. - **Import tool update** + - Optimized the user experience of the import tool to generate KCL, and added support for keywords oneOf and allOf. - **KCL Package Management Tool** @@ -43,6 +45,7 @@ Thank you to all contributors for their outstanding work over the past two weeks **💻 IDE Update** - **Semantic Highlighting** + - KCL IDE optimized semantic highlighting. - **Enhancement for Completion Features** @@ -74,10 +77,11 @@ For more information about the KCL semantic architecture model, please refer to: ### KCL Package Management Tool Supports Adding Git Dependencies via Commit -KCL Package Management Tool supports adding git dependencies via commit. +KCL Package Management Tool supports adding git dependencies via commit. Take https://github.com/KusionStack/catalog as an example, add commit a29e3db as a dependency. You can add it directly through the dependency in the kcl.mod file or the command line. Edit the kcl.mod file as follows: + ``` [dependencies] catalog = { git = "https://github.com/KusionStack/catalog.git", commit = "a29e3db" } diff --git a/blog/2024-02-21-biweekly-newsletter/index.md b/blog/2024-02-21-biweekly-newsletter/index.md index 699f0bd3..020988a8 100644 --- a/blog/2024-02-21-biweekly-newsletter/index.md +++ b/blog/2024-02-21-biweekly-newsletter/index.md @@ -32,7 +32,7 @@ kcl run oci://ghcr.io/kcl-lang/podinfo -D replicas=2 - Improved error messages when object attribute are not found at compile time. - Fixed the recursive check error for mandatory attribute of schema objects. -- Enhanced the robustness of type-checking for schema index signatures. +- Enhanced the robustness of type-checking for schema index signatures. **🔧 Toolchain Updates** @@ -42,11 +42,12 @@ kcl run oci://ghcr.io/kcl-lang/podinfo -D replicas=2 **💻 IDE Updates** - **Semantic Highlighting** + - KCL IDE optimized semantic highlighting. - **Enhancement for Completion Features** - - Fixed the issue with erroneous completions after strings followed by comments. - - Fixed the issue where internal property symbols in Schema could not be navigated. + - Fixed the issue with erroneous completions after strings followed by comments. + - Fixed the issue where internal property symbols in Schema could not be navigated. **🎁 API Updates** @@ -84,9 +85,9 @@ The following are listed in no particular order: Using KCL together with GitOps tools like Flux has the following benefits: -+ The abstraction and programmability capabilities of KCL can help simplify complex Kubernetes deployment configurations, reducing the error rate of manually writing YAML files. It allows for configuration constraint checks at compile-time, making it easier to detect errors. Additionally, it eliminates redundant configuration templates, improves the scalability of configurations across multiple environments and tenants, and enhances configurability and maintainability. -+ KCL allows developers to define the required resources for an application in a declarative manner. Combining KCL with Flux enables better implementation of Infrastructure as Code (IaC), improving deployment efficiency and simplifying application configuration management. -+ With Flux, developers and operations teams can manage the deployment of applications by separately modifying application and configuration code. The Flux Controller automatically synchronizes changes to the configuration, enabling continuous deployment and ensuring consistency. In case of issues, quick rollbacks can be achieved. +- The abstraction and programmability capabilities of KCL can help simplify complex Kubernetes deployment configurations, reducing the error rate of manually writing YAML files. It allows for configuration constraint checks at compile-time, making it easier to detect errors. Additionally, it eliminates redundant configuration templates, improves the scalability of configurations across multiple environments and tenants, and enhances configurability and maintainability. +- KCL allows developers to define the required resources for an application in a declarative manner. Combining KCL with Flux enables better implementation of Infrastructure as Code (IaC), improving deployment efficiency and simplifying application configuration management. +- With Flux, developers and operations teams can manage the deployment of applications by separately modifying application and configuration code. The Flux Controller automatically synchronizes changes to the configuration, enabling continuous deployment and ensuring consistency. In case of issues, quick rollbacks can be achieved. #### Workflow @@ -111,7 +112,7 @@ The overall workflow is as follows: ##### 1. Prepare a Kubernetes Cluster -+ Install [K3d](https://github.com/k3d-io/k3d) and create a cluster: +- Install [K3d](https://github.com/k3d-io/k3d) and create a cluster: ```shell k3d cluster create @@ -119,8 +120,8 @@ k3d cluster create > Note: You can use other methods to create your own Kubernetes cluster, such as kind, minikube, etc. -+ Install kubectl -+ Install kustomize +- Install kubectl +- Install kustomize ##### 2. Install Flux KCL Controller diff --git a/docs/tools/cli/package-management/command-reference/11.update.md b/docs/tools/cli/package-management/command-reference/11.update.md index bac1dee7..7b64ca81 100644 --- a/docs/tools/cli/package-management/command-reference/11.update.md +++ b/docs/tools/cli/package-management/command-reference/11.update.md @@ -14,7 +14,6 @@ kcl mod update [options][module_name] You can also update a package by specifying the path of that package. - ## Options ### --help, -h diff --git a/docs/user_docs/getting-started/intro.md b/docs/user_docs/getting-started/intro.md index 4b0b16d4..ec848db5 100644 --- a/docs/user_docs/getting-started/intro.md +++ b/docs/user_docs/getting-started/intro.md @@ -181,9 +181,9 @@ Pkl is a configuration as code language that has programmable, extensible, and s There some similarities between KCL and Pkl here: -+ Language features: schema, validation, immutability, etc. -+ Multi language binding, KCL provides binding for Python, Go, and Java, etc. and Pkl providers others. -+ Multiple IDE plugin support: NeoVim, VS Code, etc. +- Language features: schema, validation, immutability, etc. +- Multi language binding, KCL provides binding for Python, Go, and Java, etc. and Pkl providers others. +- Multiple IDE plugin support: NeoVim, VS Code, etc. Differently, KCL provides more relevant integration with cloud native tools and model code libraries. diff --git a/docs/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/docs/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 21eacc25..e4341587 100644 --- a/docs/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/docs/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest diff --git a/docs/user_docs/guides/package-management/4-how-to/8-kcl_mod.md b/docs/user_docs/guides/package-management/4-how-to/8-kcl_mod.md index 6d18895f..2e3abcfd 100644 --- a/docs/user_docs/guides/package-management/4-how-to/8-kcl_mod.md +++ b/docs/user_docs/guides/package-management/4-how-to/8-kcl_mod.md @@ -5,6 +5,7 @@ The `kcl.mod` file for each module is called its manifest. It is written in the TOML format. It contains metadata that is needed to compile the module. In the MVP version, the sections we plan to support are as follows: + - Package metadata: - [package](#package) - Defines a package. - [name](#package) — The name of the package. @@ -44,28 +45,29 @@ You can specify a dependency from git repository by git tag. ```toml [dependencies] - = { git = "", tag = "" } + = { git = "", tag = "" } ``` You can specify a dependency from git repository by git commit id. ```toml [dependencies] - = { git = "", commit = "" } -``` + = { git = "", commit = "" } +``` You can specify a dependency from local file path. ```toml # Find the kcl.mod under "./xxx/xxx". [dependencies] - = {path = ""} + = {path = ""} ``` ## entries + You can specify the entry points of the package when compiling. -`entries` is a sub section of `profile` section. +`entries` is a sub section of `profile` section. ```toml [profile] @@ -100,9 +102,10 @@ entries = [ ] ``` -The `mod relative paths` must contains the preffix `${k8s:KCL_MOD}`, `k8s` is the package name, `${k8s:KCL_MOD}` means the package root path of the package `k8s`. Therefore, if the package root path of `k8s` is `/.kcl/kpm/k8s`, the `entries` show above will take `/usr/my_pkg/entry1.k`, `/usr/my_pkg/subdir/entry2.k` and `/.kcl/kpm/k8s/core/api/v1/deployment.k` as the entry point of the kcl compiler. +The `mod relative paths` must contains the preffix `${k8s:KCL_MOD}`, `k8s` is the package name, `${k8s:KCL_MOD}` means the package root path of the package `k8s`. Therefore, if the package root path of `k8s` is `/.kcl/kpm/k8s`, the `entries` show above will take `/usr/my_pkg/entry1.k`, `/usr/my_pkg/subdir/entry2.k` and `/.kcl/kpm/k8s/core/api/v1/deployment.k` as the entry point of the kcl compiler. ### Note + You can use `normal path` to specify the compilation entry point in the current package path, and use `mod relative path` to specify the entry point in a third-party package. Therefore, the file path specified by `normal path` must come from the same package, that is, the `kcl.mod` path found from the normal path must only find one `kcl.mod` file, otherwise the compiler will output an error. @@ -110,6 +113,7 @@ Therefore, the file path specified by `normal path` must come from the same pack For example: In the path `/usr/kcl1`: + ``` /usr/kcl1 |--- kcl.mod @@ -117,6 +121,7 @@ In the path `/usr/kcl1`: ``` In the path `/usr/kcl2`: + ``` /usr/kcl2 |--- kcl.mod @@ -124,6 +129,7 @@ In the path `/usr/kcl2`: ``` If you compile with this `kcl.mod` in the path `/usr/kcl1`: + ``` entries = [ "entry1.k", # The corresponding kcl.mod file is /usr/kcl1/kcl.mod @@ -132,6 +138,7 @@ entries = [ ``` You will get an error: + ``` error[E3M38]: conflict kcl.mod file paths ``` diff --git a/docs/user_docs/guides/package-management/4-how-to/9-kpm_oci.md b/docs/user_docs/guides/package-management/4-how-to/9-kpm_oci.md index 8dd6fde7..3df8d35a 100644 --- a/docs/user_docs/guides/package-management/4-how-to/9-kpm_oci.md +++ b/docs/user_docs/guides/package-management/4-how-to/9-kpm_oci.md @@ -14,9 +14,9 @@ The default content of the configuration file is as follows: ```json { - "DefaultOciRegistry":"ghcr.io", - "DefaultOciRepo":"kcl-lang", - "DefaultOciPlainHttp":true + "DefaultOciRegistry": "ghcr.io", + "DefaultOciRepo": "kcl-lang", + "DefaultOciPlainHttp": true } ``` @@ -95,9 +95,9 @@ You can use `kcl mod push` to upload a KCL package to an OCI Registry. ```shell # Create a new kcl package. -$ kcl mod init +$ kcl mod init # Enter the root directory of the kcl package -$ cd +$ cd # Upload the kcl package to an oci registry $ kcl mod push ``` @@ -114,9 +114,9 @@ You can also specify the url of the OCI registry in the `kcl mod push` command. ```shell # Create a new kcl package. -$ kcl mod init +$ kcl mod init # Enter the root directory of the kcl package -$ cd +$ cd # Upload the kcl package to an oci registry $ kcl mod push ``` diff --git a/docs/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md b/docs/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md index 08d87ae2..cfaf29ae 100644 --- a/docs/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md +++ b/docs/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md @@ -9,9 +9,9 @@ Crossplane and Crossplane Composite Functions are used to decouple XR and Compos Combining KCL with Crossplane composite functions offers several benefits: -+ **Simplification of Complex Configurations**: KCL provides a more concise syntax and structure as a DSL, reducing the complexity of configurations. When combined with Crossplane’s composite resources, you can create more intuitive and easy-to-understand configuration templates with loop and condition features, simplifying the definition and maintenance of resources instead of duplicate YAML and Go code snippets. -+ **Reusability and Modularity**: KCL supports modularity and code reuse through OCI Registry, which means you can create reusable configuration components. Combined with Crossplane, this promotes the modularity of composite resources, increases the reuse of configurations, and reduces errors. -+ **Automation and Policy-Driven**: You can use KCL’s powerful features to write policies and constraints that, combined with Crossplane’s declarative resource management, can be automatically enforced, ensuring compliance within the cloud environment. +- **Simplification of Complex Configurations**: KCL provides a more concise syntax and structure as a DSL, reducing the complexity of configurations. When combined with Crossplane’s composite resources, you can create more intuitive and easy-to-understand configuration templates with loop and condition features, simplifying the definition and maintenance of resources instead of duplicate YAML and Go code snippets. +- **Reusability and Modularity**: KCL supports modularity and code reuse through OCI Registry, which means you can create reusable configuration components. Combined with Crossplane, this promotes the modularity of composite resources, increases the reuse of configurations, and reduces errors. +- **Automation and Policy-Driven**: You can use KCL’s powerful features to write policies and constraints that, combined with Crossplane’s declarative resource management, can be automatically enforced, ensuring compliance within the cloud environment. ## Prerequisites @@ -158,14 +158,14 @@ EOF ### 5. Verify the Generated Managed Resources -+ VPC +- VPC ```shell kubectl get VPC -o yaml | grep network-id networks.meta.fn.crossplane.io/network-id: network-test-functions ``` -+ InternetGateway +- InternetGateway ```shell kubectl get InternetGateway -o yaml | grep network-id @@ -221,12 +221,12 @@ spec: Here's what you can do in the KCL script: -+ Return an error using `assert {condition}, {error_message}`. -+ Read the `ObservedCompositeResource` from `option("params").oxr`. -+ Read the `ObservedComposedResources` from `option("params").ocds`. -+ Read the `DesiredCompositeResource` from `option("params").dxr`. -+ Read the `DesiredComposedResources` from `option("params").dcds`. -+ Read the environment variables. e.g. `option("PATH")` (**Not yet implemented**). +- Return an error using `assert {condition}, {error_message}`. +- Read the `ObservedCompositeResource` from `option("params").oxr`. +- Read the `ObservedComposedResources` from `option("params").ocds`. +- Read the `DesiredCompositeResource` from `option("params").dxr`. +- Read the `DesiredComposedResources` from `option("params").dcds`. +- Read the environment variables. e.g. `option("PATH")` (**Not yet implemented**). ## Library diff --git a/docs/user_docs/support/faq-kcl.md b/docs/user_docs/support/faq-kcl.md index b116ef96..bae712f3 100644 --- a/docs/user_docs/support/faq-kcl.md +++ b/docs/user_docs/support/faq-kcl.md @@ -2355,7 +2355,7 @@ schema Data: ## 52. How to output pretty json string in KCL? -KCL has in-built support for getting formatted JSON strings. Here's how you can do it: +KCL has in-built support for getting formatted JSON strings. Here's how you can do it: Paste the below content in your main.k file. @@ -2369,7 +2369,7 @@ config = { configJson = json.encode(config, ignore_private=True, indent=4) ``` -After running this code, `configJson` variable will contain a prettified JSON string. +After running this code, `configJson` variable will contain a prettified JSON string. ```json config: @@ -2394,7 +2394,7 @@ import crypto schema Person: a: int - + aa = Person {a = 1} bb = Person {a = 2} cc = Person {a = 2} @@ -2403,7 +2403,7 @@ bbhash = crypto.md5(str(bb)) cchash = crypto.md5(str(cc)) ``` -After running above script, You'll get output like this: +After running above script, You'll get output like this: ```bash aa: @@ -2430,7 +2430,7 @@ data = to_set(["aa", "bb", "bb", "cc"]) dataIsUnique = isunique(data) ``` -After running above script, You'll get output like this: +After running above script, You'll get output like this: ```bash data: @@ -2438,4 +2438,4 @@ data: - bb - cc dataIsUnique: true -``` \ No newline at end of file +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-blog/2024-01-04-biweekly-newsletter/index.md b/i18n/zh-CN/docusaurus-plugin-content-blog/2024-01-04-biweekly-newsletter/index.md index 6dad0b97..4ca82610 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-blog/2024-01-04-biweekly-newsletter/index.md +++ b/i18n/zh-CN/docusaurus-plugin-content-blog/2024-01-04-biweekly-newsletter/index.md @@ -50,17 +50,17 @@ Crossplane 及其 Composite Function 功能被用于解耦 XR(CompositeResourc 将 KCL 与 Crossplane Composite Function 功能结合可以获得如下能力 -+ **简化复杂配置**:KCL 作为 DSL 提供了更简洁的语法和结构,可以减少配置的复杂性。当与 Crossplane 的复合资源结合时,可以创建更直观、易于理解的配置模板,比如编写循环和条件语句降低模版,编写 Schema 和 Rule 进行模型抽象和校验,使用 KCL 简化资源的定义和维护,而不是编写重复的 YAML 或者使用 Go 代码编写并部署 Crossplane Function,降低配置和策略的开发及维护成本。此外,因为 Crosssplane Composition 资源本身缺乏强大的模版能力且云 API 丰富且复杂,因此有些 Composition 资源可能需要上千行 YAML 才能完成渲染资源编写,维护成本较高,使用 KCL 可以平替 YAML 提升动态配置能力。 -+ **可重用和模块化**:KCL 通过 OCI Registry 支持模块化和代码复用,这意味着可以创建可重用的配置模型,为 Crossplane Composition 资源带来模块化能力,且可同时在运行时和客户端使用,方便不同的平台团队之间进行协作。 -+ **自动化和策略**:可以使用 KCL 的强大功能来编写策略和约束,与 Crossplane 的声明式资源管理结合使用,并且在集群中自动执行,确保云资源或者 Kubernetes 资源的合规性,而无需引入额外的策略引擎。 +- **简化复杂配置**:KCL 作为 DSL 提供了更简洁的语法和结构,可以减少配置的复杂性。当与 Crossplane 的复合资源结合时,可以创建更直观、易于理解的配置模板,比如编写循环和条件语句降低模版,编写 Schema 和 Rule 进行模型抽象和校验,使用 KCL 简化资源的定义和维护,而不是编写重复的 YAML 或者使用 Go 代码编写并部署 Crossplane Function,降低配置和策略的开发及维护成本。此外,因为 Crosssplane Composition 资源本身缺乏强大的模版能力且云 API 丰富且复杂,因此有些 Composition 资源可能需要上千行 YAML 才能完成渲染资源编写,维护成本较高,使用 KCL 可以平替 YAML 提升动态配置能力。 +- **可重用和模块化**:KCL 通过 OCI Registry 支持模块化和代码复用,这意味着可以创建可重用的配置模型,为 Crossplane Composition 资源带来模块化能力,且可同时在运行时和客户端使用,方便不同的平台团队之间进行协作。 +- **自动化和策略**:可以使用 KCL 的强大功能来编写策略和约束,与 Crossplane 的声明式资源管理结合使用,并且在集群中自动执行,确保云资源或者 Kubernetes 资源的合规性,而无需引入额外的策略引擎。 #### 前置工作 -+ 准备一个 Kubernetes 集群 -+ 安装 Kubectl -+ 安装 [Crossplane 及 Crossplane CLI 1.14+](https://docs.crossplane.io/) -+ 安装 KCL -+ 安装 Go 1.21+ (可选,需要本地调试函数时才用到) +- 准备一个 Kubernetes 集群 +- 安装 Kubectl +- 安装 [Crossplane 及 Crossplane CLI 1.14+](https://docs.crossplane.io/) +- 安装 KCL +- 安装 Go 1.21+ (可选,需要本地调试函数时才用到) #### 快速开始 @@ -200,14 +200,14 @@ EOF ##### 5. 检查生成的托管资源 -+ VPC +- VPC ```shell kubectl get VPC -o yaml | grep network-id networks.meta.fn.crossplane.io/network-id: network-test-functions ``` -+ InternetGateway +- InternetGateway ```shell kubectl get InternetGateway -o yaml | grep network-id diff --git a/i18n/zh-CN/docusaurus-plugin-content-blog/2024-01-18-biweekly-newsletter/index.md b/i18n/zh-CN/docusaurus-plugin-content-blog/2024-01-18-biweekly-newsletter/index.md index 5f36f740..6a53e26e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-blog/2024-01-18-biweekly-newsletter/index.md +++ b/i18n/zh-CN/docusaurus-plugin-content-blog/2024-01-18-biweekly-newsletter/index.md @@ -30,10 +30,12 @@ tags: [KCL, Biweekly-Newsletter] **🔧 工具链更新** - **kcl-go sdk 更新** + - KCL Doc 工具支持输出为 OpenAPI 格式。 - 增加 Parse 过程相关 API。 - **Import 工具更新** + - 优化了 import 工具生成 KCL 配置用户体验,增加了对关键字 oneOf, allOf 的支持。 - **KCL 包管理工具** @@ -69,17 +71,19 @@ KCL IDE 高亮之前仅支持 KCL 语法高亮,如下图所示: 更多关于 KCL 语义架构模型的内容,参考: [KCL 高效语义模型技术揭秘:实现快速编译与增强 IDE 支持](https://kcl-lang.io/zh-CN/blog/2023-12-09-kcl-new-semantic-model) -### KCL 包管理支持通过 commit 添加 git 依赖 +### KCL 包管理支持通过 commit 添加 git 依赖 -KCL 包管理工具增加了通过 commit 来添加 git 三方库依赖的功能。以 https://github.com/KusionStack/catalog 为例,添加 commit 为 a29e3db 的版本作为依赖。可以通过编辑 kcl.mod 文件中的依赖或者命令行直接添加。 +KCL 包管理工具增加了通过 commit 来添加 git 三方库依赖的功能。以 https://github.com/KusionStack/catalog 为例,添加 commit 为 a29e3db 的版本作为依赖。可以通过编辑 kcl.mod 文件中的依赖或者命令行直接添加。 编辑 kcl.mod 文件内容如下: + ``` [dependencies] catalog = { git = "https://github.com/KusionStack/catalog.git", commit = "a29e3db" } ``` 或者通过命令行添加: + ``` kcl mod add -git https://github.com/KusionStack/catalog.git -commit a29e3db ``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-blog/2024-02-21-biweekly-newsletter/index.md b/i18n/zh-CN/docusaurus-plugin-content-blog/2024-02-21-biweekly-newsletter/index.md index f1faee24..2c30dd59 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-blog/2024-02-21-biweekly-newsletter/index.md +++ b/i18n/zh-CN/docusaurus-plugin-content-blog/2024-02-21-biweekly-newsletter/index.md @@ -36,6 +36,7 @@ kcl run oci://ghcr.io/kcl-lang/podinfo -D replicas=2 **🔧 工具链更新** - **文档工具更新** + - 支持在生成的 Markdown 格式文档对多行字符使用 HTML 转义 - **CodeQL KCL 工具** @@ -120,8 +121,8 @@ k3d cluster create > 注意:你可以在此方案中使用其他方式创建您自己的 Kubernetes 集群,如 kind, minikube 等。 -+ 安装 Kubectl -+ 安装 Kustomize +- 安装 Kubectl +- 安装 Kustomize ##### 2. 安装 Flux KCL Controller @@ -189,7 +190,7 @@ spec: ##### 4. 提交业务代码 -+ 获取代码 +- 获取代码 ```shell git clone https://github.com/kcl-lang/flask-demo.git/ diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/getting-started/intro.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/getting-started/intro.md index 7ac927a7..f6d88908 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/getting-started/intro.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/getting-started/intro.md @@ -181,9 +181,9 @@ Pkl 是一门配置即代码语言,它具有可编程、可扩展和安全的 KCL 和 Pkl 之间有一些相似之处: -+ 语言特征:Schema 定义、验证、不变性等。 -+ 多语言绑定,KCL 为 Python、Go 和 Java 语言等提供了绑定,Pkl 也提供了诸如 Java, Swift 和 Kotlin 等语言绑定。 -+ 支持多种 IDE 插件:NeoVim、VS Code等。 +- 语言特征:Schema 定义、验证、不变性等。 +- 多语言绑定,KCL 为 Python、Go 和 Java 语言等提供了绑定,Pkl 也提供了诸如 Java, Swift 和 Kotlin 等语言绑定。 +- 支持多种 IDE 插件:NeoVim、VS Code等。 不同的是,KCL 提供了更多与云原生工具和模型代码库更多的集成。 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/8-kcl_mod.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/8-kcl_mod.md index cc6dc14a..a067fb74 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/8-kcl_mod.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/8-kcl_mod.md @@ -19,21 +19,26 @@ - [entries](#entries) - 编译包的入口点。 ## 2. package + `kcl.mod` 中的第一个部分是 `[package]`。主要包含 `name`, `version`, `edition` 和 `description` 字段。 ### 2.1. name + `name` 是包的名称,它是一个字符串, 这是一个必要的字段, 注意,包的名称中不可以包含`"."`。 例如: 一个包名为 my_pkg 的 kcl 程序包。 + ``` [package] name = "my_pkg" ``` ### 2.2. version + `version` 是包的版本,它是一个字符串, 这是一个必要的字段。注意,目前 KCL 程序包的版本号仅支持语义化版本号。 例如: `my_pkg` 程序包的版本号为 `0.1.0`。 + ``` [package] name = "my_pkg" @@ -41,9 +46,11 @@ version = "0.1.0" ``` ### 2.3. edition + `edition` 是 KCL 编译器版本,它是一个字符串, 这是一个必要的字段。注意,目前 KCL 编译器版本号仅支持语义化版本号。 例如: `my_pkg` 程序包的版本号为 `0.1.0`, 并且与 0.5.1 的 KCL 编译器兼容。 + ``` [package] name = "my_pkg" @@ -52,9 +59,11 @@ edition = "0.5.0" ``` ### 2.4. description + `description` 是包的描述,它是一个字符串, 这是一个可选的字段。 例如: `my_pkg` 程序包的描述为 `This is my package.`。 + ``` [package] name = "my_pkg" @@ -91,17 +100,21 @@ k8s = "1.27" ### 3.2. git dependency 根据 git 仓库中的 tag 指定对应的依赖。 + ``` [dependencies] - = { git = "", tag = "" } + = { git = "", tag = "" } ``` + 这将会从 Git 存储库``中拉取名称为 `` 的包,`tag` 为 ``。 根据 git 仓库中的 commit id 指定对应的依赖。 + ``` [dependencies] - = { git = "", commit = "" } + = { git = "", commit = "" } ``` + 这将会从 Git 存储库``中拉取名称为 `` 的包,`commit id` 为 ``。 ## 4. entries @@ -117,7 +130,7 @@ entries = [ ] ``` -entries 中可以定义绝对路径和相对路径,如果定义的是相对路径,那么就会以当前包的 +entries 中可以定义绝对路径和相对路径,如果定义的是相对路径,那么就会以当前包的 `entries` 是 kcl 包根路径的相对路径,`kcl.mod` 文件路径是包的根路径。支持两种文件路径格式,即 `normal paths` 和 `mod relative paths`。 @@ -125,6 +138,7 @@ entries 中可以定义绝对路径和相对路径,如果定义的是相对路 - mod relative path:相对于 kcl.mod 中 [dependencies](#dependencies) 部分中的三方包的根路径。 例如: + 1. 如果 `kcl.mod` 位于 `/usr/my_pkg/kcl.mod`,则 `kpm run` 将把 `/usr/my_pkg/entry1.k` 和 `/usr/my_pkg/subdir/entry2.k` 作为 `kcl` 编译器的入口点。 ``` @@ -147,6 +161,7 @@ entries = [ `mod relative paths` 必须包含前缀 `${k8s:KCL_MOD}`,其中 `k8s` 是包名,`${k8s:KCL_MOD}` 表示包 k8s 的包根路径。因此,如果 `k8s` 的包根路径是 `/.kcl/kpm/k8s`,则上面的 `entries` 将把 `/usr/my_pkg/entry1.k`、`/usr/my_pkg/subdir/entry2.k` 和 `/.kcl/kpm/k8s/core/api/v1/deployment.k` 作为 `kcl` 编译器的入口点。 ### 注意 + 你可以使用 `normal path` 指定当前包路径中的编译入口点,使用 `mod relative path` 指定三方包中的入口点。 因此,使用 `normal path` 制定的文件路径必须来自于同一个包,即从 `normal path` 开始寻找的 `kcl.mod` 路径必须只能找到一个 `kcl.mod` 文件,不然编译器将输出错误。 @@ -154,6 +169,7 @@ entries = [ 例如: 在路径 `/usr/kcl1` 下 + ``` /usr/kcl1 |--- kcl.mod @@ -161,6 +177,7 @@ entries = [ ``` 在路径 `/usr/kcl2` 下 + ``` /usr/kcl2 |--- kcl.mod @@ -168,6 +185,7 @@ entries = [ ``` 如果你在路径`/usr/kcl1`下使用这样的 kcl.mod 编译: + ``` entries = [ "entry1.k", # 对应的 kcl.mod 文件是 /usr/kcl1/kcl.mod @@ -176,6 +194,7 @@ entries = [ ``` 将会得到错误: + ``` error[E3M38]: conflict kcl.mod file paths -``` \ No newline at end of file +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/9-oci_reg_supports.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/9-oci_reg_supports.md index 0452d656..43afeb26 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/9-oci_reg_supports.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/package-management/4-how-to/9-oci_reg_supports.md @@ -14,9 +14,9 @@ KCL 包管理工具默认使用 ghcr.io 保存 KCL 包。 ```json { - "DefaultOciRegistry":"ghcr.io", - "DefaultOciRepo":"kcl-lang", - "DefaultOciPlainHttp":true + "DefaultOciRegistry": "ghcr.io", + "DefaultOciRepo": "kcl-lang", + "DefaultOciPlainHttp": true } ``` @@ -95,9 +95,9 @@ kpm logout localhost:5001 ```shell # 创建一个新的 kcl 包。 -$ kcl mod init +$ kcl mod init # 进入 kcl 包的根目录 -$ cd +$ cd # 将 kcl 包上传到一个 oci registry $ kcl mod push ``` @@ -114,9 +114,9 @@ $ kcl mod push ```shell # 创建一个新的 kcl 包。 -$ kcl mod init +$ kcl mod init # 进入 kcl 包的根目录 -$ cd +$ cd # 将 kcl 包上传到一个 oci registry $ kcl mod push ``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.1/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.1/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.1/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.1/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.2/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.2/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.2/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.2/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.3/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.3/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.3/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.3/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.4/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.4/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.4/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.4/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.5/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.5/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.5/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.5/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.6/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.6/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.6/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.5.6/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.6.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.6.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.6.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.6.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/getting-started/install.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/getting-started/install.md index fffe76b2..c542b556 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/getting-started/install.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/getting-started/install.md @@ -34,6 +34,12 @@ $env:PATH += ";{install-location};" curl -fsSL https://kcl-lang.io/script/install-cli.sh | /bin/bash ``` +卸载 + +```bash +curl -fsSL https://kcl-lang.io/script/uninstall-cli.sh | /bin/bash +``` + #### Linux 将 KCL linux 最新版本安装到 /usr/local/bin @@ -42,12 +48,24 @@ curl -fsSL https://kcl-lang.io/script/install-cli.sh | /bin/bash wget -q https://kcl-lang.io/script/install-cli.sh -O - | /bin/bash ``` +卸载 + +```bash +wget -q https://kcl-lang.io/script/uninstall-cli.sh -O - | /bin/bash +``` + #### Windows 将 KCL windows 最新版本安装到 $Env:SystemDrive\kclvm\bin,并将该目录添加到用户 PATH 环境变量中。 ```bash -powershell -Command "iwr -useb https://kcl-lang.io/script/install-cli.ps1 | iex" +wget -q https://kcl-lang.io/script/uninstall-cli.sh -O - | /bin/bash +``` + +卸载 + +```shell +powershell -Command "iwr -useb https://kcl-lang.io/script/uninstall-cli.ps1 | iex" ``` #### Homebrew (MacOS) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/getting-started/intro.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/getting-started/intro.md index b548ff30..f6d88908 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/getting-started/intro.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/getting-started/intro.md @@ -175,6 +175,18 @@ Starlark 主要用作 Bazel 的配置语言并且是 Python 的一种方言。 KCL 一定程度上也可以看作 Python 的变种,但是它极大地增强了静态类型和配置扩展性相关的设计,并且是一个编译型语言,这与 Starlark 有着本质的不同。 +### vs. Pkl + +Pkl 是一门配置即代码语言,它具有可编程、可扩展和安全的特性。 + +KCL 和 Pkl 之间有一些相似之处: + +- 语言特征:Schema 定义、验证、不变性等。 +- 多语言绑定,KCL 为 Python、Go 和 Java 语言等提供了绑定,Pkl 也提供了诸如 Java, Swift 和 Kotlin 等语言绑定。 +- 支持多种 IDE 插件:NeoVim、VS Code等。 + +不同的是,KCL 提供了更多与云原生工具和模型代码库更多的集成。 + ### vs. Kustomize Kustomize 的核心功能是其文件级覆盖功能。但是它存在多个覆盖链的问题,因为找到特定属性值的语句不能保证它是最终值,因为其他地方出现的另一个特定值可以覆盖它。对于复杂的场景,Kustomize 文件的继承链的检索通常不如 KCL 代码的继承链检索方便,需要仔细考虑指定的配置文件覆盖顺序。此外,Kustomize 无法解决 YAML 配置编写、约束验证、模型抽象和开发等问题,更适合于简单的配置场景。 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md index ea5585fb..2f18b66f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,12 +62,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - - name: Install KCL CLI + - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest - name: Login and Push diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/8-kcl_mod.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/8-kcl_mod.md index cc6dc14a..a067fb74 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/8-kcl_mod.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/8-kcl_mod.md @@ -19,21 +19,26 @@ - [entries](#entries) - 编译包的入口点。 ## 2. package + `kcl.mod` 中的第一个部分是 `[package]`。主要包含 `name`, `version`, `edition` 和 `description` 字段。 ### 2.1. name + `name` 是包的名称,它是一个字符串, 这是一个必要的字段, 注意,包的名称中不可以包含`"."`。 例如: 一个包名为 my_pkg 的 kcl 程序包。 + ``` [package] name = "my_pkg" ``` ### 2.2. version + `version` 是包的版本,它是一个字符串, 这是一个必要的字段。注意,目前 KCL 程序包的版本号仅支持语义化版本号。 例如: `my_pkg` 程序包的版本号为 `0.1.0`。 + ``` [package] name = "my_pkg" @@ -41,9 +46,11 @@ version = "0.1.0" ``` ### 2.3. edition + `edition` 是 KCL 编译器版本,它是一个字符串, 这是一个必要的字段。注意,目前 KCL 编译器版本号仅支持语义化版本号。 例如: `my_pkg` 程序包的版本号为 `0.1.0`, 并且与 0.5.1 的 KCL 编译器兼容。 + ``` [package] name = "my_pkg" @@ -52,9 +59,11 @@ edition = "0.5.0" ``` ### 2.4. description + `description` 是包的描述,它是一个字符串, 这是一个可选的字段。 例如: `my_pkg` 程序包的描述为 `This is my package.`。 + ``` [package] name = "my_pkg" @@ -91,17 +100,21 @@ k8s = "1.27" ### 3.2. git dependency 根据 git 仓库中的 tag 指定对应的依赖。 + ``` [dependencies] - = { git = "", tag = "" } + = { git = "", tag = "" } ``` + 这将会从 Git 存储库``中拉取名称为 `` 的包,`tag` 为 ``。 根据 git 仓库中的 commit id 指定对应的依赖。 + ``` [dependencies] - = { git = "", commit = "" } + = { git = "", commit = "" } ``` + 这将会从 Git 存储库``中拉取名称为 `` 的包,`commit id` 为 ``。 ## 4. entries @@ -117,7 +130,7 @@ entries = [ ] ``` -entries 中可以定义绝对路径和相对路径,如果定义的是相对路径,那么就会以当前包的 +entries 中可以定义绝对路径和相对路径,如果定义的是相对路径,那么就会以当前包的 `entries` 是 kcl 包根路径的相对路径,`kcl.mod` 文件路径是包的根路径。支持两种文件路径格式,即 `normal paths` 和 `mod relative paths`。 @@ -125,6 +138,7 @@ entries 中可以定义绝对路径和相对路径,如果定义的是相对路 - mod relative path:相对于 kcl.mod 中 [dependencies](#dependencies) 部分中的三方包的根路径。 例如: + 1. 如果 `kcl.mod` 位于 `/usr/my_pkg/kcl.mod`,则 `kpm run` 将把 `/usr/my_pkg/entry1.k` 和 `/usr/my_pkg/subdir/entry2.k` 作为 `kcl` 编译器的入口点。 ``` @@ -147,6 +161,7 @@ entries = [ `mod relative paths` 必须包含前缀 `${k8s:KCL_MOD}`,其中 `k8s` 是包名,`${k8s:KCL_MOD}` 表示包 k8s 的包根路径。因此,如果 `k8s` 的包根路径是 `/.kcl/kpm/k8s`,则上面的 `entries` 将把 `/usr/my_pkg/entry1.k`、`/usr/my_pkg/subdir/entry2.k` 和 `/.kcl/kpm/k8s/core/api/v1/deployment.k` 作为 `kcl` 编译器的入口点。 ### 注意 + 你可以使用 `normal path` 指定当前包路径中的编译入口点,使用 `mod relative path` 指定三方包中的入口点。 因此,使用 `normal path` 制定的文件路径必须来自于同一个包,即从 `normal path` 开始寻找的 `kcl.mod` 路径必须只能找到一个 `kcl.mod` 文件,不然编译器将输出错误。 @@ -154,6 +169,7 @@ entries = [ 例如: 在路径 `/usr/kcl1` 下 + ``` /usr/kcl1 |--- kcl.mod @@ -161,6 +177,7 @@ entries = [ ``` 在路径 `/usr/kcl2` 下 + ``` /usr/kcl2 |--- kcl.mod @@ -168,6 +185,7 @@ entries = [ ``` 如果你在路径`/usr/kcl1`下使用这样的 kcl.mod 编译: + ``` entries = [ "entry1.k", # 对应的 kcl.mod 文件是 /usr/kcl1/kcl.mod @@ -176,6 +194,7 @@ entries = [ ``` 将会得到错误: + ``` error[E3M38]: conflict kcl.mod file paths -``` \ No newline at end of file +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/9-oci_reg_supports.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/9-oci_reg_supports.md index 0452d656..43afeb26 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/9-oci_reg_supports.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-0.7.0/user_docs/guides/package-management/4-how-to/9-oci_reg_supports.md @@ -14,9 +14,9 @@ KCL 包管理工具默认使用 ghcr.io 保存 KCL 包。 ```json { - "DefaultOciRegistry":"ghcr.io", - "DefaultOciRepo":"kcl-lang", - "DefaultOciPlainHttp":true + "DefaultOciRegistry": "ghcr.io", + "DefaultOciRepo": "kcl-lang", + "DefaultOciPlainHttp": true } ``` @@ -95,9 +95,9 @@ kpm logout localhost:5001 ```shell # 创建一个新的 kcl 包。 -$ kcl mod init +$ kcl mod init # 进入 kcl 包的根目录 -$ cd +$ cd # 将 kcl 包上传到一个 oci registry $ kcl mod push ``` @@ -114,9 +114,9 @@ $ kcl mod push ```shell # 创建一个新的 kcl 包。 -$ kcl mod init +$ kcl mod init # 进入 kcl 包的根目录 -$ cd +$ cd # 将 kcl 包上传到一个 oci registry $ kcl mod push ``` diff --git a/versioned_docs/version-0.5.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/versioned_docs/version-0.5.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 8a950f0c..de88dbcf 100644 --- a/versioned_docs/version-0.5.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/versioned_docs/version-0.5.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install kpm run: go install kcl-lang.io/kpm@latest diff --git a/versioned_docs/version-0.5.1/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/versioned_docs/version-0.5.1/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 8a950f0c..de88dbcf 100644 --- a/versioned_docs/version-0.5.1/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/versioned_docs/version-0.5.1/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install kpm run: go install kcl-lang.io/kpm@latest diff --git a/versioned_docs/version-0.5.2/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/versioned_docs/version-0.5.2/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 8a950f0c..de88dbcf 100644 --- a/versioned_docs/version-0.5.2/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/versioned_docs/version-0.5.2/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install kpm run: go install kcl-lang.io/kpm@latest diff --git a/versioned_docs/version-0.5.3/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/versioned_docs/version-0.5.3/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 8a950f0c..de88dbcf 100644 --- a/versioned_docs/version-0.5.3/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/versioned_docs/version-0.5.3/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install kpm run: go install kcl-lang.io/kpm@latest diff --git a/versioned_docs/version-0.5.4/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/versioned_docs/version-0.5.4/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 8a950f0c..de88dbcf 100644 --- a/versioned_docs/version-0.5.4/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/versioned_docs/version-0.5.4/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install kpm run: go install kcl-lang.io/kpm@latest diff --git a/versioned_docs/version-0.5.5/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/versioned_docs/version-0.5.5/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 8a950f0c..de88dbcf 100644 --- a/versioned_docs/version-0.5.5/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/versioned_docs/version-0.5.5/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install kpm run: go install kcl-lang.io/kpm@latest diff --git a/versioned_docs/version-0.5.6/user_docs/guides/package-management/how-to/6-push_github_action.md b/versioned_docs/version-0.5.6/user_docs/guides/package-management/how-to/6-push_github_action.md index 21eacc25..e4341587 100644 --- a/versioned_docs/version-0.5.6/user_docs/guides/package-management/how-to/6-push_github_action.md +++ b/versioned_docs/version-0.5.6/user_docs/guides/package-management/how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest diff --git a/versioned_docs/version-0.6.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/versioned_docs/version-0.6.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 21eacc25..e4341587 100644 --- a/versioned_docs/version-0.6.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/versioned_docs/version-0.6.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest diff --git a/versioned_docs/version-0.7.0/tools/cli/package-management/command-reference/11.update.md b/versioned_docs/version-0.7.0/tools/cli/package-management/command-reference/11.update.md index bac1dee7..7b64ca81 100644 --- a/versioned_docs/version-0.7.0/tools/cli/package-management/command-reference/11.update.md +++ b/versioned_docs/version-0.7.0/tools/cli/package-management/command-reference/11.update.md @@ -14,7 +14,6 @@ kcl mod update [options][module_name] You can also update a package by specifying the path of that package. - ## Options ### --help, -h diff --git a/versioned_docs/version-0.7.0/user_docs/getting-started/install.md b/versioned_docs/version-0.7.0/user_docs/getting-started/install.md index bf45c757..2cd180fc 100644 --- a/versioned_docs/version-0.7.0/user_docs/getting-started/install.md +++ b/versioned_docs/version-0.7.0/user_docs/getting-started/install.md @@ -34,6 +34,12 @@ Install or upgrade the latest darwin KCL to /usr/local/bin curl -fsSL https://kcl-lang.io/script/install-cli.sh | /bin/bash ``` +Uninstall + +```bash +curl -fsSL https://kcl-lang.io/script/uninstall-cli.sh | /bin/bash +``` + #### Linux Install or upgrade the latest linux KCL to /usr/local/bin @@ -42,6 +48,12 @@ Install or upgrade the latest linux KCL to /usr/local/bin wget -q https://kcl-lang.io/script/install-cli.sh -O - | /bin/bash ``` +Uninstall + +```bash +wget -q https://kcl-lang.io/script/uninstall-cli.sh -O - | /bin/bash +``` + #### Windows Install or upgrade the latest windows KCL to $Env:SystemDrive\kclvm\bin and add this directory to User PATH environment variable. @@ -50,6 +62,12 @@ Install or upgrade the latest windows KCL to $Env:SystemDrive\kclvm\bin and add powershell -Command "iwr -useb https://kcl-lang.io/script/install-cli.ps1 | iex" ``` +Uninstall + +```shell +powershell -Command "iwr -useb https://kcl-lang.io/script/uninstall-cli.ps1 | iex" +``` + ### Homebrew (MacOS) - Install diff --git a/versioned_docs/version-0.7.0/user_docs/getting-started/intro.md b/versioned_docs/version-0.7.0/user_docs/getting-started/intro.md index 54f0e1a0..ec848db5 100644 --- a/versioned_docs/version-0.7.0/user_docs/getting-started/intro.md +++ b/versioned_docs/version-0.7.0/user_docs/getting-started/intro.md @@ -175,6 +175,18 @@ Starlark is the language of Bazel, which is a dialect of Python. It does not hav KCL can also be regarded as a variant of Python to some extent, but it greatly enhances the design related to static typing and configuration extensibility, and is a compiled language, which is essentially different from Starlark. +### vs. Pkl + +Pkl is a configuration as code language that has programmable, extensible, and secure features. + +There some similarities between KCL and Pkl here: + +- Language features: schema, validation, immutability, etc. +- Multi language binding, KCL provides binding for Python, Go, and Java, etc. and Pkl providers others. +- Multiple IDE plugin support: NeoVim, VS Code, etc. + +Differently, KCL provides more relevant integration with cloud native tools and model code libraries. + ### vs. Kustomize The key feature of Kustomize is its ability to overlay files at a granular level. However, it faces challenges with multiple overlay chains as a specific attribute value may not be the final value, as it can be overridden by another value elsewhere. Retrieving the inheritance chain of Kustomize files can be less convenient than retrieving the inheritance chain of KCL code, particularly for complex scenarios where careful consideration of the specified configuration file overwrite order is necessary. Additionally, Kustomize does not address issues related to YAML configuration writing, constraint verification, model abstraction, and development, making it more suited for simpler configuration scenarios. diff --git a/versioned_docs/version-0.7.0/user_docs/guides/configuration.md b/versioned_docs/version-0.7.0/user_docs/guides/configuration.md index e6060815..10db9c34 100644 --- a/versioned_docs/version-0.7.0/user_docs/guides/configuration.md +++ b/versioned_docs/version-0.7.0/user_docs/guides/configuration.md @@ -88,7 +88,7 @@ nginx: Besides, we can dynamically receive external parameters through the KCL builtin function `option`. For example, for the following KCL file (db.k), we can use the KCL command line `-D` flag to receive an external dynamic parameter. ```python -env: str = option("env") or "dev" # The attribute `env` has a default value "den" +env: str = option("env") or "dev" # The attribute `env` has a default value "dev" database: str = option("database") hosts = { dev = "postgres.dev" diff --git a/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md b/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md index 21eacc25..e4341587 100644 --- a/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md +++ b/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/6-push_github_action.md @@ -62,10 +62,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Set up Go 1.19 + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: 1.19 + go-version: 1.21 - name: Install KCL CLI run: go install kcl-lang.io/cli/cmd/kcl@latest diff --git a/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/8-kcl_mod.md b/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/8-kcl_mod.md index 6d18895f..2e3abcfd 100644 --- a/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/8-kcl_mod.md +++ b/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/8-kcl_mod.md @@ -5,6 +5,7 @@ The `kcl.mod` file for each module is called its manifest. It is written in the TOML format. It contains metadata that is needed to compile the module. In the MVP version, the sections we plan to support are as follows: + - Package metadata: - [package](#package) - Defines a package. - [name](#package) — The name of the package. @@ -44,28 +45,29 @@ You can specify a dependency from git repository by git tag. ```toml [dependencies] - = { git = "", tag = "" } + = { git = "", tag = "" } ``` You can specify a dependency from git repository by git commit id. ```toml [dependencies] - = { git = "", commit = "" } -``` + = { git = "", commit = "" } +``` You can specify a dependency from local file path. ```toml # Find the kcl.mod under "./xxx/xxx". [dependencies] - = {path = ""} + = {path = ""} ``` ## entries + You can specify the entry points of the package when compiling. -`entries` is a sub section of `profile` section. +`entries` is a sub section of `profile` section. ```toml [profile] @@ -100,9 +102,10 @@ entries = [ ] ``` -The `mod relative paths` must contains the preffix `${k8s:KCL_MOD}`, `k8s` is the package name, `${k8s:KCL_MOD}` means the package root path of the package `k8s`. Therefore, if the package root path of `k8s` is `/.kcl/kpm/k8s`, the `entries` show above will take `/usr/my_pkg/entry1.k`, `/usr/my_pkg/subdir/entry2.k` and `/.kcl/kpm/k8s/core/api/v1/deployment.k` as the entry point of the kcl compiler. +The `mod relative paths` must contains the preffix `${k8s:KCL_MOD}`, `k8s` is the package name, `${k8s:KCL_MOD}` means the package root path of the package `k8s`. Therefore, if the package root path of `k8s` is `/.kcl/kpm/k8s`, the `entries` show above will take `/usr/my_pkg/entry1.k`, `/usr/my_pkg/subdir/entry2.k` and `/.kcl/kpm/k8s/core/api/v1/deployment.k` as the entry point of the kcl compiler. ### Note + You can use `normal path` to specify the compilation entry point in the current package path, and use `mod relative path` to specify the entry point in a third-party package. Therefore, the file path specified by `normal path` must come from the same package, that is, the `kcl.mod` path found from the normal path must only find one `kcl.mod` file, otherwise the compiler will output an error. @@ -110,6 +113,7 @@ Therefore, the file path specified by `normal path` must come from the same pack For example: In the path `/usr/kcl1`: + ``` /usr/kcl1 |--- kcl.mod @@ -117,6 +121,7 @@ In the path `/usr/kcl1`: ``` In the path `/usr/kcl2`: + ``` /usr/kcl2 |--- kcl.mod @@ -124,6 +129,7 @@ In the path `/usr/kcl2`: ``` If you compile with this `kcl.mod` in the path `/usr/kcl1`: + ``` entries = [ "entry1.k", # The corresponding kcl.mod file is /usr/kcl1/kcl.mod @@ -132,6 +138,7 @@ entries = [ ``` You will get an error: + ``` error[E3M38]: conflict kcl.mod file paths ``` diff --git a/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/9-kpm_oci.md b/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/9-kpm_oci.md index 8dd6fde7..3df8d35a 100644 --- a/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/9-kpm_oci.md +++ b/versioned_docs/version-0.7.0/user_docs/guides/package-management/4-how-to/9-kpm_oci.md @@ -14,9 +14,9 @@ The default content of the configuration file is as follows: ```json { - "DefaultOciRegistry":"ghcr.io", - "DefaultOciRepo":"kcl-lang", - "DefaultOciPlainHttp":true + "DefaultOciRegistry": "ghcr.io", + "DefaultOciRepo": "kcl-lang", + "DefaultOciPlainHttp": true } ``` @@ -95,9 +95,9 @@ You can use `kcl mod push` to upload a KCL package to an OCI Registry. ```shell # Create a new kcl package. -$ kcl mod init +$ kcl mod init # Enter the root directory of the kcl package -$ cd +$ cd # Upload the kcl package to an oci registry $ kcl mod push ``` @@ -114,9 +114,9 @@ You can also specify the url of the OCI registry in the `kcl mod push` command. ```shell # Create a new kcl package. -$ kcl mod init +$ kcl mod init # Enter the root directory of the kcl package -$ cd +$ cd # Upload the kcl package to an oci registry $ kcl mod push ``` diff --git a/versioned_docs/version-0.7.0/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md b/versioned_docs/version-0.7.0/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md index 08d87ae2..cfaf29ae 100644 --- a/versioned_docs/version-0.7.0/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md +++ b/versioned_docs/version-0.7.0/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md @@ -9,9 +9,9 @@ Crossplane and Crossplane Composite Functions are used to decouple XR and Compos Combining KCL with Crossplane composite functions offers several benefits: -+ **Simplification of Complex Configurations**: KCL provides a more concise syntax and structure as a DSL, reducing the complexity of configurations. When combined with Crossplane’s composite resources, you can create more intuitive and easy-to-understand configuration templates with loop and condition features, simplifying the definition and maintenance of resources instead of duplicate YAML and Go code snippets. -+ **Reusability and Modularity**: KCL supports modularity and code reuse through OCI Registry, which means you can create reusable configuration components. Combined with Crossplane, this promotes the modularity of composite resources, increases the reuse of configurations, and reduces errors. -+ **Automation and Policy-Driven**: You can use KCL’s powerful features to write policies and constraints that, combined with Crossplane’s declarative resource management, can be automatically enforced, ensuring compliance within the cloud environment. +- **Simplification of Complex Configurations**: KCL provides a more concise syntax and structure as a DSL, reducing the complexity of configurations. When combined with Crossplane’s composite resources, you can create more intuitive and easy-to-understand configuration templates with loop and condition features, simplifying the definition and maintenance of resources instead of duplicate YAML and Go code snippets. +- **Reusability and Modularity**: KCL supports modularity and code reuse through OCI Registry, which means you can create reusable configuration components. Combined with Crossplane, this promotes the modularity of composite resources, increases the reuse of configurations, and reduces errors. +- **Automation and Policy-Driven**: You can use KCL’s powerful features to write policies and constraints that, combined with Crossplane’s declarative resource management, can be automatically enforced, ensuring compliance within the cloud environment. ## Prerequisites @@ -158,14 +158,14 @@ EOF ### 5. Verify the Generated Managed Resources -+ VPC +- VPC ```shell kubectl get VPC -o yaml | grep network-id networks.meta.fn.crossplane.io/network-id: network-test-functions ``` -+ InternetGateway +- InternetGateway ```shell kubectl get InternetGateway -o yaml | grep network-id @@ -221,12 +221,12 @@ spec: Here's what you can do in the KCL script: -+ Return an error using `assert {condition}, {error_message}`. -+ Read the `ObservedCompositeResource` from `option("params").oxr`. -+ Read the `ObservedComposedResources` from `option("params").ocds`. -+ Read the `DesiredCompositeResource` from `option("params").dxr`. -+ Read the `DesiredComposedResources` from `option("params").dcds`. -+ Read the environment variables. e.g. `option("PATH")` (**Not yet implemented**). +- Return an error using `assert {condition}, {error_message}`. +- Read the `ObservedCompositeResource` from `option("params").oxr`. +- Read the `ObservedComposedResources` from `option("params").ocds`. +- Read the `DesiredCompositeResource` from `option("params").dxr`. +- Read the `DesiredComposedResources` from `option("params").dcds`. +- Read the environment variables. e.g. `option("PATH")` (**Not yet implemented**). ## Library diff --git a/versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md b/versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md index d6928510..bae712f3 100644 --- a/versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md +++ b/versioned_docs/version-0.7.0/user_docs/support/faq-kcl.md @@ -2352,3 +2352,90 @@ schema Data: check: environment in allowed, "environment must be one of {}".format(allowed) ``` + +## 52. How to output pretty json string in KCL? + +KCL has in-built support for getting formatted JSON strings. Here's how you can do it: + +Paste the below content in your main.k file. + +```python +import json + +config = { + key1 = "value1" + key2 = "value2" +} +configJson = json.encode(config, ignore_private=True, indent=4) +``` + +After running this code, `configJson` variable will contain a prettified JSON string. + +```json +config: + key1: value1 + key2: value2 +configJson: |- + { + "key1": "value1", + "key2": "value2" + } +``` + +## 53. How to calculate the hash or md5 value of KCL objects? + +KCL have in-built support for calculating MD5 hashes as well. Here is how you can do it: + +Paste the below content in your main.k file. + +```python + +import crypto + +schema Person: + a: int + +aa = Person {a = 1} +bb = Person {a = 2} +cc = Person {a = 2} +aahash = crypto.md5(str(aa)) +bbhash = crypto.md5(str(bb)) +cchash = crypto.md5(str(cc)) +``` + +After running above script, You'll get output like this: + +```bash +aa: + a: 1 +bb: + a: 2 +cc: + a: 2 +aahash: 1992c2ef118972b9c3f96c3f74cdd1a5 +bbhash: 5c71751205373815a9f2e022dd846758 +cchash: 5c71751205373815a9f2e022dd846758 +``` + +## 54. How to deduplicate str lists? + +You can use KCL to deduplicate lists of strings as shown in the code snippet below: + +```python +to_set = lambda items: [str] { + [item for item in {item = None for item in items}] +} + +data = to_set(["aa", "bb", "bb", "cc"]) +dataIsUnique = isunique(data) +``` + +After running above script, You'll get output like this: + +```bash +data: +- aa +- bb +- cc +dataIsUnique: true +```