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 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, ir, NewDefaultOutputWriter())
Output: {"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"apiVersion":"v1","kind":"Pod","metadata":{"creationTimestamp":null,"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, ir, NewDefaultOutputWriter())
Output: {"apiVersion":"config.kubernetes.io/v1","kind":"ResourceList","items":[{"apiVersion":"v1","kind":"Pod","metadata":{"creationTimestamp":null,"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":{"creationTimestamp":null,"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"},"creationTimestamp":null,"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
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":[{"apiVersion":"v1","kind":"Pod","metadata":{"creationTimestamp":null,"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.
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