Skip to main content

Abstract, Validation

Production-Ready

KCL is an open-source constraint-based record & functional language mainly used in configuration and policy scenarios.

Learn MoreDownload


Easy-to-Use

Originated from high-level languages ​​such as Python and Golang, incorporating functional language features.

Quick Modeling

Schema-centric configuration types and modular abstraction with logic and policy based on Config, Schema, Lambda, Rule.

Stability

Configuration stability built on static type system, strong immutablity , and constraints.

Scalability

High scalability through automatic merge mechanism of isolated config blocks with multiple strategies.

Fast Automation

High performance and gradient automation scheme of CRUD APIs, multilingual SDKs, language plugin.

API Affinity

Native support API ecological specifications such as OpenAPI, Kubernetes CRD, Kubernetes YAML spec.

Codify and Manage Your Modern Configuration and Policy

With configs, models, functions and rules

import base.pkg.kusion_models.kube.frontend
server: frontend.Server {
image = "nginx"
}
-- Config
import base.pkg.kusion_models.kube.frontend
server: frontend.Server {
image = "nginx"
}
schema Server:
"""Server is the abstraction of Deployment and StatefulSet.
image: str, default is Undefined, required.
Image name. More info: https://kubernetes.io/docs/concepts/containers/images.
replicas: int, default is 1, required.
Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.
labels: {str:str}, default is Undefined, optional.
Labels is a map of string keys and values that can be used to organize and categorize (scope and select) objects.
"""
image: str
replicas: int = option("replicas") or 1
labels?: {str:str}
-- Schema
schema Server:
"""Server is the abstraction of Deployment and StatefulSet.
image: str, default is Undefined, required.
Image name. More info: https://kubernetes.io/docs/concepts/containers/images.
replicas: int, default is 1, required.
Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.
labels: {str:str}, default is Undefined, optional.
Labels is a map of string keys and values that can be used to organize and categorize (scope and select) objects.
"""
image: str
replicas: int = option("replicas") or 1
labels?: {str:str}
import base.pkg.kusion_models.kube.frontend
genLocalityLabels = lambda cluster: str, app: str -> {str:str} {
{
"cluster.x-k8s.io/cluster-name" = cluster
"app.kubernetes.io/name" = app
}
}
server: frontend.Server {
labels: genLocalityLabels("my-cluster", "nginx")
}
-- Lambda
import base.pkg.kusion_models.kube.frontend
genLocalityLabels = lambda cluster: str, app: str -> {str:str} {
{
"cluster.x-k8s.io/cluster-name" = cluster
"app.kubernetes.io/name" = app
}
}
server: frontend.Server {
labels: genLocalityLabels("my-cluster", "nginx")
}
import regex
rule ServerRule for Server:
1 <= replicas < 20, "replica should be in range [1, 20)"
regex.match(image, r"^([a-z0-9.:]+).([a-z]+):([a-z0-9]+)/([a-z0-9.]+)/([a-z0-9-_.:]+)$"), "image name should satisfy the `REPOSITORY:TAG` form"
ServerRule()
-- Rule
import regex
rule ServerRule for Server:
1 <= replicas < 20, "replica should be in range [1, 20)"
regex.match(image, r"^([a-z0-9.:]+).([a-z]+):([a-z0-9]+)/([a-z0-9.]+)/([a-z0-9-_.:]+)$"), "image name should satisfy the `REPOSITORY:TAG` form"
ServerRule()

Config

Start your cloud-native journey with scalable config

Schema

Abstract your schema-centric model with static typing

Lambda

Define and reuse your config and logic through small function fragments

Rule

Define your environmental rules to ensure consistency and stability