Skip to content

fossabot/kubectl-kcl

 
 

Repository files navigation

Kubectl KCL Plugin

Go Report Card GoDoc License FOSSA Status

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/kubectl-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.21+
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("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.

License

FOSSA Status

About

Kubectl KCL Plugin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 76.1%
  • Makefile 15.3%
  • Shell 8.6%