fn

package
v0.0.0-...-884335b Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Group = "fnctrlr.lcnc.io"

	ConditionedResourceKey = Group + "/" + "conditioned"
	InternalResourceKey    = Group + "/" + "internal"
)

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

func GVKToString(gvk *schema.GroupVersionKind) string

func GetGVKString

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

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

type Context struct {
	context.Context
}

type Object

type Object interface {
	metav1.Object
	runtime.Object
}

An Object is a Kubernetes object.

type ResourceContext

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 map[string][]runtime.RawExtension `json:"resources" yaml:"resources"`
	// 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

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 ResourceParameters

type ResourceParameters struct {
	Conditioned bool
	Internal    bool
}

type ResourceRef

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

type Resources struct {
	Resources map[string][]runtime.RawExtension `json:"resources" yaml:"resources"`
}

func (*Resources) AddResource

func (r *Resources) AddResource(o Object, p *ResourceParameters) error

type Result

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

type Results []*Result

func (*Results) ErrorE

func (r *Results) ErrorE(err error)

func (*Results) Errorf

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

func (*Results) Infof

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

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