context

package
v1.11.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 18 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddJSONObject added in v1.7.0

func AddJSONObject(ctx Interface, data interface{}) error

AddJSONObject merges json data

func AddOldResource added in v1.7.0

func AddOldResource(ctx Interface, dataRaw []byte) error

func AddResource added in v1.7.0

func AddResource(ctx Interface, dataRaw []byte) error

Types

type DeferredLoader added in v1.10.0

type DeferredLoader interface {
	Name() string
	Matches(query string) bool
	HasLoaded() bool
	LoadData() error
}

DeferredLoader wraps a Loader and implements context specific behaviors. A `level` is used to track the checkpoint level at which the loader was created. If the level when loading occurs matches the loader's creation level, the loader is discarded after execution. Otherwise, the loader is retained so that it can be applied to the prior level when the checkpoint is restored or reset.

func NewDeferredLoader added in v1.10.1

func NewDeferredLoader(name string, loader Loader, logger logr.Logger) (DeferredLoader, error)

type DeferredLoaders added in v1.10.1

type DeferredLoaders interface {
	Add(loader DeferredLoader, level int)
	LoadMatching(query string, level int) error
	Reset(removeCheckpoint bool, level int)
}

DeferredLoaders manages a list of DeferredLoader instances

func NewDeferredLoaders added in v1.10.1

func NewDeferredLoaders() DeferredLoaders

type EvalInterface

type EvalInterface interface {
	// Query accepts a JMESPath expression and returns matching data
	Query(query string) (interface{}, error)

	// HasChanged accepts a JMESPath expression and compares matching data in the
	// request.object and request.oldObject context fields. If the data has changed
	// it return `true`. If the data has not changed it returns false. If either
	// request.object or request.oldObject are not found, an error is returned.
	HasChanged(jmespath string) (bool, error)
}

EvalInterface is used to query and inspect context data TODO: move to contextapi to prevent circular dependencies

type Interface

type Interface interface {
	// AddRequest marshals and adds the admission request to the context
	AddRequest(request admissionv1.AdmissionRequest) error

	// AddVariable adds a variable to the context
	AddVariable(key string, value interface{}) error

	// AddContextEntry adds a context entry to the context
	AddContextEntry(name string, dataRaw []byte) error

	// ReplaceContextEntry replaces a context entry to the context
	ReplaceContextEntry(name string, dataRaw []byte) error

	// AddResource merges resource json under request.object
	AddResource(data map[string]interface{}) error

	// AddOldResource merges resource json under request.oldObject
	AddOldResource(data map[string]interface{}) error

	// SetTargetResource merges resource json under target
	SetTargetResource(data map[string]interface{}) error

	// AddOperation merges operation under request.operation
	AddOperation(data string) error

	// AddUserInfo merges userInfo json under kyverno.userInfo
	AddUserInfo(userInfo kyvernov1beta1.RequestInfo) error

	// AddServiceAccount merges ServiceAccount types
	AddServiceAccount(userName string) error

	// AddNamespace merges resource json under request.namespace
	AddNamespace(namespace string) error

	// AddElement adds element info to the context
	AddElement(data interface{}, index, nesting int) error

	// AddImageInfo adds image info to the context
	AddImageInfo(info apiutils.ImageInfo, cfg config.Configuration) error

	// AddImageInfos adds image infos to the context
	AddImageInfos(resource *unstructured.Unstructured, cfg config.Configuration) error

	// AddDeferredLoader adds a loader that is executed on first use (query)
	// If deferred loading is disabled the loader is immediately executed.
	AddDeferredLoader(loader DeferredLoader) error

	// ImageInfo returns image infos present in the context
	ImageInfo() map[string]map[string]apiutils.ImageInfo

	// GenerateCustomImageInfo returns image infos as defined by a custom image extraction config
	// and updates the context
	GenerateCustomImageInfo(resource *unstructured.Unstructured, imageExtractorConfigs kyvernov1.ImageExtractorConfigs, cfg config.Configuration) (map[string]map[string]apiutils.ImageInfo, error)

	// Checkpoint creates a copy of the current internal state and pushes it into a stack of stored states.
	Checkpoint()

	// Restore sets the internal state to the last checkpoint, and removes the checkpoint.
	Restore()

	// Reset sets the internal state to the last checkpoint, but does not remove the checkpoint.
	Reset()

	EvalInterface
	// contains filtered or unexported methods
}

Interface to manage context operations TODO: move to contextapi to prevent circular dependencies

func NewContext

func NewContext(jp jmespath.Interface) Interface

NewContext returns a new context

func NewContextFromRaw added in v1.7.0

func NewContextFromRaw(jp jmespath.Interface, raw []byte) Interface

NewContextFromRaw returns a new context initialized with raw data

type InvalidVariableError added in v1.8.0

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

InvalidVariableError represents error for non-white-listed variables

func (InvalidVariableError) Error added in v1.8.0

func (i InvalidVariableError) Error() string

type LeveledLoader added in v1.10.1

type LeveledLoader interface {
	// Level provides the declaration level for the DeferredLoader
	Level() int
	DeferredLoader
}

LeveledLoader is a DeferredLoader with a Level

type Loader added in v1.10.1

type Loader interface {
	// Load data fetches or produces data and stores it in the context
	LoadData() error
	// Has loaded indicates if the loader has previously
	// executed and stored data in a context
	HasLoaded() bool
}

Loader fetches or produces data and loads it into the context. A loader is created for each context entry (e.g. `context.variable`, `context.apiCall`, etc.) Loaders are invoked lazily based on variable lookups. Loaders may be invoked multiple times to handle checkpoints and restores that occur when processing loops. A loader that fetches remote data should be able to handle multiple invocations in an optimal manner by mantaining internal state and caching remote data. For example, if an API call is made the data retrieved can be stored so that it can be saved in the outer context when a restore is performed.

type MockContext added in v1.5.2

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

MockContext is used for testing and validation of variables

func NewMockContext added in v1.5.2

func NewMockContext(re *regexp.Regexp, vars ...string) *MockContext

NewMockContext creates a new MockContext that allows variables matching the supplied list of wildcard patterns

func (*MockContext) AddVariable added in v1.5.2

func (ctx *MockContext) AddVariable(wildcardPattern string)

AddVariable adds given wildcardPattern to the allowed variable patterns

func (*MockContext) HasChanged added in v1.5.2

func (ctx *MockContext) HasChanged(_ string) (bool, error)

func (*MockContext) Query added in v1.5.2

func (ctx *MockContext) Query(query string) (interface{}, error)

Query the JSON context with JMESPATH search path

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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