Skip to main content

17 posts tagged with "Newsletter"

View All Tags

· 6 min read

What is Jsonnet

Jsonnet is a Domain Specific Language (DSL) designed to simplify the creation, management, and maintenance of JSON data. It was originally designed and developed by Google employee Dave Cunningham as a 20% project around 10 years ago. The design of Jsonnet was influenced by several configuration languages used internally at Google, with the aim of improving the readability, maintainability, and programmability of configuration files while remaining compatible with JSON. It introduces features such as variables, functions, conditionals, loops, and code comments, making it easier and more intuitive to write complex data structures.

Jsonnet code is currently owned by Google. However, last month, due to the departure of Jsonnet's founder Dave Cunningham from Google for a new venture, the project is now managed by Rohit Jangid within Google.

What is KCL

KCL is an open-source, constraint-based record and functional language that enhances the writing of complex configurations, including those for cloud-native scenarios. It is hosted by the Cloud Native Computing Foundation (CNCF) as a Sandbox Project. With advanced programming language technology and practices, KCL is dedicated to promoting better modularity, scalability, and stability for configurations. It enables simpler logic writing and offers ease of automation APIs and integration with homegrown systems.

Differences Between Jsonnet and KCL

Design Philosophy

Jsonnet aims to enhance the readability and conciseness of configuration files through the introduction of programming language features such as variables, functions, operators, and control structures. This approach lowers the management complexity of complex configurations with guaranteed full compatibility with JSON. However, Jsonnet does not address important features such as types and validation, leading to a lack of consideration for stability and engineering efficiency in the configuration and policy domain.

At a design level, KCL is more "universal" and "modern", not only in its language design elements but also in its specific language features. Additionally, KCL focuses not only on simplifying the creation, management, and maintenance of JSON/YAML data, but also addresses specific cloud-native complexities and security risks. It converges language design towards problems specific to the cloud-native domain, aiming to converge its design around language technology and GitOps integration to strengthen stability and consistency guarantees. It achieves this through automated API, strong immutability, conflict detection, and support for custom validation expressions, among other capabilities.

Language Features

Both KCL and Jsonnet support variable definition, references, function definitions, and configuration merging, although their degrees of support and syntax semantics differ. They both support common programming language features such as arithmetic, logical operations, comprehensions, conditions, functions, standard libraries, and importing third-party modules, although in different manners. Unlike Jsonnet, KCL provides support for user-defined types, limited or mixed support for object-oriented features, and immutability, ensuring stability at an engineering level. Both KCL and Jsonnet can directly import JSON/YAML data types and Kubernetes CRDs.

Moreover, KCL integrates many built-in language features to fulfill configuration scenarios, such as configuration patching, data validation, and security compliance. This provides KCL with more static analysis capabilities to meet IDE or other tool chain needs and combine constraint checking.

Developer Tools

Both Jsonnet and KCL communities provide a wide range of language tools, including testing, formatting, and package management support. While Jsonnet's dynamic nature makes comprehensive IDE support difficult, KCL offers official Language Server support, which can be easily extended and integrated into IDE plugins, including NeoVim and other emerging LSP-supported IDEs or editors. KCL's Language Server provides complete features such as syntax highlighting, autocompletion, navigation, refactoring, and quick fixes, and is growing rapidly.

Multiple Language Bindings

For better integration of configuration language into users' applications, Jsonnet currently provides four different multi-language implementations in the community, including C++, Go, Rust, and Python bindings. KCL currently offers an official Rust implementation and provides various bindings such as Go, Python, Java, Node.js, C#, C++, C, and WASM, all based on Rust, ensuring predictable and consistent results regardless of the language used.

Performance

  • KCL (test.k)
a = lambda name: str {
apiVersion = "apps/v1"
kind = "Deployment"
metadata = {
name = name
labels = {"app": "nginx"}
}
spec = {
replicas = 3
selector.matchLabels = {"app": "nginx"}
template.metadata.labels = {"app": "nginx"}
template.spec.containers = [
{
name = metadata.name
image = "${metadata.name}:1.14.2"
ports = [{ containerPort = 80 }]
}
]
}
}
temp = {"a${i}": a("nginx") for i in range(1000)}
  • Jsonnet (test.jsonnet)
local a(name) = {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: name,
labels: {["app"]: "nginx"}
},
spec: {
replicas: 3,
selector: {
matchLabels: {["app"]: "nginx"}
},
template: {
metadata: {
labels: {["app"]: "nginx"}
},
spec: {
containers: [
{
name: name,
image: name + ":1.14.2",
ports: [{ containerPort: 80 }]
}
]
}
},
}
};
{
temp: {["a%d" % i]: a("nginx") for i in std.range(0, 1000)},
}

Run time (considering actual resource expenditure in production environments, this test is based on a single core):

KCL v0.9.3Jsonnet v0.20.0 (C++ version)Jsonnet v0.20.0 (Go version)Jsonnet v0.5.0-pre96 (Rust version jrsonnet)Jsonnet v0.1.2 (Rust version rsjsonnet)
155 ms (kcl test.k)1480 ms (jsonnet test.jsonnet)400 ms (jsonnet test.jsonnet)153 ms (rsjsonnet test.jsonnet)142 ms (jrsonnet test.jsonnet)

Summary

The comparison table below summarizes the features of Jsonnet and KCL for reference.

FeaturesJsonnetKCL
Open Source LicenseApache-2.0Apache-2.0
Development LanguageC++, Go, Rust, etcRust
Language StyleJSON-likePython-like, Go-like
Language FunctionalityMediumHigh
Runtime PerformanceMediumMedium
Incremental Compilation
Standard Library
Package Management Tool
Formatting Tool
Documentation Tool
Testing Tool
Debugging Tool✅ (Simple ReplDebugger)
IDE PluginsIntelliJ, NeoVim, VS CodeIntelliJ, NeoVim, VS Code
Multi-language SDKsC++, Go, Python, RustGo, Python, Java, Node.js, C#, C++, C, WASM
Multi-language PluginsGo, Python, Java
Language Server
OCI Registry Support
Community Model Library
REST Server Support
Export Configuration DataJSON, YAML, TOML, ini, etc.JSON, YAML, TOML
Import from Other Data or Schema
Kubernetes Configuration Support
Cloud-native Tool Integration Support

References

· 4 min read

KCL is an open-source configuration and policy language hosted by the Cloud Native Computing Foundation (CNCF) as a Sandbox Project. Built on a foundation of constraints and functional programming principles, KCL enhances the process of writing complex configurations, particularly in cloud-native environments. By leveraging advanced programming language techniques, KCL promotes improved modularity, scalability, and stability in configuration management. It simplifies logic writing, offers easy-to-use automation APIs, and seamlessly integrates with existing systems.

This section will update the KCL language community's latest news, including features, website updates, and the latest community news, helping everyone better understand the KCL community!

KCL Website: https://kcl-lang.io

Special Thanks

Special thanks to all community contributors over the past two weeks. The following list is in no particular order:

  • Thanks to @liangyuanpeng for feedback and test case completion for KCL bugs. 🙌
  • Thanks to @MatisseB for contributing to the KCL PROTOC environment variable setting feature. 🙌
  • Thanks to @DavidChevallier for contributing to the KCL argo-cd third-party library. 🙌
  • Thanks to @kukacz for contributing to the KCL cluster-api-provider-metal3, cluster-api-provider-gcp, and other third-party libraries. 🙌
  • Thanks to @dennybaa for contributing to the victoria-metrics-operator, istio, and other third-party libraries. 🙌
  • Thanks to @ihor-hrytskiv for contributing to the jsonpatch third-party library. 🙌
  • Thanks to @XiaoK29 for contributing to the kcl-go SDK. 🙌
  • Thanks to @patrycju, @kukacz, @dennybaa, @LinYunling, @liangyuanpeng, @riven-blade, @bozaro, @MatisseB, @ealap, @tvandinther, @leon-andria, @Wes McNamee, @Uladzislau Maher, @M Slane, @Tom van Dinther, @Lukáš Kubín, @Mohamed Asif, @Sergei Iakovlev, @Korada Vishal, @Asish Kumar and others for their invaluable suggestions and feedback during the recent period of using KCL 🙌

Overview

Thanks to all contributors for their outstanding work over the past two weeks (2024.06.12 - 2024.06.27). Here is an overview of the key content:

📦️ Modules Updates

  • Added the cluster-api package version 0.1.1, which supports managing clusters through the cluster API.
  • Added the cluster-api-provider-metal3 package, which supports managing Metal3 through the cluster API.
  • Added the cluster-api-provider-gcp package, which supports managing GCP through the cluster API.
  • Added the cluster-api-addon-provider-helm package, which supports managing helm charts through Addon.
  • Added the cluster-api-addon-provider-aws package, which supports managing AWS through the cluster API.
  • Added the cluster-api-provider-azure package, which supports managing Azure through the cluster API.
  • Bump the k8s package version to 1.30.
  • Bump the argo-cd package version to 0.1.1.
  • Bump the victoria-metrics-operator package version to 0.45.1, add some check statement prompt information.
  • Bump the istio package version to 1.21.2, adjust some check rules, and add documentation.
  • Bump the jsonpatch package version to 0.0.5, support rfc6901Decode.

🏄 Language Updates

  • Added centos7 amd64 build environment.
  • Fix some typos in the code comments.
  • Fix the issue of the cache of file.modpath and file.workdir causing performance degradation.
  • Fix the issue some of the schema instance types with inheritance structures are recognized incorrectly.
  • Fix the repeated execution of the branch part in multiple if statements.
  • Fix the environment variable PROTOC setting issue.

💻 IDE Updates

  • Added support for go to def of the schema parameter and schema return value in lambda expressions.
  • Added support for the completion of importing internal packages in the IDE.
  • Added support for the completion of the schema attributes in the IDE.
  • Fix the issue of missing auto-completion prompts in expressions.
  • Fix the issue of the kcl.mod modification not taking effect due to the cache.
  • Fix the issue of the IDE incorrectly prompting the type of the schema attribute.
  • Fix the long string highlighting issue.

📬️ Toolchain Updates

  • Fix the issue of replacing default third-party dependencies with oci dependencies in kcl.mod for kpm.
  • kcl-openapi use case update, fixed some compilation errors, and added a check for the existence of optional attribute values when adding schema.

⛵️ API Updates

  • Fix the issue of inserting configuration errors with the OverrideFile API.
  • ListVariable API supports compile-time configuration merging.

🔥 SDK Updates

  • go SDK supports importing schema from go.
  • go SDK cleans up some deprecated code and adds some tests.
  • Java SDK aligns with API updates.

📚️ Documentation Updates

  • Added the kcl doc generation html/markdown file format error solution.
  • Added the solution to the compilation error caused by the package name in the import statement containing -.
  • Adjusted the document use case to adapt to the update.

Resources

❤️ See here to join us!

For more resources, please refer to