Skip to content

Peefy/kubectl-kcl

 
 

Repository files navigation

Kubectl KCL Plugin

Go Report Card GoDoc License

KCL is a constraint-based record & functional domain language. Full documents of KCL can be found here.

This project is a kubectl plugin to generate, mutate and validate Kubernetes manifests using the KCL programming language.

Installation

Krew

Add to krew index and install with:

kubectl krew index add kubectl-kcl https://github.com/KusionStack/kubectl-kcl
kubectl krew install kubectl-kcl/kubectl-kcl

GitHub release

Download the binary from GitHub releases.

If you want to use this as a kubectl plugin, then copy the kubectl-kcl binary to your PATH. If not, you can also use the binary standalone.

Build

Prerequisites

  • GoLang 1.18+
git clone https://github.com/KusionStack/kubectl-kcl.git
cd kubectl-kcl
go run main.go

Test

Unit Test

go test -v ./...

Integration Test

go run main.go run --file ./examples/kcl-run.yaml

Guides for Developing KCL

Here's what you can do in the KCL script:

  • Read resources from option("resource_list"). The option("resource_list") complies with the KRM Functions Specification. You can read the input resources from option("resource_list")["items"] and the functionConfig from option("resource_list")["functionConfig"].
  • Return a KPM list for output resources.
  • Return an error using assert {condition}, {error_message}.
  • Read the environment variables. e.g. option("PATH") (Not yet implemented).
  • Read the OpenAPI schema. e.g. option("open_api")["definitions"]["io.k8s.api.apps.v1.Deployment"] (Not yet implemented).

Full documents of KCL can be found here.

About

Kubectl KCL Plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 71.3%
  • Makefile 18.0%
  • Shell 10.7%