|
| 1 | +--- |
| 2 | +slug: 2024-07-05-kcl-0.9.0-release |
| 3 | +title: KCL v0.9.0 Release Blog |
| 4 | +authors: |
| 5 | + name: KCL Team |
| 6 | + title: KCL Team |
| 7 | +tags: [Release Blog, KCL] |
| 8 | +--- |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +The KCL team is pleased to announce that **KCL v0.9.0 is now available**! This release has brought three key updates to everyone |
| 13 | + |
| 14 | +- _Enhance the coding experience and efficiency with a more performant, feature-rich, and less error-prone KCL language, toolchain, and IDE._ |
| 15 | +- _A more comprehensive and diverse set of standard libraries, third-party libraries, and community ecosystem integrations, covering different application scenarios and requirements._ |
| 16 | +- _Richer multi-language SDKs and plugins, seamlessly integrating with different programming languages and development environments._ |
| 17 | + |
| 18 | +[KCL](https://github.com/kcl-lang) is an open-source, constraint-based record and functional language hosted by Cloud Native Computing Foundation (CNCF). KCL improves the writing of numerous complex configurations, such as cloud-native scenarios, through its mature programming language technology and practice. It is dedicated to building better modularity, scalability, and stability around configurations, simpler logic writing, faster automation, and great built-in or API-driven integrations. |
| 19 | + |
| 20 | +## ❤️ Special Thanks |
| 21 | + |
| 22 | +**We would like to extend our heartfelt thanks to all 120 community contributors who participated in the iteration from version v0.8 to v0.9 over the past 120 days. The following list is in no particular order.** |
| 23 | + |
| 24 | +*@Shashank Mittal, @MattHodge, @officialasishkumar, @Gmin2, @Akash Kumar, @sfshumaker, @sanzoghenzo, @MOHAMED FAWAS, @bradkwadsworth-mw, @excalq, @Daksh-10, @metacoma, @Wes McNamee, @Stéphane Este-Gracias, @octonawish-akcodes, @zong-zhe, @shashank-iitbhu, @NAVRockClimber, @AkashKumar7902, @Petrosz007, @patrycju, @Korada Vishal, @selfuryon, @tvandinther, @vtomilov, @Peefy, @taylormonacelli, @Tertium, @Stefano Borrelli, @Bishal, @kukacz, @borgius, @steeling, @jheyduk, @HStéphane Este-Gracias, @userxiaosi, @folliehiyuki, @kubernegit, @nizq, @Alexander Fuchs, @ihor-hrytskiv, @Mohamed Asif, @reedjosh, @Wck-iipi, @evensolberg, @aldoborrero@ron18219, @rodrigoalvamat, @mproffitt, @karlhepler, @shruti2522, @leon-andria, @prahaladramji, @Even Solberg, @utnim2, @warjiang, @Asish Kumar, @He1pa, @Emmanuel Alap, @d4v1d03, @Yvan da Silva, @Abhishek, @DavidChevallier, @zargor, @Kim Sondrup, @SamirMarin, @Hai Wu, @MatisseB, @beholdenkey, @nestoralonso, @HAkash Kumar, @olinux, @liangyuanpeng, @ngergs, @Penguin, @ealap, @markphillips100, @Henri Williams, @eshepelyuk, @CC007, @mintu, @M Slane, @zhuxw, @atelsier, @aleeriz, @LinYunling, @YvanDaSilva, @chai2010, @Sergey Ryabin, @vfarcic, @vemoo, @riven-blade, @ibishal, @empath-nirvana, @bozaro, @jgascon-nx, @reckless-huang, @Sergei Iakovlev, @Blarc, @JeevaRamanathan, @dennybaa, @PrettySolution, @east4ming, @nkabir, @sestegra, @XiaoK29, @ricochet1k, @yjsnly, @umaher, @SjuulJanssen, @wilsonwang371, @Lukáš Kubín, @samuel-deal-tisseo, @blakebarnett, @Uladzislau Maher, @ytsarev, @Vishalk91-4, @Stephen C, @Tom van Dinther, @MrGuoRanDuo, @dopesickjam* |
| 25 | + |
| 26 | +## 📚 Key Updates |
| 27 | + |
| 28 | +### ⚡️ Performance Enhancements |
| 29 | + |
| 30 | +#### Runtime Performance |
| 31 | + |
| 32 | +In the new KCL v0.9 release, a new fast runtime mode has been introduced. This can be enabled by setting the `KCL_FAST_EVAL=1` environment variable, which improves startup and runtime performance. For configurations using Schema (such as the `k8s` third-party library), this offers approximately a **3x** performance boost compared to previous versions. For simple configurations without Schema, output YAML performance has been tested to surpass tools like `helm template` and `kustomize build` that use YAML and Go Templates. |
| 33 | + |
| 34 | +#### IDE Performance |
| 35 | + |
| 36 | +KCL IDE has further optimized incremental compilation and performance for semantic analysis in large projects. For KCL projects with around 400 files, the end-to-end response time has been reduced to **20%** of the previous version. |
| 37 | + |
| 38 | +### 🔧 Core Features |
| 39 | + |
| 40 | +#### Language |
| 41 | + |
| 42 | ++ String interpolation now supports escaping with `\${}` similar to Shell to cancel interpolation. |
| 43 | + |
| 44 | +```python |
| 45 | +world = "world" |
| 46 | +hello_world_0 = "hello ${world}" # hello world |
| 47 | +hello_world_1 = "hello \${world}" # hello ${world} |
| 48 | +``` |
| 49 | + |
| 50 | ++ Added schema type support to the `typeof` function for distinguishing schema types from instances. |
| 51 | + |
| 52 | +```python |
| 53 | +schema Foo: |
| 54 | + bar?: str |
| 55 | + |
| 56 | +foo = Foo {} |
| 57 | +type_schema = typeof(foo) # schema |
| 58 | +type_type = typeof(Foo) # type |
| 59 | +``` |
| 60 | + |
| 61 | ++ Added a `full_pkg` keyword argument to the `instances()` method of Schema to read instances of the corresponding schema from all code. |
| 62 | + |
| 63 | +```python |
| 64 | +schema Person: |
| 65 | + name: str |
| 66 | + |
| 67 | +alice = Person {name = "Alice"} |
| 68 | +all_persons = Person.instances(True) |
| 69 | +``` |
| 70 | + |
| 71 | ++ Removed implicit comparison between bool and int types `0 < True`. |
| 72 | ++ Removed comparison features for the list type `[0] < [1]`. |
| 73 | ++ Added type assertion failure functionality to the `as` keyword. |
| 74 | ++ Optimized closure variable capture logic of `lambda` functions and configuration code blocks `{}` in different scopes to be more intuitive. |
| 75 | + |
| 76 | +#### Toolchain |
| 77 | + |
| 78 | ++ `kcl run` now supports outputting configurations in TOML format with the `--format` toml option. |
| 79 | ++ `kcl mod add` now supports adding dependencies from private third-party OCI Registries and Git repositories with the `--oci` and `--git` options. |
| 80 | ++ `kcl import` now supports importing entire Go Packages as KCL Schemas. |
| 81 | ++ `kcl import` now supports importing files with YAML stream format (`---`). |
| 82 | ++ `kcl import` now supports importing TOML files as KCL configurations. |
| 83 | ++ `kcl clean` now supports cleaning external dependencies and compile caches. |
| 84 | ++ `kcl mod init` now supports setting the version of a new KCL module with the `--version` tag. |
| 85 | ++ Commands like `kcl run`, `kcl mod add`, and `kcl mod pull` now support accessing private repositories via local Git. |
| 86 | + |
| 87 | +#### IDE |
| 88 | + |
| 89 | ++ Supports multiple quick fix options. |
| 90 | ++ Syntax highlighting for `kcl.mod` and `kcl.mod.lock` files. |
| 91 | ++ Partial syntax hover highlighting in the IDE. |
| 92 | ++ `import` completion for external dependencies. |
| 93 | ++ Function symbol highlighting and Inlay Hints displaying default variable types. |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +#### API |
| 98 | + |
| 99 | ++ The Override API now supports setting different attribute operators (`:`, `=`, and `+=`) for configuration overrides. |
| 100 | ++ Go API now supports prototext format and KCL schema output as KCL configurations. |
| 101 | ++ Go API now supports serializing any Go Type and Go Value to KCL Schema and configurations. |
| 102 | + |
| 103 | +### 📦️ Standard Libraries and Third-Party Libraries |
| 104 | + |
| 105 | +#### Standard Libraries |
| 106 | + |
| 107 | ++ Added the `file` standard library for file IO operations, such as reading configurations from YAML and performing configuration merges. |
| 108 | + |
| 109 | +```python |
| 110 | +import file |
| 111 | +import yaml |
| 112 | +import json_merge_patch as p |
| 113 | + |
| 114 | +config = p.merge(yaml.decode(file.read("deployment.yaml")), { |
| 115 | + metadata.name = "override_value" |
| 116 | +}) |
| 117 | +``` |
| 118 | + |
| 119 | +For more functions in the `file` module, see: [https://www.kcl-lang.io/docs/reference/model/file](https://www.kcl-lang.io/docs/reference/model/file) |
| 120 | + |
| 121 | ++ Added the `template` standard library for writing template configurations. |
| 122 | + |
| 123 | +```python |
| 124 | +import template |
| 125 | + |
| 126 | +_data = { |
| 127 | + name = "handlebars", |
| 128 | + v = [ { a = 1 }, { a = 2 } ], |
| 129 | + c = { d = 5 }, |
| 130 | + g = { b = [ { aa = { bb = 55} }, { aa = { bb = 66} } ] }, |
| 131 | + people = [ "Yehuda Katz", "Alan Johnson", "Charles Jolley" ] |
| 132 | +} |
| 133 | + |
| 134 | +content = template.execute("""\ |
| 135 | +Hello world from {{name}} |
| 136 | +
|
| 137 | +{{#each v}} |
| 138 | +{{this.a}} |
| 139 | +{{/each}} |
| 140 | +{{ c.d }} |
| 141 | +{{#each people}} |
| 142 | +{{ this }} |
| 143 | +{{/each}} |
| 144 | +{{#each g.b}} |
| 145 | +{{this.aa.bb}} |
| 146 | +{{/each}} |
| 147 | +""", _data) |
| 148 | +``` |
| 149 | + |
| 150 | ++ Added the `runtime` standard library for capturing runtime exceptions, useful for `kcl test` tool to test exception cases. |
| 151 | + |
| 152 | +```python |
| 153 | +import runtime |
| 154 | + |
| 155 | +schema Person: |
| 156 | + name: str |
| 157 | + age: int |
| 158 | + |
| 159 | + check: |
| 160 | + 0 <= age <= 120, "age must be in [1, 120], got ${age}" |
| 161 | + |
| 162 | +test_person_check_error = lambda { |
| 163 | + assert runtime.catch(lambda { |
| 164 | + p = Person {name = "Alice", age: -1} |
| 165 | + }) == "age must be in [1, 120], got -1" |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +#### Third-Party Libraries |
| 170 | + |
| 171 | +The number of KCL models has increased to **313**, including major updates as follows: |
| 172 | + |
| 173 | ++ `k8s` released version 1.30 |
| 174 | ++ `argo-cd` released version 0.1.1 |
| 175 | ++ `argo-workflow` released version 0.0.3 |
| 176 | ++ `istio` released version 1.21.2 |
| 177 | ++ `victoria-metrics-operator` released version 0.45.1 |
| 178 | ++ `cert-manager` released version 0.1.2 |
| 179 | ++ `cilium` released version 0.1.1 |
| 180 | ++ `Longhorn` released version 0.0.1 |
| 181 | ++ `jsonpatch` released version 0.0.5, supporting rfc6901Decode |
| 182 | ++ Added a new third-party library `difflib` for comparing configuration differences |
| 183 | ++ Added `argo-cd-order` for sorting argocd sync operation resource order |
| 184 | ++ Added models for `cluster-api`, including `cluster-api`, `cluster-api-provider-metal3`, `cluster-api-provider-gcp`, `cluster-api-addon-provider-helm`, `cluster-api-addon-provider-aws`, `cluster-api-provider-azure`, and more |
| 185 | + |
| 186 | +### ☸️ Ecosystem Integration |
| 187 | + |
| 188 | ++ Fixed concurrency issue in Argo KCL plugin causing Sync errors. |
| 189 | ++ Releasing Flux KCL Controller [https://github.com/kcl-lang/flux-kcl-controller](https://github.com/kcl-lang/flux-kcl-controller), currently supporting GitOps with OCI and Git configurations. |
| 190 | ++ KCL officially integrated into Crossplane Functions Marketplace, releasing v0.9.0 [https://github.com/crossplane-contrib/function-kcl](https://github.com/crossplane-contrib/function-kcl). |
| 191 | + |
| 192 | +```yaml |
| 193 | +apiVersion: apiextensions.crossplane.io/v1 |
| 194 | +kind: Composition |
| 195 | +metadata: |
| 196 | + name: example |
| 197 | +spec: |
| 198 | + compositeTypeRef: |
| 199 | + apiVersion: example.crossplane.io/v1beta1 |
| 200 | + kind: XR |
| 201 | + mode: Pipeline |
| 202 | + pipeline: |
| 203 | + - step: basic |
| 204 | + functionRef: |
| 205 | + name: function-kcl |
| 206 | + input: |
| 207 | + apiVersion: krm.kcl.dev/v1alpha1 |
| 208 | + kind: KCLInput |
| 209 | + source: | |
| 210 | + # Read the XR |
| 211 | + oxr = option("params").oxr |
| 212 | + # Patch the XR with the status field |
| 213 | + dxr = oxr | { |
| 214 | + status.dummy = "cool-status" |
| 215 | + } |
| 216 | + # Construct a AWS bucket |
| 217 | + bucket = { |
| 218 | + apiVersion = "s3.aws.upbound.io/v1beta1" |
| 219 | + kind = "Bucket" |
| 220 | + metadata.annotations: { |
| 221 | + "krm.kcl.dev/composition-resource-name" = "bucket" |
| 222 | + } |
| 223 | + spec.forProvider.region = option("oxr").spec.region |
| 224 | + } |
| 225 | + # Return the bucket and patched XR |
| 226 | + items = [bucket, dxr] |
| 227 | + - step: automatically-detect-ready-composed-resources |
| 228 | + functionRef: |
| 229 | + name: function-auto-ready |
| 230 | +``` |
| 231 | +
|
| 232 | +Additionally, you can find more real use cases of KCL with other ecosystem projects here: |
| 233 | +
|
| 234 | ++ [https://github.com/mindwm/mindwm-gitops](https://github.com/mindwm/mindwm-gitops) |
| 235 | ++ [https://github.com/vfarcic/crossplane-kubernetes](https://github.com/vfarcic/crossplane-kubernetes) |
| 236 | ++ [https://github.com/giantswarm/crossplane-gs-apis/blob/main/crossplane.giantswarm.io/xnetworks/package/compositions/peered-vpc-network.yaml](https://github.com/giantswarm/crossplane-gs-apis/blob/main/crossplane.giantswarm.io/xnetworks/package/compositions/peered-vpc-network.yaml) |
| 237 | ++ [https://github.com/upbound/configuration-aws-eks/blob/main/apis/composition-kcl.yaml](https://github.com/upbound/configuration-aws-eks/blob/main/apis/composition-kcl.yaml) |
| 238 | +
|
| 239 | +### 🧩 Multi-Language SDKs and Plugins |
| 240 | +
|
| 241 | +#### Multi-Language SDKs |
| 242 | +
|
| 243 | +The number of KCL multi-language SDKs has increased to **7**, currently supporting Rust, Go, Java, .NET, Python, Node.js, and WASM. These can be used without installing additional KCL command-line tools, optimizing the installation size to **90%** of previous versions and removing the need for complex system dependencies. Furthermore, each SDK provides the same APIs for code execution, code analysis, type parsing, and adding external dependencies. Here are some examples with the Java and C# SDKs: |
| 244 | +
|
| 245 | ++ Java |
| 246 | +
|
| 247 | +```java |
| 248 | +import com.kcl.api.API; |
| 249 | +import com.kcl.api.Spec.ExecProgram_Args; |
| 250 | +import com.kcl.api.Spec.ExecProgram_Result; |
| 251 | + |
| 252 | +public class ExecProgramTest { |
| 253 | + public static void main(String[] args) throws Exception { |
| 254 | + API api = new API(); |
| 255 | + ExecProgram_Result result = api |
| 256 | + .execProgram(ExecProgram_Args.newBuilder().addKFilenameList("path/to/kcl.k").build()); |
| 257 | + System.out.println(result.getYamlResult()); |
| 258 | + } |
| 259 | +} |
| 260 | +``` |
| 261 | + |
| 262 | ++ C# |
| 263 | + |
| 264 | +```csharp |
| 265 | +namespace KclLib.Tests; |
| 266 | + |
| 267 | +using KclLib.API; |
| 268 | + |
| 269 | +public class KclLibAPITest |
| 270 | +{ |
| 271 | + public static void Main() |
| 272 | + { |
| 273 | + var execArgs = new ExecProgram_Args(); |
| 274 | + execArgs.KFilenameList.Add("path/to/kcl.k"); |
| 275 | + var result = new API().ExecProgram(execArgs); |
| 276 | + Console.WriteLine(result.YamlResult); |
| 277 | + } |
| 278 | +} |
| 279 | +``` |
| 280 | + |
| 281 | +For more information on installing and using other SDKs, see [https://github.com/kcl-lang/lib](https://github.com/kcl-lang/lib) |
| 282 | + |
| 283 | +#### Multi-Language Plugins |
| 284 | + |
| 285 | +The number of KCL multi-language plugins has increased to **3**, currently supporting Go, Python, and Java. Only basic SDK dependencies are required to achieve seamless interoperation between common languages and KCL. Here are some examples with Python and Java plugins: |
| 286 | + |
| 287 | +Write the following KCL code (main.k) |
| 288 | + |
| 289 | +```python |
| 290 | +import kcl_plugin.my_plugin |
| 291 | + |
| 292 | +result = my_plugin.add(1, 1) |
| 293 | +``` |
| 294 | + |
| 295 | +Use the Python SDK to register a Python function for calling in KCL |
| 296 | + |
| 297 | +```python |
| 298 | +import kcl_lib.plugin as plugin |
| 299 | +import kcl_lib.api as api |
| 300 | + |
| 301 | +plugin.register_plugin("my_plugin", {"add": lambda x, y: x + y}) |
| 302 | + |
| 303 | +def main(): |
| 304 | + result = api.API().exec_program( |
| 305 | + api.ExecProgram_Args(k_filename_list=["main.k"]) |
| 306 | + ) |
| 307 | + assert result.yaml_result == "result: 2" |
| 308 | + |
| 309 | +main() |
| 310 | +``` |
| 311 | + |
| 312 | +Use the Java SDK to register a Java function for calling in KCL |
| 313 | + |
| 314 | +```java |
| 315 | +package com.kcl; |
| 316 | + |
| 317 | +import com.kcl.api.API; |
| 318 | +import com.kcl.api.Spec.ExecProgram_Args; |
| 319 | +import com.kcl.api.Spec.ExecProgram_Result; |
| 320 | + |
| 321 | +import java.util.Collections; |
| 322 | + |
| 323 | +public class PluginTest { |
| 324 | + public static void main(String[] mainArgs) throws Exception { |
| 325 | + API.registerPlugin("my_plugin", Collections.singletonMap("add", (args, kwArgs) -> { |
| 326 | + return (int) args[0] + (int) args[1]; |
| 327 | + })); |
| 328 | + ExecProgram_Result result = new API() |
| 329 | + .execProgram(ExecProgram_Args.newBuilder().addKFilenameList("main.k").build()); |
| 330 | + System.out.println(result.getYamlResult()); |
| 331 | + } |
| 332 | +} |
| 333 | +``` |
| 334 | + |
| 335 | +For more examples of using other multi-language plugins, see [https://www.kcl-lang.io/docs/reference/plugin/overview](https://www.kcl-lang.io/docs/reference/plugin/overview) |
| 336 | + |
| 337 | +Additionally, you can find more real use cases of KCL multi-language plugins here: |
| 338 | + |
| 339 | ++ [https://github.com/cakehappens/kcfoil/blob/main/cmd/kcf/template.go](https://github.com/cakehappens/kcfoil/blob/main/cmd/kcf/template.go) |
| 340 | + |
| 341 | +## 🌐 Other Resources |
| 342 | + |
| 343 | +🔥 Check out the [KCL Community](https://github.com/kcl-lang/community) and join us 🔥 |
| 344 | + |
| 345 | +For more resources, refer to: |
| 346 | + |
| 347 | +- [KCL Website](https://kcl-lang.io/) |
| 348 | +- [KusionStack Website](https://kusionstack.io/) |
0 commit comments