kustomize-kcl

command module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Kustomize KCL Function

Go Report Card GoDoc License

This is an example of implementing a KCL function for Kustomize. KCL is a constraint-based record & functional domain language. Full documents of KCL can be found here.

Function Implementation

The function is implemented as an image, and built using make image.

The function is implemented as a go program, which reads a collection of input Resource configuration, passing them to KCL.

Function Configuration

See the API struct definition in main.go for documentation.

  • source - the KCL function code.
  • params - top-level arguments for KCL

Function invocation

The function is invoked by authoring a local Resource with metadata.annotations.[config.kubernetes.io/function] and running:

sudo kustomize fn run examples/set-annotation/local-resource/ --as-current-user --dry-run

This exists non-zero if the KCL code has no errors.

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.
  • Read the environment variables. e.g. option("PATH").
  • Read the OpenAPI schema. e.g. option("open_api")["definitions"]["io.k8s.api.apps.v1.Deployment"]
  • Return an error using assert {condition}, {error_message}.

Library

You can directly use KCL standard libraries without importing them, such as regex.match, math.log.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL