Documentation
¶
Index ¶
- Variables
- func AddCustomInputType[Resource client.Object, Custom any](bind func(Resource) (Custom, error))
- func Main[T Inputs](fn SynthFunc[T], opts ...Option)
- func ReadInput[T client.Object](ir *InputReader, key string, out T) error
- func ReadManifest(path string) ([]client.Object, error)
- type InputReader
- type Inputs
- type MungableInputs
- type MungeFunc
- type Option
- type OutputWriter
- type SynthFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInputNotFound = errors.New("input not found")
var ErrInputReadingFailed = errors.New("input reading failed")
var Scheme = scheme.Scheme
Functions ¶
func AddCustomInputType ¶ added in v0.1.5
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, &mainConfig{}, ir, NewDefaultOutputWriter())
Output: {"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"apiVersion":"v1","kind":"Pod","metadata":{"name":"foobar\n"},"spec":{"containers":null},"status":{}}]}
Example (Map) ¶
type myType struct {
SecretKey string
}
AddCustomInputType(func(in *corev1.Secret) (map[string]*myType, error) {
m := make(map[string]*myType, len(in.Data))
for k, v := range in.Data {
m[k] = &myType{
SecretKey: string(v),
}
}
return m, nil
})
type exampleInputs struct {
CustomInputs map[string]*myType `eno_key:"test-secret"`
}
fn := func(inputs exampleInputs) ([]client.Object, error) {
output := &corev1.Pod{}
output.Name = string(inputs.CustomInputs["key"].SecretKey)
return []client.Object{output}, nil
}
ir := newTestInputReader()
main(fn, &mainConfig{}, ir, NewDefaultOutputWriter())
Output: {"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"apiVersion":"v1","kind":"Pod","metadata":{"name":"foobar\n"},"spec":{"containers":null},"status":{}}]}
Example (Slice) ¶
type myType struct {
SecretKey string
}
AddCustomInputType(func(in *corev1.Secret) ([]*myType, error) {
return []*myType{{
SecretKey: string(in.Data["key"]),
}}, nil
})
type exampleInputs struct {
CustomInputs []*myType `eno_key:"test-secret"`
}
fn := func(inputs exampleInputs) ([]client.Object, error) {
output := &corev1.Pod{}
output.Name = string(inputs.CustomInputs[0].SecretKey)
return []client.Object{output}, nil
}
ir := newTestInputReader()
main(fn, &mainConfig{}, ir, NewDefaultOutputWriter())
Output: {"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"apiVersion":"v1","kind":"Pod","metadata":{"name":"foobar\n"},"spec":{"containers":null},"status":{}}]}
func Main ¶ added in v0.1.4
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":[{"apiVersion":"v1","kind":"Pod","metadata":{"name":"test-pod"},"spec":{"containers":null},"status":{}}]}
Example (WithMungers) ¶
// Example using precreted mungers
fn := func(inputs struct{}) ([]client.Object, error) {
output := &corev1.Pod{}
output.Name = "test-pod"
return []client.Object{output}, nil
}
//stdout of main will be compared with output comment below becausse this is an example
Main(fn, WithManagedByEno(), WithReconcilationInterval(time.Minute))
Output: {"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{"eno.azure.io/reconcile-interval":"1m0s"},"labels":{"app.kubernetes.io/managed-by":"Eno"},"name":"test-pod"},"spec":{"containers":null},"status":{}}]}
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
func (i *InputReader) All() map[string]*unstructured.Unstructured
func (*InputReader) IsOptional ¶ added in v0.2.1
func (ir *InputReader) IsOptional(key string) bool
IsOptional returns true if the input with the given key is marked as optional. This is determined by checking the FunctionConfig.optionalRefs list which contains all optional ref keys from the synthesizer spec.
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, &mainConfig{}, ir, NewDefaultOutputWriter())
Output: {"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"apiVersion":"v1","kind":"Pod","metadata":{"name":"foobar\n"},"spec":{"containers":null},"status":{}}]}
type MungableInputs ¶ added in v0.1.24
type MungableInputs interface {
Munge() error
}
MungableInputs is an optional interface that can be implemented by Inputs structs if it is, it gets called after inputs are read. It can fail the whole Synthesis.
type MungeFunc ¶ added in v0.0.19
type MungeFunc func(*unstructured.Unstructured)
type Option ¶ added in v0.1.22
type Option func(*mainConfig)
option defines an option for configuring/augmenting the Main function.
func WithManagedByEno ¶ added in v0.1.22
func WithManagedByEno() Option
WithManagedByEno returns an iption that annotates the given Kubernetes object to indicate that it is managed by Eno. It sets the "eno.azure.io/managed-by" annotation to the Eno controller identifier.
func WithMunger ¶ added in v0.1.22
WithMunger adds a munge function that will be applied to each output object. Multiple munge functions can be provided and they will be applied in order.
Example usage:
Main(synthesizer,
WithMunger(func(obj *unstructured.Unstructured) {
// Add common labels
labels := obj.GetLabels()
if labels == nil {
labels = make(map[string]string)
}
labels["app.kubernetes.io/managed-by"] = "eno"
obj.SetLabels(labels)
}),
WithMunger(func(obj *unstructured.Unstructured) {
// Add environment-specific annotations
annotations := obj.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
}
annotations["eno.azure.io/reconcile-interval"] = "1m"
obj.SetAnnotations(annotations)
}),
)
func WithReconcilationInterval ¶ added in v0.1.22
WithReconcilationInterval returns an option that annotates the given Kubernetes object to configure its reconciliation interval. It sets the "eno.azure.io/reconcile-interval" annotation to the provided duration string, which controls how frequently Eno will reconcile the resource.
func WithScheme ¶ added in v0.1.31
WithScheme configures the runtime.Scheme used for automatic type metadata inference.
The scheme enables automatic population of TypeMeta (apiVersion and kind) fields for Kubernetes objects based on their Go types. When an object is processed and its GroupVersionKind is empty, the scheme will be consulted to determine the appropriate apiVersion and kind values.
If no scheme is provided, or if an object's type is not registered in the scheme, the object will be processed without modification.
Example usage:
scheme := runtime.NewScheme() corev1.AddToScheme(scheme) appsv1.AddToScheme(scheme) Main(synthesizer, WithScheme(scheme))
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) AddResult ¶ added in v0.1.4
func (w *OutputWriter) AddResult(result *krmv1.Result)
func (*OutputWriter) Write ¶
func (w *OutputWriter) Write() error