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.
You can use KCL to
- Generate low-level static configuration data such as JSON, YAML, etc., or integrate with existing data.
- Reduce boilerplate in configuration data with the schema modeling.
- Define schemas with rule constraints for configuration data and validate them automatically.
- Organize, simplify, unify and manage large configurations without side effects through gradient automation schemes and GitOps.
- Manage large configurations in a scalable way with isolated configuration blocks.
- Mutating or validating Kubernetes resources with cloud-native configuration tool plugins.
- Used as a platform engineering programming language to deliver modern applications with Kusion Stack.
go run ./cmds/kcl-go run hello.k
name: kcl
age: 1
two: 2
x0:
name: kcl
age: 1
x1:
name: kcl
age: 101
go test ./...
package main
import (
"fmt"
kcl "kcl-lang.io/kcl-go"
)
func main() {
yaml := kcl.MustRun("kubernetes.k", kcl.WithCode(k_code)).GetRawYamlResult()
fmt.Println(yaml)
}
const k_code = `
apiVersion = "apps/v1"
kind = "Deployment"
metadata = {
name = "nginx"
labels.app = "nginx"
}
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 }]
}
]
}
`
Run the command:
go run ./examples/kubernetes/main.go
Output:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
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
See the KCL website
Apache License Version 2.0