starlark

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: Apache-2.0 Imports: 34 Imported by: 1

Documentation

Overview

Package starlark contains a kio.Filter which can be applied to resources to transform them through starlark program.

Starlark has become a popular runtime embedding in go programs, especially for Kubernetes and data processing. Examples: https://github.com/cruise-automation/isopod, https://qri.io/docs/starlark/starlib, https://github.com/stripe/skycfg, https://github.com/k14s/ytt

The resources are provided to the starlark program through the global variable "resourceList". "resourceList" is a dictionary containing an "items" field with a list of resources. The starlark modified "resourceList" is the Filter output.

After being run through the starlark program, the filter will copy the comments from the input resources to restore them -- due to them being dropped as a result of serializing the resources as starlark values.

"resourceList" may also contain a "functionConfig" entry to configure the starlark script itself. Changes made by the starlark program to the "functionConfig" will be reflected in the Filter.FunctionConfig value.

The Filter will also format the output so that output has the preferred field ordering rather than an alphabetical field ordering.

The resourceList variable adheres to the kustomize function spec as specified by: https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/functions-spec.md

All items in the resourceList are resources represented as starlark dictionaries/ The items in the resourceList respect the io spec specified by: https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/config-io.md

The starlark language spec can be found here: https://github.com/google/starlark-go/blob/master/doc/spec.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnwrapResources

func UnwrapResources(in *yaml.RNode) ([]*yaml.RNode, *yaml.RNode, error)

UnwrapResources unwraps the resources and the functionConfig from a resourceList

func WrapResources

func WrapResources(nodes []*yaml.RNode, fc *yaml.RNode) (*yaml.RNode, error)

WrapResources wraps resources and an optional functionConfig in a resourceList

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

type Filter

type Filter struct {
	Name string

	// Program is a starlark script which will be run against the resources
	Program string

	// URL is the url of a starlark program to fetch and run
	URL string

	// Path is the path to a starlark program to read and run
	Path string

	runtimeutil.FunctionFilter
}

Filter transforms a set of resources through the provided program

func (*Filter) Filter

func (sf *Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error)

func (*Filter) Run

func (sf *Filter) Run(reader io.Reader, writer io.Writer) error

func (*Filter) String

func (sf *Filter) String() string

type LazyInitializationOpenapi added in v0.4.1

type LazyInitializationOpenapi struct {
	// contains filtered or unexported fields
}

func (*LazyInitializationOpenapi) Freeze added in v0.4.1

func (v *LazyInitializationOpenapi) Freeze()

func (*LazyInitializationOpenapi) Get added in v0.4.1

func (*LazyInitializationOpenapi) Hash added in v0.4.1

func (v *LazyInitializationOpenapi) Hash() (uint32, error)

func (*LazyInitializationOpenapi) String added in v0.4.1

func (v *LazyInitializationOpenapi) String() string

func (*LazyInitializationOpenapi) Truth added in v0.4.1

func (*LazyInitializationOpenapi) Type added in v0.4.1

type SimpleFilter

type SimpleFilter struct {
	// Name of the starlark program
	Name string
	// Program is a starlark script which will be run against the resources
	Program string
	// FunctionConfig is the functionConfig for the function.
	FunctionConfig *yaml.RNode
}

SimpleFilter transforms a set of resources through the provided starlark program. It doesn't touch the id annotation. It doesn't copy comments.

func (*SimpleFilter) Filter

func (sf *SimpleFilter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error)

func (*SimpleFilter) String

func (sf *SimpleFilter) String() string

Jump to

Keyboard shortcuts

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