- Install Go 1.17+
- Install KCLVM (or
go run ./cmds/kcl-go/ setup-kclvm
and add./_build/{Darwin|Darwin-arm64|Linux}/bin
toPATH
)
$ go run ./cmds/kcl-go
$ 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"
"kusionstack.io/kclvm-go"
)
func main() {
yaml := kclvm.MustRun("kubernetes.k", kclvm.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
Apache License Version 2.0