fnruntime

package
v0.0.0-...-c7d747a Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FnExecErrorTruncateLines = 4
	// FnExecErrorIndentation is the number of spaces at the beginning of each
	// line of function failure messages.
	FnExecErrorIndentation = 2
)
View Source
const (
	FuncGenPkgContext = "builtins/gen-pkg-context"
)
View Source
const ResourceIDAnnotation = "internal.config.k8s.io/kpt-resource-id"

ResourceIDAnnotation is used to uniquely identify the resource during round trip to and from a function execution. This annotation is meant to be consumed by kpt during round trip and should be deleted after that

View Source
const (
	WasmPathEnv = "KPT_FN_WASM_PATH"
)

Variables

This section is empty.

Functions

func ContainerRuntimeAvailable

func ContainerRuntimeAvailable(runtime ContainerRuntime) error

func DeleteResourceIds

func DeleteResourceIds(input []*yaml.RNode) error

DeleteResourceIds removes the kpt-resource-id annotation from all resources

func IsMatch

func IsMatch(node *yaml.RNode, selector kptfilev1.Selector) bool

IsMatch returns true if the resource matches input selection criteria

func MergeWithInput

func MergeWithInput(output, selectedInput, input []*yaml.RNode) []*yaml.RNode

MergeWithInput merges the transformed output with input resources input: all input resources, selectedInput: selected input resources output: output resources as the result of function on selectedInput resources for input: A,B,C,D; selectedInput: A,B; output: A,E(A transformed, B Deleted, E Added) the result should be A,C,D,E resources are identified by kpt-resource-id annotation

func NewConfigMap

func NewConfigMap(data map[string]string) (*yaml.RNode, error)

func NewContainerEnvFromStringSlice

func NewContainerEnvFromStringSlice(envStr []string) *runtimeutil.ContainerEnv

NewContainerEnvFromStringSlice returns a new ContainerEnv pointer with parsing input envStr. envStr example: ["foo=bar", "baz"] using this instead of runtimeutil.NewContainerEnvFromStringSlice() to avoid default envs LOG_TO_STDERR

func ResolveToImageForCLI

func ResolveToImageForCLI(_ context.Context, image string) (string, error)

ResolveToImageForCLI converts the function short path to the full image url. If the function is Catalog function, it adds "gcr.io/kpt-fn/".e.g. set-namespace:v0.1 --> gcr.io/kpt-fn/set-namespace:v0.1

func SaveResults

func SaveResults(fsys filesys.FileSystem, resultsDir string, fnResults *fnresult.ResultList) (string, error)

SaveResults saves results gathered from running the pipeline at specified dir in the input FileSystem.

func SelectInput

func SelectInput(input []*yaml.RNode, selectors, exclusions []kptfilev1.Selector, _ *SelectionContext) ([]*yaml.RNode, error)

SelectInput returns the selected resources based on criteria in selectors

func SetResourceIds

func SetResourceIds(input []*yaml.RNode) error

SetResourceIds adds kpt-resource-id annotation to each input resource

Types

type ContainerFn

type ContainerFn struct {
	Ctx context.Context

	// Image is the container image to run
	Image string
	// ImagePullPolicy controls the image pulling behavior.
	ImagePullPolicy ImagePullPolicy
	// Container function will be killed after this timeour.
	// The default value is 5 minutes.
	Timeout time.Duration
	Perm    ContainerFnPermission
	// UIDGID is the os User ID and Group ID that will be
	// used to run the container in format userId:groupId.
	// If it's empty, "nobody" will be used.
	UIDGID string
	// StorageMounts are the storage or directories to mount
	// into the container
	StorageMounts []runtimeutil.StorageMount
	// Env is a slice of env string that will be exposed to container
	Env []string
	// FnResult is used to store the information about the result from
	// the function.
	FnResult *fnresult.Result
}

ContainerFn implements a KRMFn which run a containerized KRM function

func (*ContainerFn) Run

func (f *ContainerFn) Run(reader io.Reader, writer io.Writer) error

Run runs the container function using docker runtime. It reads the input from the given reader and writes the output to the provided writer.

type ContainerFnPermission

type ContainerFnPermission struct {
	AllowNetwork bool
	AllowMount   bool
}

ContainerFnPermission contains the permission of container function such as network access.

type ContainerImageError

type ContainerImageError struct {
	Image  string
	Output string
}

ContainerImageError is an error type which will be returned when the container run time cannot verify docker image.

func (*ContainerImageError) Error

func (e *ContainerImageError) Error() string

type ContainerRuntime

type ContainerRuntime string
const (
	ContainerRuntimeEnv = "KPT_FN_RUNTIME"

	Docker  ContainerRuntime = "docker"
	Podman  ContainerRuntime = "podman"
	Nerdctl ContainerRuntime = "nerdctl"
)

func StringToContainerRuntime

func StringToContainerRuntime(v string) (ContainerRuntime, error)

func (ContainerRuntime) GetBin

func (r ContainerRuntime) GetBin() string

type ExecError

type ExecError struct {
	// OriginalErr is the original error returned from function runtime
	OriginalErr error

	// TruncateOutput indicates should error message be truncated
	TruncateOutput bool

	// Stderr is the content written to function stderr
	Stderr string `yaml:"stderr,omitempty"`

	// ExitCode is the exit code returned from function
	ExitCode int `yaml:"exitCode,omitempty"`
}

ExecError implements an error type that stores information about function failure.

func (*ExecError) Error

func (fe *ExecError) Error() string

func (*ExecError) String

func (fe *ExecError) String() string

String returns string representation of the failure.

type ExecFn

type ExecFn struct {
	// Path is the os specific path to the executable
	// file. It can be relative or absolute.
	Path string
	// Args are the arguments to the executable
	Args []string

	Env map[string]string
	// Container function will be killed after this timeour.
	// The default value is 5 minutes.
	Timeout time.Duration
	// FnResult is used to store the information about the result from
	// the function.
	FnResult *fnresult.Result
}

func (*ExecFn) Run

func (f *ExecFn) Run(r io.Reader, w io.Writer) error

Run runs the executable file which reads the input from r and writes the output to w.

type FsLoader

type FsLoader struct {
	Filename string
}

type FunctionRunner

type FunctionRunner struct {
	// contains filtered or unexported fields
}

FunctionRunner wraps FunctionFilter and implements kio.Filter interface.

func NewFunctionRunner

func NewFunctionRunner(ctx context.Context,
	fltr *runtimeutil.FunctionFilter,
	pkgPath types.UniquePath,
	fnResult *fnresult.Result,
	fnResults *fnresult.ResultList,
	opts RunnerOptions) (*FunctionRunner, error)

NewFunctionRunner returns a FunctionRunner given a specification of a function and it's config.

func NewRunner

func NewRunner(
	ctx context.Context,
	fsys filesys.FileSystem,
	f *kptfilev1.Function,
	pkgPath types.UniquePath,
	fnResults *fnresult.ResultList,
	opts RunnerOptions,
	runtime fn.FunctionRuntime,
) (*FunctionRunner, error)

NewRunner returns a FunctionRunner given a specification of a function and it's config.

func (*FunctionRunner) Filter

func (fr *FunctionRunner) Filter(input []*yaml.RNode) (output []*yaml.RNode, err error)

func (*FunctionRunner) SetFnConfig

func (fr *FunctionRunner) SetFnConfig(conf *yaml.RNode)

SetFnConfig updates the functionConfig for the FunctionRunner instance.

type ImagePullPolicy

type ImagePullPolicy string
const (
	AlwaysPull       ImagePullPolicy = "Always"
	IfNotPresentPull ImagePullPolicy = "IfNotPresent"
	NeverPull        ImagePullPolicy = "Never"
)

func (*ImagePullPolicy) AllStrings

func (e *ImagePullPolicy) AllStrings() []string

func (*ImagePullPolicy) HelpAllowedValues

func (e *ImagePullPolicy) HelpAllowedValues() string

HelpAllowedValues builds help text for the allowed values

func (*ImagePullPolicy) Set

func (e *ImagePullPolicy) Set(v string) error

Set implements pflag.Value

func (*ImagePullPolicy) String

func (e *ImagePullPolicy) String() string

String implements pflag.Value and fmt.Stringer

func (*ImagePullPolicy) Type

func (e *ImagePullPolicy) Type() string

Type implements pflag.Value

type ImageResolveFunc

type ImageResolveFunc func(ctx context.Context, image string) (string, error)

ImageResolveFunc is the type for a function that can resolve a partial image to a (more) fully-qualified name

type MultiLineFormatter

type MultiLineFormatter struct {
	// Title under which lines need to be printed
	Title string

	// Lines to be printed on the CLI.
	Lines []string

	// TruncateOuput determines if output needs to be truncated or not.
	TruncateOutput bool

	// MaxLines to be printed if truncation is enabled.
	MaxLines int

	// UseQuote determines if line needs to be quoted or not
	UseQuote bool
}

MultiLineFormatter knows how to format multiple lines in pretty format that can be displayed to an end user.

func (*MultiLineFormatter) String

func (ri *MultiLineFormatter) String() string

String returns multiline string.

type OciLoader

type OciLoader struct {
	// contains filtered or unexported fields
}

func NewOciLoader

func NewOciLoader(cacheDir, image string) *OciLoader

type RunnerOptions

type RunnerOptions struct {
	// ImagePullPolicy controls the image pulling behavior before running the container.
	ImagePullPolicy ImagePullPolicy

	// when set to true, function runner will set the package path annotation
	// on resources that do not have it set. The resources generated by
	// functions do not have this annotation set.
	SetPkgPathAnnotation bool

	DisplayResourceCount bool

	// allowExec determines if function binary executable are allowed
	// to be run during pipeline execution. Running function binaries is a
	// privileged operation, so explicit permission is required.
	AllowExec bool

	// AllowNetwork specifies if container based functions are allowed
	// to access network during pipeline execution. Accessing network is
	// considered a privileged operation (and makes render operation non-hermetic),
	// so explicit permission is desired.
	AllowNetwork bool

	// allowWasm determines if function wasm are allowed to be run during pipeline
	// execution. Running wasm function is an alpha feature, so it needs to be
	// enabled explicitly.
	AllowWasm bool

	// ResolveToImage will resolve a partial image to a fully-qualified one
	ResolveToImage ImageResolveFunc
}

func (*RunnerOptions) InitDefaults

func (o *RunnerOptions) InitDefaults()

type SelectionContext

type SelectionContext struct {
	RootPackagePath types.UniquePath
}

type WasmFn

type WasmFn struct {
	// contains filtered or unexported fields
}

func NewWasmFn

func NewWasmFn(loader WasmLoader) (*WasmFn, error)

func (*WasmFn) Run

func (f *WasmFn) Run(r io.Reader, w io.Writer) error

type WasmLoader

type WasmLoader interface {
	// contains filtered or unexported methods
}

type WasmNodejsFn

type WasmNodejsFn struct {
	NodeJsRunner *ExecFn
	// contains filtered or unexported fields
}

func NewNodejsFn

func NewNodejsFn(loader WasmLoader) (*WasmNodejsFn, error)

func (*WasmNodejsFn) Run

func (f *WasmNodejsFn) Run(r io.Reader, w io.Writer) error

type WasmRuntime

type WasmRuntime string
const (
	Wasmtime WasmRuntime = "wasmtime"
	Nodejs   WasmRuntime = "nodejs"

	WasmRuntimeEnv = "KPT_FN_WASM_RUNTIME"
)

type WasmtimeFn

type WasmtimeFn struct {
	wasmexec.Memory
	*wasmtime.Instance
	// contains filtered or unexported fields
}

func NewWasmtimeFn

func NewWasmtimeFn(loader WasmLoader) (*WasmtimeFn, error)

func (*WasmtimeFn) Error

func (f *WasmtimeFn) Error(format string, params ...interface{})

Error implements the wasmexec.errorLogger interface

func (*WasmtimeFn) GetSP

func (f *WasmtimeFn) GetSP() (uint32, error)

func (*WasmtimeFn) Resume

func (f *WasmtimeFn) Resume() error

func (*WasmtimeFn) Run

func (f *WasmtimeFn) Run(r io.Reader, w io.Writer) error

Run runs the executable file which reads the input from r and writes the output to w.

func (*WasmtimeFn) Write

func (f *WasmtimeFn) Write(fd int, b []byte) (n int, err error)

Write implements the wasmexec.fdWriter interface.

Jump to

Keyboard shortcuts

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