Documentation
¶
Overview ¶
Package runneroptions holds options for the function runtime.
Index ¶
- Constants
- func ContextError(ctx context.Context, err error, stderr func() string, truncateOutput bool) error
- func DefaultImagePrefix() string
- func WithFnTimeout(parent context.Context, timeout, defaultTimeout time.Duration) (context.Context, context.CancelFunc)
- func WithRunTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- type ConditionEvaluator
- type ImagePullPolicy
- type LogOptions
- type PackageIDType
- type RunnerOptions
Constants ¶
const ( FuncGenPkgContext = "builtins/gen-pkg-context" GHCRImagePrefix = "ghcr.io/kptdev/krm-functions-catalog" PrefixEnvVar = "KPT_IMAGE_PREFIX" )
const TimeoutExitCode = -1
TimeoutExitCode is the exit code reported for a function that timed out. It is the exit code of a process that was killed by a signal.
Variables ¶
This section is empty.
Functions ¶
func ContextError ¶
ContextError returns the error for a function whose ctx has ended, or nil if ctx has not ended. err is the error from running the function, which is nil if only a child process of the function was killed. stderr is called only if ctx has ended. truncateOutput is copied to the returned ExecError.
func DefaultImagePrefix ¶
func DefaultImagePrefix() string
DefaultImagePrefix returns the image prefix from the KPT_IMAGE_PREFIX env var, or GHCRImagePrefix if unset.
func WithFnTimeout ¶
func WithFnTimeout(parent context.Context, timeout, defaultTimeout time.Duration) (context.Context, context.CancelFunc)
WithFnTimeout returns the context that a single function is run with. The function is limited by timeout. When timeout is zero, the function is limited by the time limit of the whole run if parent has one, and by defaultTimeout otherwise.
func WithRunTimeout ¶
func WithRunTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
WithRunTimeout returns a copy of ctx that ends when timeout has passed. The functions that are run with the returned context share this time limit, so it limits the whole run and not each function. When timeout is zero, ctx is returned as it is.
Types ¶
type ConditionEvaluator ¶
type ConditionEvaluator interface {
EvaluateCondition(ctx context.Context, celCond string, resources []*yaml.RNode, checkFrequency uint, costLimit uint64) (bool, error)
}
ConditionEvaluator evaluates a function celCondition against the current resource list.
type ImagePullPolicy ¶
type ImagePullPolicy string
const ( AlwaysPull ImagePullPolicy = "Always" IfNotPresentPull ImagePullPolicy = "IfNotPresent" NeverPull ImagePullPolicy = "Never" )
type LogOptions ¶
type LogOptions struct {
PkgNameFormat string
PkgNameSep string
PkgNameID PackageIDType
// TruncateImageName determines whether the full image name or just the base
// name and the tag will be logged.
TruncateImageName bool
// ResultSeparator is used to join the per-item lines of a function's
// structured [Results] output. Defaults to "\n" (multi-line) when empty.
// Embedding applications (e.g. Porch) can set this to "; " to keep the
// result output on a single line for log-friendliness.
ResultSeparator string
}
func DefaultLogOptions ¶
func DefaultLogOptions() LogOptions
func (*LogOptions) FillDefaults ¶
func (o *LogOptions) FillDefaults()
func (*LogOptions) IsZero ¶
func (o *LogOptions) IsZero() bool
type PackageIDType ¶
type PackageIDType int8
const ( // Use directory name to identify the package/subpackage DirName PackageIDType = iota // Use Kptfile metadata.name to identify the package/subpackage KptfileMeta )
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
// ImagePrefix determines the prefix ResolveToImage will use when resolving a
// partial image reference to a fully qualified image reference
ImagePrefix string
LogOptions LogOptions
// FullDisplayName is the resolved display name of the package or subpackage.
// Meant for internal usage, like the render executor.
FullDisplayName string
// CELEnvironment evaluates function conditions. It is nil until
// InitCELEnvironment in the root module has been called successfully.
// Assign only a non-nil implementation: a typed nil stored in this
// interface is not a nil interface.
CELEnvironment ConditionEvaluator
// CelCheckFrequency is the number of CEL evaluation steps before an interruption is checked.
CelCheckFrequency uint
// CelCostLimit is the maximum cost of a CEL evaluation.
CelCostLimit uint64
ExtraTlsCerts [][]byte
// Timeout is the maximum time the whole run is allowed to take: all the
// functions of the pipeline for `kpt fn render`, and the function for
// `kpt fn eval`. A container or exec function that is still running when
// it has passed is killed. When it is zero, there is no limit for the
// whole run, and each function is limited by the default timeout of the
// function runtime (5 minutes).
Timeout time.Duration
}
func (*RunnerOptions) InitDefaults ¶
func (opts *RunnerOptions) InitDefaults(defaultImagePrefix string)
func (*RunnerOptions) ResolveToImage ¶
func (opts *RunnerOptions) ResolveToImage(image string) string
ResolveToImage converts the KRM function short path to the full image url. If the function is a catalog function, it prepends `prefix`, e.g. "set-namespace:v0.1" --> prefix + "set-namespace:v0.1". A "/" is appended to `prefix` if it is not an empty string and does not end with a "/".
func (*RunnerOptions) ValidatePrefix ¶
func (opts *RunnerOptions) ValidatePrefix() error
ValidatePrefix checks that ImagePrefix is a valid registry path.
func (*RunnerOptions) ValidateTimeout ¶
func (opts *RunnerOptions) ValidateTimeout() error
ValidateTimeout checks that Timeout is not negative.