function

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 10 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCustomInputType added in v0.1.5

func AddCustomInputType[Resource client.Object, Custom any](bind func(Resource) (Custom, error))

AddCustomInputType allows types that do not implement client.Object to be used as fields of Inputs structs.

Example
type myType struct {
	SecretKey string
}

AddCustomInputType(func(in *corev1.Secret) (*myType, error) {
	return &myType{
		SecretKey: string(in.Data["key"]),
	}, nil
})

type exampleInputs struct {
	CustomInput *myType `eno_key:"test-secret"`
}

fn := func(inputs exampleInputs) ([]client.Object, error) {
	output := &corev1.Pod{}
	output.Name = string(inputs.CustomInput.SecretKey)
	return []client.Object{output}, nil
}

ir := newTestInputReader()
main(fn, ir, NewDefaultOutputWriter())
Output:
{"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"metadata":{"creationTimestamp":null,"name":"foobar\n"},"spec":{"containers":null},"status":{}}]}

func Main added in v0.1.4

func Main[T Inputs](fn SynthFunc[T])

Main is the entrypoint for Eno synthesizer processes written using the framework defined by this package.

Example
fn := func(inputs struct{}) ([]client.Object, error) {
	output := &corev1.Pod{}
	output.Name = "test-pod"
	return []client.Object{output}, nil
}

Main(fn)
Output:
{"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"metadata":{"creationTimestamp":null,"name":"test-pod"},"spec":{"containers":null},"status":{}}]}

func ReadInput

func ReadInput[T client.Object](ir *InputReader, key string, out T) error

Types

type InputReader

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

func NewDefaultInputReader

func NewDefaultInputReader() (*InputReader, error)

func NewInputReader

func NewInputReader(r io.Reader) (*InputReader, error)

func (*InputReader) All added in v0.0.15

type Inputs added in v0.1.4

type Inputs interface{}

Inputs is satisfied by any struct that defines the inputs required by a SynthFunc. Use the `eno_key` struct tag to specify the corresponding ref key for each input. Each field must either be a client.Object or a custom type registered with AddCustomInputType.

Example
type exampleInputs struct {
	MySecret *corev1.Secret `eno_key:"test-secret"`
}

fn := func(inputs exampleInputs) ([]client.Object, error) {
	output := &corev1.Pod{}
	output.Name = string(inputs.MySecret.Data["key"])
	return []client.Object{output}, nil
}

ir := newTestInputReader()
main(fn, ir, NewDefaultOutputWriter())
Output:
{"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"metadata":{"creationTimestamp":null,"name":"foobar\n"},"spec":{"containers":null},"status":{}}]}

type MungeFunc added in v0.0.19

type MungeFunc func(*unstructured.Unstructured)

type OutputWriter

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

func NewDefaultOutputWriter

func NewDefaultOutputWriter() *OutputWriter

func NewOutputWriter

func NewOutputWriter(w io.Writer, munge MungeFunc) *OutputWriter

func (*OutputWriter) Add

func (w *OutputWriter) Add(outs ...client.Object) error

func (*OutputWriter) AddResult added in v0.1.4

func (w *OutputWriter) AddResult(result *krmv1.Result)

func (*OutputWriter) Write

func (w *OutputWriter) Write() error

type SynthFunc added in v0.1.4

type SynthFunc[T Inputs] func(inputs T) ([]client.Object, error)

SynthFunc defines a synthesizer function that takes a set of inputs and returns a list of objects.

Jump to

Keyboard shortcuts

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