UX improvements to kyaml/fn/framework

This commit is contained in:
Phillip Wittrock
2020-05-07 20:22:17 -07:00
parent 3dfc76b769
commit 5bae01fa68
6 changed files with 86 additions and 98 deletions

View File

@@ -6,7 +6,20 @@
//
// Examples
//
// Example function implementation using framework.ResourceList with functionConfig
// Example function implementation using framework.Command with flag input
//
// var value string
// resourceList := &framework.ResourceList{}
// cmd := framework.Command(resourceList, func() error {
// for i := range resourceList.Items {
// // modify the items...
// }
// return nil
// })
// cmd.Flags().StringVar(&value, "value", "", "annotation value")
// if err := cmd.Execute(); err != nil { return err }
//
// Example function implementation using framework.ResourceList with a struct input
//
// type Spec struct {
// Value string `yaml:"value,omitempty"`
@@ -24,23 +37,11 @@
// }
// if err := rl.Write(); err != nil { return err }
//
// Example function implementation using framework.Command with flags
//
// var value string
// cmd := framework.Command(nil, func(items []*yaml.RNode) ([]*yaml.RNode, error) {
// for i := range items {
// // modify the items...
// }
// return items, nil
// })
// cmd.Flags().StringVar(&value, "value", "", "annotation value")
// if err := cmd.Execute(); err != nil { return err }
//
// Architecture
//
// Functions modify a slice of resources (ResourceList.items) which are read as input and written
// Functions modify a slice of resources (ResourceList.Items) which are read as input and written
// as output. The function itself may be configured through a functionConfig
// (ResourceList.functionConfig).
// (ResourceList.FunctionConfig).
//
// Example Function Input:
//
@@ -67,7 +68,7 @@
// # run the function by creating this container and providing this
// # Example as the functionConfig
// config.kubernetes.io/function: |
// image: image/containing/fuction:impl
// image: image/containing/function:impl
// spec:
// value: foo
//
@@ -77,7 +78,7 @@
//
// Functions may also be specified imperatively and run using:
//
// config run DIR/ --image image/containing/fuction:impl -- value=foo
// config run DIR/ --image image/containing/function:impl -- value=foo
//
// When run imperatively, a ConfigMap is generated for the functionConfig, and the command
// arguments are set as ConfigMap data entries.
@@ -91,15 +92,11 @@
//
// Mutator and Generator Functions
//
// Functions may add, delete or modify resources by modifying the items slice.
// When using framework.Command this is done through returning the new items slice.
// When using framework.ResourceList this is done through modifying ResourceList.Items in place.
// Functions may add, delete or modify resources by modifying the ResourceList.Items slice.
//
// Validator Functions
//
// A function may validate resources by providing a Result.
// When using framework.Command this is done through returning a framework.Result as an error.
// WHen using framework.ResourceList this is done through setting ResourceList.Result.
// A function may emit validation results by setting the ResourceList.Result
//
// Configuring Functions
//