generic

package
v0.11.13 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDisruptionAttributePrefix = "disruption"

DefaultDisruptionAttributePrefix is the attribute-name prefix whose per-severity registrations vet-disruption consults: disruption-critical, disruption-high, disruption-medium, disruption-low.

View Source
const SchemaOtherDataKey = api.OtherDataSource("schema")

SchemaOtherDataKey is the key of the OtherData vet-jsonschema-from-unit reads its schema from.

Variables

View Source
var ErrNoSchema = errors.New("no schema")

ErrNoSchema is what a schema lookup returns, wrapped, for a resource that has to have a schema and has none. The resource fails validation with it, rather than the function failing.

Functions

func CELActivation

func CELActivation(dataMap map[string]any, params map[string]any, functionContext map[string]any) map[string]any

CELActivation builds the activation map for a resource with params and the FunctionContext metadata, which exposes fields such as functionContext.TargetID and functionContext.UnitSlug.

func CELOtherDataVarOpts added in v0.11.11

func CELOtherDataVarOpts() []cel.EnvOption

CELOtherDataVarOpts declares other and otherOrigins, the OtherData a function was passed (OtherResources): other.policies is the list of resources passed under the key policies, and otherOrigins.policies[i] where other.policies[i] came from.

func CELResourcesVarOpts added in v0.11.12

func CELResourcesVarOpts() []cel.EnvOption

CELResourcesVarOpts declares resources, every resource in the data the function was given, so that an expression evaluated on one resource can read the others beside it: the rest of a Unit's resources, or, run by a Release Trigger, everything the Release bundles.

func CELVarOpts

func CELVarOpts() []cel.EnvOption

CELVarOpts returns the standard CEL variable options for r, object, params, and functionContext (the ConfigHub FunctionContext metadata).

func CelParseParams

func CelParseParams(args []api.FunctionArgument, startIndex int) (map[string]any, error)

CelParseParams extracts key=value params from function arguments starting at the given index and returns them as a map[string]any suitable for CEL evaluation.

func CelToGo added in v0.2.8

func CelToGo(val ref.Val) any

CelToGo deeply converts a CEL ref.Val to plain Go types, so that a result can be marshaled or type-switched without dealing in ref.Val. Exported for callers evaluating CEL outside the function executor, such as a server-side View column read from stored JSON.

func CoerceTextToSchemaTypes added in v0.11.12

func CoerceTextToSchemaTypes(value any, schema any) any

CoerceTextToSchemaTypes converts the strings in value, a document decoded from JSON, that schema, a decoded JSON Schema, declares as integers, numbers or booleans and not as strings, to those types, when their text is one. Integers and numbers become json.Numbers. The schemas that apply to a value are found through properties, patternProperties, additionalProperties, items, prefixItems and additionalItems, through allOf, anyOf and oneOf, and through $refs within the schema. value is changed in place, and the result is returned.

func GenericFnDeletePath

func GenericFnDeletePath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, options *api.FunctionOptions) (gaby.Container, any, error)

func GenericFnGetBoolPath

func GenericFnGetBoolPath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, options *api.FunctionOptions) (gaby.Container, any, error)

func GenericFnGetCEL

func GenericFnGetCEL(resourceProvider yamlkit.ResourceProvider, options *api.FunctionOptions, functionContext *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, extraEnvOpts ...cel.EnvOption) (gaby.Container, any, error)

GenericFnGetCEL implements get-cel extraction. Extra CEL env options can be passed by toolchain-specific overrides.

func GenericFnGetHash added in v0.2.30

func GenericFnGetHash(
	resourceProvider yamlkit.ResourceProvider,
	parsedData gaby.Container,
	args []api.FunctionArgument,
	options *api.FunctionOptions,
) (gaby.Container, any, error)

GenericFnGetHash computes a SHA-256 hash of all values at the specified paths for each resource and returns them, one AttributeValue per resource, leaving the data unchanged. The reported Path is the first path hashed, not a path the hash is stored at -- the point of this function is that it is stored nowhere.

func GenericFnGetIntPath

func GenericFnGetIntPath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, options *api.FunctionOptions) (gaby.Container, any, error)

func GenericFnGetPath

func GenericFnGetPath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, options *api.FunctionOptions) (gaby.Container, any, error)

func GenericFnGetStringPath

func GenericFnGetStringPath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, options *api.FunctionOptions) (gaby.Container, any, error)

func GenericFnResourceWhereMatchWithComparators

func GenericFnResourceWhereMatchWithComparators(resourceProvider yamlkit.ResourceProvider, customComparators []api.CustomStringComparator, options *api.FunctionOptions, functionContext *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument) (gaby.Container, any, error)

func GenericFnSelectWhereResourceWithComparators

func GenericFnSelectWhereResourceWithComparators(resourceProvider yamlkit.ResourceProvider, customComparators []api.CustomStringComparator, options *api.FunctionOptions, functionContext *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument) (gaby.Container, any, error)

func GenericFnSetBoolPath

func GenericFnSetBoolPath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, upsert bool, options *api.FunctionOptions) (gaby.Container, any, error)

func GenericFnSetCEL

func GenericFnSetCEL(resourceProvider yamlkit.ResourceProvider, functionContext *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, options *api.FunctionOptions, extraEnvOpts ...cel.EnvOption) (gaby.Container, any, error)

GenericFnSetCEL implements set-cel mutation. The CEL expression returns a partial resource map that is merged into the original resource using strategic merge (similar to Kubernetes ApplyConfiguration). Only the fields present in the CEL result are modified; all other fields are preserved. Extra CEL env options can be passed by toolchain-specific overrides.

func GenericFnSetHash added in v0.1.26

func GenericFnSetHash(
	resourceProvider yamlkit.ResourceProvider,
	parsedData gaby.Container,
	args []api.FunctionArgument,
	options *api.FunctionOptions,
) (gaby.Container, any, error)

GenericFnSetHash computes a SHA-256 hash of all values at the specified paths for each resource and stores the hash at the resource provider's context path for HashKeySuffix.

func GenericFnSetIntPath

func GenericFnSetIntPath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, upsert bool, options *api.FunctionOptions) (gaby.Container, any, error)

func GenericFnSetPath added in v0.1.89

func GenericFnSetPath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, upsert bool, options *api.FunctionOptions) (gaby.Container, any, error)

GenericFnSetPath sets a YAML document value at args[1] (path) for resource type args[0], with args[2] the YAML value. It replaces all fields at the path; with a terminal associative segment it find-or-appends a merge-keyed list element, injecting the merge key into the value when the value omits it. Also used by set-attributes for DataTypeYAML attributes.

func GenericFnSetStringPath

func GenericFnSetStringPath(resourceProvider yamlkit.ResourceProvider, _ *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, upsert bool, options *api.FunctionOptions) (gaby.Container, any, error)

func GenericFnSetTemplate added in v0.1.71

func GenericFnSetTemplate(resourceProvider yamlkit.ResourceProvider, functionContext *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, options *api.FunctionOptions) (gaby.Container, any, error)

GenericFnSetTemplate implements set-template. It parses key=value params from args[2:], renders args[0] as a Go template with FunctionContext + Params in scope, and writes the rendered string to args[1] on every resource matched by WhereResource.

func GenericFnVetCEL

func GenericFnVetCEL(resourceProvider yamlkit.ResourceProvider, options *api.FunctionOptions, functionContext *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument, extraEnvOpts ...cel.EnvOption) (gaby.Container, any, error)

GenericFnVetCEL implements vet-cel validation. Extra CEL env options can be passed by toolchain-specific overrides (e.g., Kubernetes admission policy libraries).

func GenericFnVetCELWithOtherData added in v0.11.11

func GenericFnVetCELWithOtherData(resourceProvider yamlkit.ResourceProvider, options *api.FunctionOptions, functionContext *api.FunctionContext, parsedData gaby.Container, other OtherResources, args []api.FunctionArgument, extraEnvOpts ...cel.EnvOption) (gaby.Container, any, error)

GenericFnVetCELWithOtherData is GenericFnVetCEL with the OtherData the function was passed, which the expression reads as other and otherOrigins.

func GenericFnVetJSONSchema

func GenericFnVetJSONSchema(resourceProvider yamlkit.ResourceProvider, options *api.FunctionOptions, functionContext *api.FunctionContext, parsedData gaby.Container, args []api.FunctionArgument) (gaby.Container, any, error)

func GenericFnVetJSONSchemaFromUnit added in v0.11.0

func GenericFnVetJSONSchemaFromUnit(resourceProvider yamlkit.ResourceProvider, options *api.FunctionOptions,
	functionContext *api.FunctionContext, parsedData, schemaData gaby.Container, ignoreRequired bool) (gaby.Container, any, error)

GenericFnVetJSONSchemaFromUnit validates each resource of parsedData against the JSON Schema schemaData holds, the data of the Unit passed as OtherData schema.

func GenericFnVetMergeKeys

func GenericFnVetMergeKeys(resourceProvider yamlkit.ResourceProvider, options *api.FunctionOptions, parsedData gaby.Container) (gaby.Container, any, error)

GenericFnVetMergeKeys checks for duplicate merge keys across all resources.

func GenericVetDisruption added in v0.1.98

func GenericVetDisruption(
	resourceProvider yamlkit.ResourceProvider,
	parsedData gaby.Container,
	parsedOtherData map[api.OtherDataSource]gaby.Container,
	attributePrefix string,
	threshold api.Score,
	options *api.FunctionOptions,
) (api.ValidationResult, error)

GenericVetDisruption grades the changes between the current data and a baseline revision, by severity tier, and fails when the worst change reaches the threshold.

Two situations look superficially alike and are handled differently on purpose:

  • No baseline at all (parsedOtherData empty). The unit has never been applied. This must pass: with nothing applied there is nothing to disrupt — creating a resource is not replacing one — and failing here would deadlock the unit, since it could never be applied to acquire the baseline that would let it pass.
  • A baseline was supplied, but under a source this function cannot interpret, such as a revision a caller named in other_data_source. That is a misconfiguration, and returning "passed" would credit a validator that never actually ran. It is an error.

func GenericVetImmutable added in v0.1.26

func GenericVetImmutable(
	resourceProvider yamlkit.ResourceProvider,
	parsedData gaby.Container,
	parsedOtherData map[api.OtherDataSource]gaby.Container,
	attributeName api.AttributeName,
	notLive bool,
	options *api.FunctionOptions,
) (api.ValidationResult, error)

GenericVetImmutable validates that immutable fields have not been changed between the current data and the baseline revision data provided via OtherData. It compares values at all paths registered under the specified attribute name.

func GenericVetValues

func GenericVetValues(resourceProvider yamlkit.ResourceProvider, parsedData gaby.Container, attributeName api.AttributeName, filter *api.ValueFilter, options *api.FunctionOptions) (api.ValidationResult, error)

GenericVetValues validates all values at paths registered for the given attribute name against the provided ValueFilter. It is exported so that other functions (e.g. vet-images) can call it.

func LabelSelectorMatches added in v0.11.11

func LabelSelectorMatches(selector any, labelValues any) (bool, error)

LabelSelectorMatches reports whether a Kubernetes label selector selects a set of labels, both as decoded from YAML or JSON: matchLabels and matchExpressions ANDed, read as the API server reads a LabelSelector (metav1.LabelSelectorAsSelector). An empty selector selects everything, and a null one nothing, as for a NetworkPolicy's podSelector and a PodDisruptionBudget's selector respectively. Absent labels are no labels.

func NamespaceLabels added in v0.11.11

func NamespaceLabels(namespaces any, name string) map[string]any

NamespaceLabels returns the labels of the Namespace named name among namespaces, a list of resources as decoded from YAML or JSON, as a namespaceSelector is matched against them: its own, with kubernetes.io/metadata.name, which the API server sets on every Namespace. A Namespace not among them has that label alone.

func NewCELEnv

func NewCELEnv(vars []cel.EnvOption, extraOpts ...cel.EnvOption) (*cel.Env, error)

NewCELEnv creates a CEL environment with the given variables and optional extra options. This provides the base CEL environment used by all generic CEL functions.

func PodLabels added in v0.11.11

func PodLabels(resource any) any

PodLabels returns the labels of the pods a Kubernetes resource, as decoded from YAML or JSON, runs: a workload's pod template's, wherever its kind keeps it (k8skit.PodLabelsPath), such as a CronJob's spec.jobTemplate.spec.template, or a bare Pod's own. A resource that runs pods but labels none has no labels, an empty map; one that runs no pods, such as a Service, returns nil.

func RegisterPathSetterAndGetter

func RegisterPathSetterAndGetter(
	fh handler.FunctionRegistry,
	name string,
	parameters []api.FunctionParameter,
	description string,
	attributeName api.AttributeName,
	resourceProvider yamlkit.ResourceProvider,
	addSetter bool,
	upsert bool,
	defaults bool,
)

func RegisterStandardFunctions

func RegisterStandardFunctions(fh handler.FunctionRegistry, converter configkit.ConfigConverter, resourceProvider yamlkit.ResourceProvider)

func ResourcesOf added in v0.11.12

func ResourcesOf(parsedData gaby.Container) ([]any, error)

ResourcesOf returns every resource in parsedData as a map, for the resources variable, whatever the function's WhereResource selects: a check of the resources it selects reads the others too.

func VetAgainstSchemas added in v0.8.1

func VetAgainstSchemas(resourceProvider yamlkit.ResourceProvider, options *api.FunctionOptions, parsedData gaby.Container,
	metadataPath string, schemaFor func(api.ResourceType) (*gojsonschema.Schema, error)) (gaby.Container, any, error)

VetAgainstSchemas validates each resource against the schema schemaFor returns for its type, and reports every violation as a failed path. schemaFor returns nil for a type it does not validate, and an error wrapping ErrNoSchema for a type that fails for want of one. A metadataPath other than "" names a dotted path, such as an AppConfig Unit's configHub block, that is left out of what is validated.

Types

type OtherResources added in v0.11.11

type OtherResources struct {
	Resources map[string][]any
	Origins   map[string][]any
}

OtherResources is the OtherData a general-purpose function such as vet-cel or vet-starlark was passed, as an expression reads it: by key, the list of resources passed under it, and, at the same positions, where each came from. A key a Trigger's OtherUnitSelections pass holds the resources of the selected Units, possibly none; the origin of each names its Unit and Space (api.OtherDataOrigin, by its JSON field names). An entry read from one Unit or revision has an empty origin for each resource.

func NewOtherResources added in v0.11.11

func NewOtherResources(parsed map[api.OtherDataSource]gaby.Container, origins map[api.OtherDataSource][]api.OtherDataOrigin) (OtherResources, error)

NewOtherResources reads a function's parsed OtherData and the origins of its documents.

func OtherResourcesOf added in v0.11.11

OtherResourcesOf reads the OtherData a function was passed.

Jump to

Keyboard shortcuts

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