composite

package
v0.0.0-...-d4612c9 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func To

func To(resource any, jsonObject any) (err error)

To is a helper function that converts any object to any object by sending it round-robin through `json.Marshal`

func ToUnstructured

func ToUnstructured(apiVersion, kind, object any) (u *unstructured.Unstructured, err error)

ToUnstructured is a helper function that creates an unstructured object from any object that contains metadata, spec and optionally status.

func ToUnstructuredKubernetesObject

func ToUnstructuredKubernetesObject(mr any, providerConfigRef, deletionPolicy string) (o *unstructured.Unstructured, err error)

ToUnstructuredKubernetesObject is a helper function that wraps a given CR resource in a `crossplane-contrib/provider-kubernetes.Object` structure and returns this as an unstructured.Unstructured object

mr any The managed resource to wrap providerConfigRef string

Types

type Composition

type Composition struct {
	// ObservedComposite is an object that reflects the composite resource that
	//is created from the claim
	ObservedComposite any

	// DesiredComposite is the raw composite resource we want creating
	DesiredComposite *resource.Composite

	// ObservedComposed is a set of resources that are composed by the composite
	// and exist in the cluster
	ObservedComposed map[resource.Name]resource.ObservedComposed

	// DesiredComposed is the set of resources we require to be created
	DesiredComposed map[resource.Name]*resource.DesiredComposed

	// Input is the information brought in from the function binding
	Input InputProvider
}

Composition contains the main request objects required for interacting with composition function resources.

func New

func New(req *fnv1beta1.RunFunctionRequest, input InputProvider, composite any) (c *Composition, err error)

New takes a RunFunctionRequest object and converts it to a Composition

This method should be called at the top of your RunFunction.

Example:

func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequest) (rsp *fnv1beta1.RunFunctionResponse, err error) {
	f.log.Info("Running Function", composedName, req.GetMeta().GetTag())
	rsp = response.To(req, response.DefaultTTL)

	input := v1beta1.Input{}
	if composed, err = composite.New(req, &input, &composite); err != nil {
		response.Fatal(rsp, errors.Wrap(err, "error setting up function "+composedName))
		return rsp, nil
	}

	...
	// Function body
	...

	if err = f.composed.ToResponse(rsp); err != nil {
		response.Fatal(rsp, errors.Wrapf(err, "cannot convert composition to response %T", rsp))
		return
	}

	response.Normal(rsp, "Successful run")
	return rsp, nil
}

func (*Composition) AddDesired

func (c *Composition) AddDesired(n string, u *unstructured.Unstructured) (err error)

AddDesired takes an unstructured object and adds it to the desired composed resources

If the object exists on the stack already, we do a deepEqual to see if the object has changed and if not, this method won't do anything.

  • `n` The name of the composite resource to add. This is the pipeline name and not the metadata name
  • `u` The unstructured object to add to the set of desired resources

func (*Composition) ToResponse

func (c *Composition) ToResponse(r *fnv1beta1.RunFunctionResponse) (err error)

ToResponse converts the composition back into the response object

This method should be called at the end of your RunFunction immediately before returning a normal response.

Wrap this in an error handler and set `response.Fatal` on error

type InputProvider

type InputProvider interface {
	runtime.Object
}

InputProvider This is basically a wrapper to `runtime.Object` and exists to ensure that all inputs to the `New` conform to a supported type

type InvalidMetadata

type InvalidMetadata struct{}

InvalidMetadata is raised when an object metadata cannot be unpacked to a Metadata object

func (*InvalidMetadata) Error

func (e *InvalidMetadata) Error() string

type InvalidSpec

type InvalidSpec struct{}

InvalidSpec is raised when an object spec cannot be unpacked to the required spec object

func (*InvalidSpec) Error

func (e *InvalidSpec) Error() string

type MissingMetadata

type MissingMetadata struct{}

MissingMetadata is raised when an object does not contain a metadata type

func (*MissingMetadata) Error

func (e *MissingMetadata) Error() string

type MissingSpec

type MissingSpec struct{}

MissingSpec when an object requiring spec is detected but spec is not found during unpack

func (*MissingSpec) Error

func (e *MissingSpec) Error() string

type WaitingForSpec

type WaitingForSpec struct{}

WaitingForSpec Raise this error if your input has no spec on the XR but spec is required. Methods receiving this should return response.Normal

func (*WaitingForSpec) Error

func (w *WaitingForSpec) Error() string

Jump to

Keyboard shortcuts

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