fn

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsMain

func AsMain(input interface{}) error

AsMain evaluates the ResourceContext from STDIN to STDOUT. `input` can be - a `ResourceContextProcessor` which implements `Process` method - a function `Runner` which implements `Run` method

func GVKToString added in v0.0.6

func GVKToString(gvk *schema.GroupVersionKind) string

func GetGVKString added in v0.0.6

func GetGVKString(o Object) string

func Log

func Log(in ...interface{})

func Logf

func Logf(format string, in ...interface{})

func Run

func Run(p ResourceContextProcessor, in []byte) ([]byte, error)

Run evaluates the function. input must be a resourceContext in json format. An updated resourceContext will be returned.

func StringToGVK added in v0.0.6

func StringToGVK(s string) *schema.GroupVersionKind

Types

type ByteReadWriter

type ByteReadWriter struct {
	// Reader is where ResourceContext are decoded from.
	Reader io.Reader

	// Writer is where ResourceContext are encoded.
	Writer io.Writer
}

func (*ByteReadWriter) Read

func (rw *ByteReadWriter) Read() (*ResourceContext, error)

type Context added in v0.0.5

type Context struct {
	context.Context
}

type Object added in v0.0.7

type Object interface {
	metav1.Object
	runtime.Object
}

An Object is a Kubernetes object.

type ResourceContext added in v0.0.5

type ResourceContext struct {
	// fnconfig provides additional configuration for the function
	FunctionConfig map[string]runtime.RawExtension `json:"functionConfig,omitempty" yaml:"functionConfig,omitempty"`
	// Resources contain the resource on which this function operates
	Resources *Resources `json:"resources,omitempty" yaml:"resources,omitempty"`
	// results provide a structured
	Results *Results `json:"results,omitempty" yaml:"results,omitempty"`
}

func ParseResourceContext

func ParseResourceContext(input []byte) (*ResourceContext, error)

type ResourceContextProcessor

type ResourceContextProcessor interface {
	Process(fnCtx *ResourceContext) (bool, error)
}

ResourceContextProcessor is implemented by configuration functions built with this framework

func WithContext added in v0.0.5

func WithContext(ctx context.Context, runner Runner) ResourceContextProcessor

type ResourceContextProcessorFunc

type ResourceContextProcessorFunc func(fnCtx *ResourceContext) (bool, error)

ResourceContextProcessorFunc converts a compatible function to a ResourceContextProcessor.

func (ResourceContextProcessorFunc) Process

type ResourceRef added in v0.0.5

type ResourceRef struct {
	APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
	Kind       string `json:"kind,omitempty" yaml:"kind,omitempty"`
	Name       string `json:"name,omitempty" yaml:"name,omitempty"`
	Namespace  string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
}

ResourceRef fills the ResourceRef field in Results

type Resources added in v0.0.5

type Resources struct {
	// holds the input KRM resources with the key being GVK in string format
	Input map[string][]runtime.RawExtension `json:"input,omitempty" yaml:"input,omitempty"`
	// holds the output KRM resources with the key being GVK in string format
	Output map[string][]runtime.RawExtension `json:"output,omitempty" yaml:"output,omitempty"`
	// holds the conditional KRM resources with the key being GVK in string format
	Conditions map[string][]runtime.RawExtension `json:"conditions,omitempty" yaml:"conditions,omitempty"`
}

func (*Resources) AddCondition added in v0.0.6

func (r *Resources) AddCondition(o Object) error

func (*Resources) AddIntput added in v0.0.10

func (r *Resources) AddIntput(o Object) error

func (*Resources) AddOutput added in v0.0.6

func (r *Resources) AddOutput(o Object) error

func (*Resources) AddUniqueCondition added in v0.0.10

func (r *Resources) AddUniqueCondition(o Object) error

func (*Resources) AddUniqueIntput added in v0.0.10

func (r *Resources) AddUniqueIntput(o Object) error

func (*Resources) AddUniqueOutput added in v0.0.10

func (r *Resources) AddUniqueOutput(o Object) error

type Result added in v0.0.5

type Result struct {
	// Message is a human readable message. This field is required.
	Message string `json:"message,omitempty" yaml:"message,omitempty"`

	// Severity is the severity of this result
	Severity Severity `yaml:"severity,omitempty" json:"severity,omitempty"`

	// ResourceRef is a reference to a resource.
	// Required fields: apiVersion, kind, name.
	ResourceRef *ResourceRef `json:"resourceRef,omitempty" yaml:"resourceRef,omitempty"`
}

Result defines a result for the fucntion execution

type Results added in v0.0.5

type Results []*Result

func (*Results) ErrorE added in v0.0.5

func (r *Results) ErrorE(err error)

func (*Results) Errorf added in v0.0.5

func (r *Results) Errorf(format string, a ...any)

func (*Results) Infof added in v0.0.5

func (r *Results) Infof(format string, a ...any)

Infof writes an Info level `result` to the results slice. It accepts arguments according to a format specifier.

type Runner

type Runner interface {
	// Run provides the entrypoint to allow you to process the resources. any crud operation
	// Args:
	//    fnConfig: the configuration parameters of the function
	//    resources: The KRM resources.
	//    results: You can use `ErrorE` `Errorf` `Infof` to add user message to `Results`.
	// Returns:
	//    return a boolean to tell whether the execution should be considered as PASS or FAIL.
	Run(context *Context, fnConfig map[string]runtime.RawExtension, resources *Resources, results *Results) bool
}

type Severity added in v0.0.5

type Severity string

Severity indicates the severity of the Result

const (
	// Error indicates the result is an error.  Will cause the function to exit non-0.
	Error Severity = "error"
	// Info indicates the result is an informative message
	Info Severity = "info"
)

Jump to

Keyboard shortcuts

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