Skip to main content

· 6 min read

KCL is an open-source, constraint-based record and functional language that enhances the writing of complex configurations, including those for cloud-native scenarios. With its 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.

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

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

Overview

Thank you to all contributors for their outstanding work over the past two weeks (08.10-08.23 2023). Here is an overview of the key content:

🔧 Language and Toolchain Updates

  • KCL Formatting Tool Updates - Support for formatting code snippets with syntax errors and partial code snippets and automatic correction of indentation errors in configuration blocks.
  • KCL Documentation Tool Updates - Support for exporting document index pages
  • KCL Import Tool Updates - Support for converting Terraform Provider Schema to KCL Schema
  • KCL Export Tool Updates - Support for exporting OpenAPI Spec from KCL Schema, integrating with OpenAPI ecosystem
  • KCL IDE Updates - Support for compilation cache feature to improve performance of some IDE features and providing rich error messages and import statement quick fix capabilities
  • KCL Package Management Tool Updates - Support for output information experience optimization for the kpm push command and adding duplicate tag check when pushing KCL package. Adding the --vendor parameter for the kpm push and kpm pkg commands to determine whether to package third-party libraries in KCL packages together
  • KCL Language Updates - Optimize Schema semantic check and union type check error messages and support for exporting type output of configuration blocks.

🏄 API Updates

  • KCL Schema model parsing GetSchemaType API newly added KCL package related information and schema attribute default values.

📰 Official Website and Use Case Updates

Special Thanks

The following are listed in no particular order:

KCL Import Tool Updates

The KCL Import Tool now adds support for converting Terraform Provider Schema to KCL Schema based on Protobuf, JsonSchema OpenAPI models, and Go Structures, such as the following Terraform Provider Json (obtained through the command terraform providers schema -json > provider.json , For more details, please refer to https://developer.hashicorp.com/terraform/cli/commands/providers/schema)

{
"format_version": "0.2",
"provider_schemas": {
"registry.terraform.io/aliyun/alicloud": {
"provider": {
"version": 0,
"block": {
"attributes": {},
"block_types": {},
"description_kind": "plain"
}
},
"resource_schemas": {
"alicloud_db_instance": {
"version": 0,
"block": {
"attributes": {
"db_instance_type": {
"type": "string",
"description_kind": "plain",
"computed": true
},
"engine": {
"type": "string",
"description_kind": "plain",
"required": true
},
"security_group_ids": {
"type": ["set", "string"],
"description_kind": "plain",
"optional": true,
"computed": true
},
"security_ips": {
"type": ["set", "string"],
"description_kind": "plain",
"optional": true,
"computed": true
},
"tags": {
"type": ["map", "string"],
"description_kind": "plain",
"optional": true
}
},
"block_types": {},
"description_kind": "plain"
}
},
"alicloud_config_rule": {
"version": 0,
"block": {
"attributes": {
"compliance": {
"type": [
"list",
[
"object",
{
"compliance_type": "string",
"count": "number"
}
]
],
"description_kind": "plain",
"computed": true
},
"resource_types_scope": {
"type": ["list", "string"],
"description_kind": "plain",
"optional": true,
"computed": true
}
}
}
}
},
"data_source_schemas": {}
}
}
}

Then the tool can output the following KCL code

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

schema AlicloudConfigRule:
"""
AlicloudConfigRule

Attributes
----------
compliance: [ComplianceObject], optional
resource_types_scope: [str], optional
"""

compliance?: [ComplianceObject]
resource_types_scope?: [str]

schema ComplianceObject:
"""
ComplianceObject

Attributes
----------
compliance_type: str, optional
count: int, optional
"""

compliance_type?: str
count?: int

schema AlicloudDbInstance:
"""
AlicloudDbInstance

Attributes
----------
db_instance_type: str, optional
engine: str, required
security_group_ids: [str], optional
security_ips: [str], optional
tags: {str:str}, optional
"""

db_instance_type?: str
engine: str
security_group_ids?: [str]
security_ips?: [str]
tags?: {str:str}

check:
isunique(security_group_ids)
isunique(security_ips)

KCL Vault Integration

In just three steps, we can use Vault to store and manage sensitive information and use it in KCL.

Firstly, we install and use Vault to store foo and bar information

vault kv put secret/foo foo=foo
vault kv put secret/bar bar=bar

Then write the following KCL code (main.k)

apiVersion = "apps/v1"
kind = "Deployment"
metadata = {
name = "nginx"
labels.app = "nginx"
annotations: {
"secret-store": "vault"
# Valid format:
# "ref+vault://PATH/TO/KV_BACKEND#/KEY"
"foo": "ref+vault://secret/foo#/foo"
"bar": "ref+vault://secret/bar#/bar"
}
}
spec = {
replicas = 3
selector.matchLabels = metadata.labels
template.metadata.labels = metadata.labels
template.spec.containers = [
{
name = metadata.name
image = "${metadata.name}:1.14.2"
ports = [{ containerPort = 80 }]
}
]
}

Finally, the decrypted configuration can be obtained through the Vals command-line tool

kcl main.k | vals eval -f -

For more details and use cases, please refer to https://kcl-lang.io/docs/user_docs/guides/secret-management/vault

Community

  • 🎉 Congratulations to Zhu Junxing from Huazhong University of Science and Technology for successfully passing the mid-term assessment of the Gitlink Coding Summer Camp (GLCC) and completing the conversion of KCL Import tool Jsonschema and Terraform Provider Schema to KCL Schema. The community will grant him the KCL Community Maintainer role in the future.
  • 💻 KCL participated in the CNCF TAG Application Delivery community meeting and reported on the project.

Resources

❤️ Thanks to all KCL users and community members for their valuable feedback and suggestions in the community. We will write more articles on the new features of KCL v0.5.x, so stay tuned!

For more resources, please refer to

· 4 min read

KCL is an open-source, constraint-based record and functional language that enhances the writing of complex configurations, including those for cloud-native scenarios. With its 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.

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

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

Overview

In the past two weeks (2023 07.26 to 08.09), a total of 34 PRs were merged in all KCL projects. Thanks to all contributors for their outstanding work. The following is a summary of the merged PRs.

  • 🔧 Language and toolchain updates
    • KCL document tool update - Markdown document export support
    • KCL import tool update - JsonSchema - KCL schema conversion support
    • KCL package management tool KPM supports setting compilation parameters in kcl.mod, optimizing command line prompts
    • KCL IDE extension autocomplete, jump, hover document display optimization and Vim and NeoVim KCL plugin support
  • 🏄 API updates
    • KCL Schema model parsing GetSchemaType API newly added decorator information and package information fields
  • 🏠 Community extension updates
    • Helmfile KCL plugin support
  • 📰 Website and case updates

Special Thanks

  • Thanks to @jakezhu9 for contributing to the conversion of JsonSchema to KCL Schema in the KCL Import tool 🙌
  • Thanks to @xxmao123 for contributing to Vim and NeoVim KCL plugins 🙌
  • Thanks to @yyxhero for the help and support provided in Helmfile KCL plugin support 🙌
  • Thanks to @nkabir, @mihaigalos, @prahaladramji, @dhhopen, etc. for their valuable suggestions and discussions on using KCL 🙌

KCL Import Tool Update

On the basis of converting Protobuf, OpenAPI models, and Go structures into KCL Schema, the KCL Import tool adds support for converting JsonSchema to KCL Schema. For example, for the following JsonSchema:

{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/schemas/customer.json",
"type": "object",
"$defs": {
"address": {
"type": "object",
"properties": {
"city": {
"type": "string"
},
"state": {
"$ref": "#/$defs/state"
}
}
},
"state": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
},
"properties": {
"name": {
"type": "string"
},
"address": {
"$ref": "#/$defs/address"
}
}
}

After using the KCL Import tool, the output KCL code is as follows:

schema Customer:
    """
    Customer

    Attributes
    ----------
    name: str, optional
    address: Address, optional
    """

    name?: str
    address?: Address

schema Address:
    """
    Address

    Attributes
    ----------
    city: str, optional
    state: State, optional
    """

    city?: str
    state?: State

schema State:
    """
    State

    Attributes
    ----------
    name: str, optional
    """

    name?: str

Helmfile KCL Plugin

Helmfile is a declarative specification and tool for deploying Helm Charts. With the Helmfile KCL plugin, you can:

  • Edit or verify Helm Chart through non-invasive hook methods, separating the data and logic parts of Kubernetes configuration management
    • Modify resource labels/annotations, inject sidecar container configuration
    • Use KCL schema to validate resources
    • Define your own abstract application models
  • Maintain multiple environment and tenant configurations elegantly, rather than simply copying and pasting.

Here is a detailed explanation using a simple example. With the Helmfile KCL plugin, you do not need to install any components related to KCL. You only need the latest version of the Helmfile tool on your local device.

We can write a helmfile.yaml file as follows:

repositories:
- name: prometheus-community
  url: https://prometheus-community.github.io/helm-charts

releases:
- name: prom-norbac-ubuntu
  namespace: prometheus
  chart: prometheus-community/prometheus
  set:
  - name: rbac.create
    value: false
  transformers:
  # Use KCL Plugin to mutate or validate Kubernetes manifests.
  - apiVersion: krm.kcl.dev/v1alpha1
    kind: KCLRun
    metadata:
      name: "set-annotation"
      annotations:
        config.kubernetes.io/function: |
          container:
            image: docker.io/kcllang/kustomize-kcl:v0.2.0
    spec:
      source: |
        [resource | {if resource.kind == "Deployment": metadata.annotations: {"managed-by" = "helmfile-kcl"}} for resource in option("resource_list").items]

In the above file, we referenced the Prometheus Helm Chart and injected the managed-by="helmfile-kcl" label into all deployment resources of Prometheus with just one line of KCL code. The following command can be used to deploy the above configuration to the Kubernetes cluster:

helmfile apply

For more use cases, please refer to https://github.com/kcl-lang/krm-kcl

Resources

❤️ Thanks to all KCL users and community members for their valuable feedback and suggestions in the community. We will write more articles on the new features of KCL v0.5.x, so stay tuned!

For more resources, please refer to