fnruntime

package
v0.0.0-...-f5227cc Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: Apache-2.0 Imports: 23 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
)

Variables

This section is empty.

Functions

func ContainerRuntimeAvailable

func ContainerRuntimeAvailable(runtime ContainerRuntime) 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(ctx 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 "docker.io/yndd".e.g. set-topology:v0.1 --> docker.io/yndd/set-topology:v0.1

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 fnlib.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 *fnresultv1alpha1.Result
}

ContainerFn implements a KRMFn which run a containerized KRM function

func (*ContainerFn) FnRun

func (f *ContainerFn) FnRun(ctx context.Context, 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.

func (*ContainerFn) SvcRun

func (f *ContainerFn) SvcRun(ctx context.Context) 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

ContainerRuntime is the type of container runtime

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 *fnresultv1alpha1.Result
}

func (*ExecFn) FnRun

func (f *ExecFn) FnRun(ctx context.Context, 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 (*ExecFn) SvcRun

func (f *ExecFn) SvcRun(ctx context.Context) error

type FunctionKind

type FunctionKind string
const (
	FuntionKindFunction FunctionKind = "function"
	FunctionKindService FunctionKind = "service"
)

type FunctionRunner

type FunctionRunner interface {
	FnRun(ctx context.Context, reader io.Reader, writer io.Writer) error
	SvcRun(ctx context.Context) error
}

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 Runner

type Runner interface {
	Run(ctx context.Context, rCtx *fn.ResourceContext) (*fn.ResourceContext, error)
}

func NewRunner

func NewRunner(
	ctx context.Context,
	fnc ctrlcfgv1alpha1.Function,
	opts RunnerOptions,
) (Runner, error)

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

type RunnerOptions

type RunnerOptions struct {
	Kind FunctionKind

	// only used for kind =service, exposes the port used by the service in the container
	ServicePort int

	// ImagePullPolicy controls the image pulling behavior before running the container.
	ImagePullPolicy fnlib.ImagePullPolicy

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

	// allowWasm determines if function wasm are allowed to be run during
	// 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()

Jump to

Keyboard shortcuts

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