inventory

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagKey       = "crossplane"
	TagSeparator = ":"

	TagTypeInput             = "input"
	TagTypeRequired          = "required"
	TagTypeObservedComposite = "observed-composite"
	TagTypeObservedComposed  = "observed-composed"
	TagTypeDesiredComposite  = "desired-composite"
	TagTypeDesiredComposed   = "desired-composed"
)

Variables

This section is empty.

Functions

func BuildFromRequest

func BuildFromRequest(req *fnv1.RunFunctionRequest, log logging.Logger, targets ...any) error

BuildFromRequest converts a given requests data to the inventory.

func BuildGracefulFromRequest

func BuildGracefulFromRequest(
	req *fnv1.RunFunctionRequest,
	log logging.Logger,
	targets ...any,
) (conversionIssues []string, err error)

BuildGracefulFromRequest converts a given requests data to the inventory.

func ConvertToResponse

func ConvertToResponse(rsp *fnv1.RunFunctionResponse, sources ...any) error

ConvertToResponse is a wrapper that extracts desired state and sets the response.

func CountResources

func CountResources(inventory ResourcesMap, resourceKey string) int

CountResources returns the number of resources stored in the inventory for the given key. If the key is not found in the inventory, it returns 0.

func ExtractDesiredState

func ExtractDesiredState(
	sources ...any,
) (*resource.Composite, map[resource.Name]*resource.DesiredComposed, error)

ExtractDesiredState extracts composite and composed resources from sources using reflection.

func FindConflictingPrefix

func FindConflictingPrefix[T any](m map[string]T, prefix string) string

FindConflictingPrefix reports whether the provided prefix matches any key in the mapping-by-prefix relationship (in either direction). It returns (ok, matchedKey).

func GetResource

func GetResource[T runtime.Object](
	inventory ResourceMap,
	resourceKey string,
) (T, fnv1.Ready, map[string][]byte, bool)

GetResource retrieves a resource with a given key of type T from the inventory map.

func GetResourceMap

func GetResourceMap[T runtime.Object](
	inventory ResourceMap,
	objectKey string,
) (map[string]T, map[string]fnv1.Ready, map[string]map[string][]byte, bool)

GetResourceMap retrieves a resource of type T from the inventory map.

func GetResources

func GetResources[T runtime.Object](
	inventory ResourcesMap,
	resourceKey string,
) ([]T, []fnv1.Ready, []map[string]byte, bool)

GetResources retrieves resources of type []T from the inventory map.

func GetTyped

func GetTyped[T runtime.Object](c runtime.Object) (T, bool)

func HasResource

func HasResource(inventory ResourceMap, resourceKey string) bool

HasResource checks whether the inventory has resource of the given key.

func Inject

func Inject(inv Reader, targets ...any) error

Inject sets the values in the target struct fields based on tags and inventory data. It processes fields with "crossplane" tags and injects corresponding values from the inventory.

Types

type ConnectionDetails

type ConnectionDetails = map[string][]byte

type Mapping

type Mapping map[string]MappingFunc

type MappingFunc

type MappingFunc = func() (runtime.Object, error)

type MappingType

type MappingType map[string]reflect.Type

MappingType is a mapping of resource names to their types.

type Option

type Option func(*builder) error

Option is a functional option for configuring BuildInventory.

func BuildInventoryOptions

func BuildInventoryOptions(targets ...any) ([]Option, error)

func WithComposite

func WithComposite(m MappingFunc) Option

WithComposite sets the composite (XRD) mapping function.

func WithInput

func WithInput(m MappingFunc) Option

WithInput sets the input mapping function.

func WithMapping

func WithMapping(m Mapping) Option

WithMapping sets the resource mappings.

type Reader

type Reader interface {
	// GetDesiredComposite returns the desired composite resource
	GetDesiredComposite() *Resource

	// GetObservedComposite returns the observed composite resource
	GetObservedComposite() *Resource

	// GetDesiredComposed returns the map of desired composed resources
	GetDesiredComposed() ResourceMap

	// GetObservedComposed returns the map of observed composed resources
	GetObservedComposed() ResourceMap

	// GetRequirements returns the map of extra resources
	GetRequirements() ResourcesMap
	// GetInput returns the input
	GetInput() runtime.Object
}

Reader provides read access to inventory data.

func BuildGracefulInventory

func BuildGracefulInventory(
	log logging.Logger,
	req *fnv1.RunFunctionRequest,
	gracefulConversion bool,
	opts ...Option,
) (r Reader, conversionIssues []string, err error)

func BuildInventory

func BuildInventory(
	log logging.Logger,
	req *fnv1.RunFunctionRequest,
	opts ...Option,
) (Reader, error)

type Resource

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

func (*Resource) Connection

func (r *Resource) Connection() ConnectionDetails

func (*Resource) Ready

func (r *Resource) Ready() fnv1.Ready

func (*Resource) RuntimeObject

func (r *Resource) RuntimeObject() runtime.Object

type ResourceMap

type ResourceMap = map[string]*Resource

type Resources

type Resources []*Resource

type ResourcesMap

type ResourcesMap map[string]Resources

type TypeRegistry

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

TypeRegistry manages type validation and storage for different field categories.

Jump to

Keyboard shortcuts

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