/kubectl-kcl

Kubectl KCL Plugin

Primary LanguageGoApache License 2.0Apache-2.0

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

Use this as a kubectl plugin.

From Krew Index

Add to krew index and install with:

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

From GitHub Releases

Download the binary from GitHub releases, then copy the kubectl-kcl binary to your PATH. If not, you can also use the binary standalone.

Usage

kubectl kcl run -f ./examples/kcl-run.yaml

Developing

Prerequisites

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

Test

Unit Test

go test ./...

Integration Test

go run main.go run -f ./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("items") and the functionConfig from option("functionConfig").
  • Return a KRM list for output resources.
  • Return an error using assert {condition}, {error_message}.
  • Read the PATH variables. e.g. option("PATH").
  • Read the environment variables. e.g. option("env").

Full documents of KCL can be found here.