Mutation, Validation, Abstraction
Production-Ready
KCL is an open-source constraint-based record & functional language mainly used in configuration and policy scenarios.
Learn MoreDownloadEasy-to-Use
Originated from programming languages such as Python and Golang, rich language features, power IDEs and tools.
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 plugins for GitOps.
API Affinity
Native support API ecological specifications such as OpenAPI, Kubernetes CRD and KRM spec.
Codify and Manage Your Modern Configuration and Policy
With configs, models, functions and rules
import base.pkg.kusion_models.kube.frontendserver: frontend.Server {image = "nginx"}
-- Configimport base.pkg.kusion_models.kube.frontendserver: 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: strreplicas: int = option("replicas") or 1labels?: {str:str}
-- Schemaschema 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: strreplicas: int = option("replicas") or 1labels?: {str:str}
import base.pkg.kusion_models.kube.frontendgenLocalityLabels = 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")}
-- Lambdaimport base.pkg.kusion_models.kube.frontendgenLocalityLabels = 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 regexrule 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()
-- Ruleimport regexrule 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()