Skip to main content

9 posts tagged with "Release Blog"

View All Tags

· 14 min read

Introduction

The KCL team is pleased to announce that KCL v0.8.0 is now available! This release has brought three key updates to everyone: Language, Tools, and Integrations.

  • Use KCL language, tools and IDE extensions with more complete features and fewer errors to improve code writing experience and efficiency.

  • More comprehensive and rich community ecosystem integration, improving operation and maintenance experience.

  • More comprehensive KCL third-party dependencies, easier integration with cloud-native ecosystem.

KCL v0.8.0 is now available for download at KCL v0.8.0 Release Page or KCL Official Website.

KCL 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.

This blog will introduce the content of KCL v0.8.0 and recent developments in the KCL community to readers.

Language Updates

🚗 Grammar and Semantics Updates

KCL supports show-hidden

KCL v0.8.0 adds support for --show-hidden to display private variables.

The main.k

a = {_b = 1}

Compile by kcl run main.k --show-hidden.

a:
_b: 1

KCL supports arguments and keyword arguments union

KCL v0.8.0 adds support for arguments and keyword arguments union. Schema instances with arguments will union arguments during union operations.

schema Person[separator]:
firstName: str = "John"
lastName: str
fullName: str = firstName + separator + lastName

x = Person(" ") {lastName = "Doe"}

y = Person("-") {lastName = "Doe1"}

z = x | y

The compiled result is as follows:

x:
firstName: John
lastName: Doe
fullName: John Doe
y:
firstName: John
lastName: Doe1
fullName: John-Doe1
z:
firstName: John
lastName: Doe1
fullName: John-Doe1

KCL supports scalar yaml stream output

In v0.8.0, by using yaml_stream method, you can output the result of yaml scalar.

import manifests

x0 = 1
x1 = 2
manifests.yaml_stream([x0, x1])

The compiled result is as follows:

1
---
2

KCL removes the __settings__ attribute in the compiled output

In v0.8.0, the __settings__ attribute is removed from the compiled output.

schema Person:
__settings__: {str:str} = {"output_type": "STANDALONE"}
name?: str
age?: int
school?: str

a = Person{
name: "a",
}

The compiled result is as follows.

a:
name: a

KCL supports the key and value evaluation in the config expression

In v0.8.0, KCL supports the key and value evaluation in the config expression.

_data = {
"a": 'foo'
"b": 'bar'
}

r0 = [{v = k} for k, v in _data]
r1 = [{k = v} for k, v in _data]
r2 = [{k.foo = v} for k, v in _data]
r3 = [[k] for k, v in _data]
r4 = [[k, v] for k, v in _data]

The compiled result is as follows.

r0:
- foo: a
- bar: b
r1:
- a: foo
- b: bar
r2:
- a:
foo: foo
- b:
foo: bar
r3:
- - a
- - b
r4:
- - a
- foo
- - b
- bar

🚀 Diagnostic Optimization

KCL uses the elif keyword in the if block, not else if.

Compile the following KCL program:

if True: a = 1
else if False: b = 1

The diagnostic information in KCL has added suggestions for error correction:

error[E1001]: InvalidSyntax
--> main.k:2:6
|
2 | else if False: b = 1
| ^ 'else if' here is invalid in KCL, consider using the 'elif' keyword
|

🚀 Language writing experience optimization

KCL standard library adds file system access functions

KCL has added methods to access the file system. In v0.8.0, it supports methods such as read, glob, etc. to access the file system.

By using the read, you can read the contents of a file as a string.

import file

a = file.read("hello.txt")

Add the following content to the hello.txt file:

Hello World !

The compilation result is as follows:

a: Hello World !

By combining the json.decode method, you can easily deserialize a JSON file.

Add the following content to the hello.json file:

{
"name": "John",
"age": 10
}

KCL program:

import file
import json

_a = json.decode(file.read("hello.json"))

name = _a.name
age = _a.age

The compilation result is as follows:

name: John
age: 10

More details - https://kcl-lang.io/zh-CN/docs/reference/model/file/

KCL Compiler supports the use of environment variable KCL_CACHE_PATH to specify the cache path

KCL Compiler will cache the generated code to the directory specified by the environment variable KCL_CACHE_PATH. If not specified, it will be generated to the project root directory.

KCL Plugin System supports using Golang to write KCL plugins

KCL Plugin System supports using Golang to write KCL plugins. The following is an example of using Golang to define the hello plugin.

package hello_plugin

import (
"kcl-lang.io/kcl-go/pkg/plugin"
)

func init() {
plugin.RegisterPlugin(plugin.Plugin{
Name: "hello",
MethodMap: map[string]plugin.MethodSpec{
"add": {
Body: func(args *plugin.MethodArgs) (*plugin.MethodResult, error) {
v := args.IntArg(0) + args.IntArg(1)
return &plugin.MethodResult{V: v}, nil
},
},
},
})
}

With the hello plugin, you can use the add method in the KCL program.

package main

import (
"fmt"

"kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kcl-go/pkg/native" // Import the native API
_ "kcl-lang.io/kcl-go/pkg/plugin/hello_plugin" // Import the hello plugin
)

func main() {
// Note we use `native.MustRun` here instead of `kcl.MustRun`, because it needs the cgo feature.
yaml := native.MustRun("main.k", kcl.WithCode(code)).GetRawYamlResult()
fmt.Println(yaml)
}

const code = `
import kcl_plugin.hello

name = "kcl"
three = hello.add(1,2) # 3

😸 KCL supports linux arm64

KCL v0.8.0 adds support for the Linux arm64 platform in the release product.

You can find the compressed package with the suffix linux-arm64 on the KCL Release Page

🏄 SDK & API Updates

Rust SDK

KCL Rust SDK provides a series of APIs for compiling, validating, testing, and formatting KCL files.

KCL Rust SDK: https://github.com/kcl-lang/lib

Java SDK

KCL Java SDK adds syntax tree, scope, symbol, and other syntax and semantic structure definitions and related query APIs.

Go SDK

  • KCL Doc supports output in OpenAPI format.
  • Go SDK add APIs for parsing.

API Update

  • KCL API adds API for validating JSON and YAML files.
  • Introducing syntax and semantic analysis APIs for analyzing KCL code.
  • Introducing a binary artifact build API for caching compilation results.
  • Introducing a binary artifact execution API for directly running compiled results, avoiding redundant compilation and improving performance.
  • Introducing a code generation API to programmatically implement KCL code generation instead of writing complex templates.

More updates can be found here.

🐞 Other Updates and Bug Fixes

  • Fixed compilation errors caused by using the -S compilation parameter in KCL CLI.
  • Corrected an issue in the kcl fmt tool where an extra newline was added at the end when formatting lambda expressions.
  • Resolved an error in Schema Doc code completion snippets.
  • Fixed a recursive check error for required properties in Schema objects.
  • Enhanced the robustness of Schema index signature type checks.
  • Addressed an issue where string identifiers like “$if” were not correctly defined within Schema.
  • Optimized error messages for unexpected tokens in syntax errors.
  • Rectified variable calculations in unexpected dictionary comprehension expressions where the key and loop variable were the same.

IDE & Toolchain Updates

IDE Updates

IDE semantic-level highlighting enhancement

KCL IDE previously only supported KCL syntax highlighting, as shown in the figure below:

old-ide

We have gradually introduced a new KCL semantic model in the past year. With the support of the new semantic model, KCL IDE now supports semantic-level highlighting. Code that is semantically related will be highlighted in the same way.

new-ide

For more information about the KCL semantic model, see: Unlocking Advanced Code Intelligence with the KCL Semantic Model

IDE supports completion of builtin methods

KCL IDE supports completion of builtin methods, as shown in the figure below:

builtin-completion

IDE supports quick fix for variable reference errors

KCL IDE supports quick fix for variable reference errors, as shown in the figure below:

quick-fix

IDE supports incremental parsing and asynchronous compilation

IDE supports incremental parsing and asynchronous compilation through the new semantic model, which improves the compilation speed and writing experience.

More details: https://kcl-lang.io/zh-CN/blog/2023-12-09-kcl-new-semantic-model

IDE LSP bug fixes

  • Fixed an issue where string interpolation variables in assert statements couldn’t navigate.
  • Corrected an exception-triggering issue in function autocompletion within strings.
  • Resolved an autocompletion error when a comment followed a string.
  • Fixed an issue where internal property symbols in schemas couldn’t navigate.
  • Addressed an exception in alias semantic checks and autocompletion for import statements.
  • Rectified autocompletion issues in check expressions within schemas.
  • Fixed autocompletion errors in nested schema definitions.
  • Resolved missing hover information for certain elements.
  • Ensured consistent symbol types for autocompletion across different syntaxes.
  • Distinguished between schema type and instance autocompletion symbols.
  • Standardized schema comment documentation autocompletion format.
  • Fixed issues where symbols within configuration block if statements couldn’t navigate or autocompletion was affected.

Vet Tool Updates

In v0.8.0 release, we have optimized the diagnostic of the KCL verification tool. In the work of using the KCL verification tool to verify json/yaml files, the abnormal location of the json file will be accurately located.

Take hello.json as an example, we will verify the content of the json file through the following main.k file.

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

The main.k

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

We can verify the content of the json file through the following command.

kcl vet hello.json main.k

We can see the error location in the json file:

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)
|

KCL cli supports git repository as a compilation entry

By using the following command, you can use the KCL git repository as a compilation entry.

kcl run <git url>

kcl mod graph supports output KCL package dependency graph

You can use command kcl mod graph to output the KCL package dependency graph.

KCL Package Management

KCL Package Management supports adding git dependencies through commit

KCL Package Management adds the ability to add git repo dependencies through commit. For example, using https://github.com/KusionStack/catalog,add commit a29e3db as a dependency. You can add it through editing the kcl.mod file or directly through the command line.

Edit the kcl.mod file as follows:

[dependencies]
catalog = { git = "https://github.com/KusionStack/catalog.git", commit = "a29e3db" }

Or add it through the command line:

kcl mod add --git https://github.com/KusionStack/catalog.git --commit a29e3db

KCL Package Management supports the dependency name with -

KCL Package Management supports the dependency name with -. For example, you can add the set-annotation as a dependency through the following command:

kcl mod add set-annotation

In the KCL program, you can reference it through set_annotation.

import set_annotation

KCL Import Tool

  • Support mapping OpenAPI multiplyOf specification to KCL multiplyof function for validation.
  • Support outputting multiple KCL files from YAML Stream-formatted Kubernetes CRD files.
  • Support generating validation expressions for OpenAPI allOf keyword.
  • Support generating validation expressions for KCL array and dictionary types using all/any.

Community Integrations & Extensions Updates

Flux KCL Controller Release

We have developed Flux KCL Controller to supports KCL integration with Flux. After installing Flux KCL Controller in the cluster, you can use the following resources to achieve continuous integration of KCL git repositories through FluxCD.

apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: kcl-deployment
namespace: source-system
spec:
interval: 30s
# The URL of the git repository
url: https://github.com/awesome-kusion/kcl-deployment.git
ref:
branch: main
---
apiVersion: krm.kcl.dev.fluxcd/v1alpha1
kind: KCLRun
metadata:
name: kcl-deployment
namespace: source-system
spec:
sourceRef:
kind: GitRepository
name: kcl-deployment

More details: https://kcl-lang.io/zh-CN/blog/2024-02-01-biweekly-newsletter/

CodeQL KCL Tool

We finished CodeQL KCL dbschema definition and data extraction for KCL syntax and semantics. We can use CodeQL to query KCL code for static analysis and scanning to improve code security.

More details: https://github.com/kcl-lang/codeql-kcl

KCL Modules Update

There are 303 KCL modules in the KCL v0.8.0 release on https://artifacthub.io, mainly including new models related to Crossplane Provider and libraries related to JSON merge operations.

kcl run oci://ghcr.io/kcl-lang/podinfo -D replicas=2
  • JSON Schema library released version 0.0.4, fixed type definition errors. You can execute the following command to update or add dependencies.
kcl mod add jsonschema:0.0.4

Other Updates

The full update and bugfix List of KCL v0.8.0 can be found at: https://github.com/kcl-lang/kcl/compare/v0.7.0...v0.8.0

Document Updates

The versioning semantic option is added to the KCL website. Currently, v0.4.x, v0.5.x, v0.6.x, v0.7.0 and v0.8.0 versions are supported.

Community Updates

KCL LFX Project KickOff

Congratulations to @AkashKumar7902, @octonawish-akcodes, @shashank-iitbhu for being selected for the CNCF KCL LFX project, and thanks to @Vanshikav123, @Amit Pandey for their active participation.

KCL on Crossplane Function Market

After the release of the combination function in Crossplane v1.14, the scope of using Crossplane to build cloud-native platforms has been rapidly expanded. The KCL team has followed up and proactively built a reusable function. The entire Crossplane ecosystem can now leverage the high-level experience and capabilities provided by KCL to build its own cloud-native platform.

More details: https://blog.crossplane.io/function-kcl/

Special Thanks

Thanks to the community friends for their contributions to KCL v0.8.0. The following list is in no particular order:

  • Thanks to @jakezhu9 for the continuous contribution to the kcl import tool 🤝
  • Thanks to @octonawish-akcodes for the continuous contributions to KCL code cleanup and FAQ documentation 🙌
  • Thanks to @satyazzz123 for contributing to the support of reading environment variables in KRM KCL 🙌
  • Thanks to @AkashKumar7902 for the contributions to the package management tool feature in KCL 🙌
  • Thanks to @UtkarshUmre for the contribution to the KCL linux-arm64 build CI 🙌
  • Thanks to @octonawish-akcodes and @d4v1d03 for the continuous contributions to KCL FAQ documentation and KCL IDE feature 🙌
  • Thanks to @octonawish-akcodes for the contribution to the Ansible KCL Module
  • Thanks to @AkashKumar7902 and @Vanshikav123 for the contributions to the package management tool feature in KCL 🙌
  • Thanks to @StevenLeiZhang for the contributions to KCL documentation and KCL plugin
  • Thanks to @patrycju, @Callum Lyall, @Matt Gowie, @ShiroDN, @FLAGLORD, @YiuTerran, @flyinox, @steeling, @Anoop, @Even Solberg, @Phillip Neumann, @Naxe, @rozaliev, @CloudZero357, @martingreber, @az, @Art3mK, @Erick, @TheChinBot, @Evgeny Shepelyuk, @yonas, @vtomilov, @Fdall, @bozaro, @starkers, and @MrGuoRanDuo for their valuable suggestions and feedback during the iteration process of KCL v0.8 🙌

Next Steps

We expect to release KCL v0.9.0 in May 2024. For more details, please refer to KCL 2024 Roadmap and KCL v0.9.0 Milestone. If you have more ideas and needs, please feel free to raise Issues or Discussions in the KCL Github repository, and welcome to join our community for discussion 🙌 🙌 🙌

Additional Resources

For more information, see KCL FAQ.

Resources

Thank all KCL users for their valuable feedback and suggestions during this version release. For more resources, please refer to:

See the community for ways to join us. 👏👏👏

· 9 min read

Introduction

The KCL team is pleased to announce that KCL v0.7.0 is now available! This release has brought three key updates to everyone: Language, Tools, and Integrations.

  • Use KCL language, tools and IDE extensions with more complete features and fewer errors to improve code writing experience and efficiency.

  • The new KCL CLI integrates KCL package management, doc, test and other peripheral ecosystems.

  • The rich KCL third-party library market artifacthub.io provides more than 200 KCL third-party libraries for you to choose from.

KCL v0.7.0 is now available for download at KCL v0.7.0 Release Page or KCL Official Website.

KCL 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.

This blog will introduce the content of KCL v0.7.0 and recent developments in the KCL community to readers.

Language Updates

⭐️ New KCL CLI

When compiling, use kcl, when downloading packages, use kpm, if you have a KCL model that you want to send to the cluster, you also need to use kusion, kcl is the compilation command, kpm run can also be compiled, I also found kusion compile in the kusion command line, do you have the same confusion, what is the relationship between these tools? How do I use them?

For this reason, we provide you with a new KCL CLI, the goal is to include the KCL ecosystem together, to provide you with a unified and concise operation page, everything, one-click direct.

The new KCL CLI will continue to use kcl as the command prefix, and currently provides multiple sub-commands including compilation, package management, and formatting tools.

cli-help

🔧 Diagnostic Information Optimization

We have tried to add repair suggestions in some error messages. If you are frustrated by the KCL compilation failure, you may wish to listen to the compiler's suggestions.

import sub as s1

The_first_kcl_program = s.The_first_kcl_program

Let's listen to what the compiler says. You may have written s1 as s by mistake.

did you mean

KCL cannot find the third-party library used in the package? Try kcl mod add, if it still doesn't work, we have prepared more than 200 KCL models for you on artifacthub.io, come and have a look, there is always one that suits you!

try-kcl-mod-add

🚀 Language Writing Experience Optimization

Removed indentation check in some code blocks

In some code blocks, whether the indentation is aligned has become less important.

If your code is written like this

schema TestIndent:
name: str
msg: str
id: int

test_indent = TestIndent {
name = "test"
msg = "test"
id = 1
}

In the past, you may have encountered a lot of red errors, but now this is not a mistake, kcl fmt will help you tidy it up.

kcl-fmt

Lambda expression type annotation

In the new version of KCL, we have added type annotations for lambda expressions, and you can write lambda with type annotations in the new version of KCL.

schema Test:
name: str

identity: (Test) -> bool = lambda res: Test -> bool {
res.name == "hello"
}

c = identity(Test { name = "hello" })

🏄 API Updates

🐞 Other Updates and Bug Fixes

IDE & Toolchain Updates

IDE Updates

KCL IDE supports goto reference and renaming of symbols

IDE supports goto reference of symbols, using goto reference or find all references:

find-ref

IDE supports renaming of symbols:

rename

IDE supports formatting of import statements and union types

We have optimized the behavior of blank lines between import statements and other code blocks (formatted as one blank line) and the behavior of spaces between union types (formatted as separated by |):

fmt

KCL IDE has added a lot of completion prompts

We have added a lot of completion prompts for the configuration definition, which simplifies the user's mind of writing configuration based on the model and improves the efficiency of configuration editing. In addition, the parameter completion when calling the built-in function is enhanced. Talk is cheap, let's take a look at the effect directly:

func-completion

conf-completion

And for the model design, we have also added a quick generation of docstring to reduce the boilerplate of typing by hand:

gen-docstring

Performance

  • KCL has designed and restructured a new semantic model, as well as an API that supports nearest symbol search and symbol semantic information query.
  • The migration of IDE completion, jump, and hover functions to new semantic models significantly reduces the difficulty and code volume of IDE development.
  • The KCL compiler supports syntax incremental parsing and semantic incremental checking, which improves the performance of KCL compilation, construction, and IDE plugin usage in most scenarios by 5-10 times.

KCL IDE other updates and bug fixes

  • KCL IDE extension for IntelliJ 2023.2+
  • Fix the problem that the language service virtual file system related bug: the file dimension change will cause the language service to crash and must be restarted to recover, which has now been fixed.
  • Support import statement completion of external package dependencies introduced by package management tools
  • Fix the display position of the function parameter undefined type error

Test Tool Updates

Are you worried that your KCL program is written incorrectly? Why not come and test it? This update provides a new KCL test tool.

The new KCL test tool supports writing unit tests using KCL lambda and executing tests using the tool.

You can write your test cases through lambda expressions in the file with the suffix _test.k.

import .app

# Convert the `App` model into Kubernetes Deployment and Service Manifests
test_kubernetesRender = lambda {
a = app.App {
name = "app"
containers.ngnix = {
image = "ngnix"
ports = [{containerPort = 80}]
}
service.ports = [{ port = 80 }]
}
deployment_got = kubernetesRender(a)
assert deployment_got[0].kind == "Deployment"
assert deployment_got[1].kind == "Service"
}

You can run this test case and view the test results through kcl test.

After the test is passed, you will get the following results:

test-pass

If your test fails, kcl test will output error information to help you troubleshoot the problem.

test-failed

KCL Package Management

The update command is added to the kcl mod command. The update command is used to automatically update local dependencies. kcl mod update will automatically download the missing third-party libraries for you. For details, please refer to: https://github.com/kcl-lang/kpm/pull/212

KCL Import Tool

The KCL Import tool supports one-click generation of KCL configuration/models from YAML/JSON/CRD/Terraform Schema, realizing automated migration.

If you have the following yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

You can convert it to a KCL program through the command kcl import test.yaml.

"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""

apiVersion = "apps/v1"
kind = "Deployment"
metadata = {
name = "nginx-deployment"
labels = {
app = "nginx"
}
}
spec = {
replicas = 3
selector = {
matchLabels = {
app = "nginx"
}
}
template = {
metadata = {
labels = {
app = "nginx"
}
}
spec = {
containers = [
{
name = "nginx"
image = "nginx:1.14.2"
ports = [
{
containerPort = 80
}
]
}
]
}
}
}

More details: https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/adapt-from-kubernetes

Community Integrations & Extensions Updates

KCL Marketplace with ArtifactHub

Through the integration of artifacthub.io, we have built a KCL third-party library market, where you can share your KCL programs with us. You can also choose freely and find the KCL third-party library that suits you!

Open the homepage of artifacthub.io, search for the keyword you need directly, and you can see the relevant content about the KCL third-party library!

artifachub-index

Click on the third-party library homepage, you can view the detailed content and related documents about the third-party library.

pkg-page

If you don't know how to use these third-party libraries, the button on the right can bring up the installation page for you.

install-pkg

Welcome to contribute your third-party libraries to the KCL community on artifacthub.io and make the KCL community more colorful!

Contributing to KCL Marketplace: https://kcl-lang.io/docs/user_docs/guides/package-management/how-to/publish_pkg_to_ah

Other Updates

The full update and bugfix List of KCL v0.7.0 can be found at: https://github.com/kcl-lang/kcl/compare/v0.6.0...v0.7.0

Document Updates

The versioning semantic option is added to the KCL website. Currently, v0.4.x, v0.5.x, v0.6.x and v0.7.0 versions are supported.

Community Updates

KCL Officially Becomes CNCF Sandbox Project

🎉 🎉 🎉 On September 20, 2023, the KCL project passed the evaluation of the Technical Oversight Committee of the Cloud Native Computing Foundation (CNCF), the world's top open source foundation, and officially became a CNCF sandbox project.

More details - https://kcl-lang.io/blog/2023-09-19-kcl-joining-cncf-sandbox/

Next Steps

We expect to release KCL v0.8.0 in February 2024. For more details, please refer to KCL 2024 Roadmap and KCL v0.8.0 Milestone. If you have more ideas and needs, please feel free to raise Issues or Discussions in the KCL Github repository, and welcome to join our community for discussion 🙌 🙌 🙌

Additional Resources

For more information, see KCL FAQ.

Resources

Thank all KCL users for their valuable feedback and suggestions during this version release. For more resources, please refer to:

See the community for ways to join us. 👏👏👏