This document is for an unreleased version of Crossplane.

This document applies to the Crossplane master branch and not to the latest release v2.4.

Functions extend Crossplane with new ways to configure composition.

You can use different composition functions to configure what Crossplane does when someone creates or updates a composite resource (XR).

Important

This page is a work in progress.

Functions are packages, like Providers and Configurations. Their APIs are similar. You install and configure them the same way as a provider.

Read the composition documentation to learn how to use functions in a composition.

Install a function

Install a Function with a Crossplane Function object setting the spec.package value to the location of the function package.

For example, to install the patch and transform function,

1apiVersion: pkg.crossplane.io/v1
2kind: Function
3metadata:
4  name: crossplane-contrib-function-patch-and-transform
5spec:
6  package: xpkg.crossplane.io/crossplane-contrib/function-patch-and-transform:v0.8.2

By default, the Function pod installs in the same namespace as Crossplane (crossplane-system).

Note

Functions are part of the pkg.crossplane.io group.

The meta.pkg.crossplane.io group is for creating Function packages.

Instructions on building Functions are outside of the scope of this document. Read the Crossplane contributing Function Development Guide for more information.

For information on the specification of Function packages read the Crossplane Function Package specification.

1apiVersion: meta.pkg.crossplane.io/v1
2kind: Function
3metadata:
4  name: provider-aws
5spec:
6# Removed for brevity

Functions managed by Crossplane

Important
Referencing functions by OCI reference is an alpha feature. Enable it by setting the --enable-pipeline-oci-references feature flag.

A Composition or Operation pipeline step can reference a function package by digest with the function field instead of naming an installed Function with functionRef. Read Roll out function changes to learn why you might want to use this feature.

You don’t install these functions yourself. For each digest a pipeline references, Crossplane creates a FunctionRevision. Crossplane groups the revisions under a Function named after the package repository. For example, xpkg.crossplane.io/crossplane-contrib/function-go-templating becomes crossplane-contrib-function-go-templating, the same name Crossplane uses when it installs the function as a dependency.

The CompositionRevisions and Operations that reference a function by OCI reference own its FunctionRevision. The FunctionRevision is garbage collected by Kubernetes when you delete the last CompositionRevision or Operation that references it.

External revisions

For Functions installed by users or as dependencies, Crossplane’s package manager sets one active revision. The revisions created for function references in the CompositionRevisions and Operations are different. Controllers outside the package manager manage these “external” revisions. The package manager pulls the package, runs a function pod for each one, and records their names in the parent Function’s status.externalFunctionRefs field. Multiple external revisions of the same Function can be active at once and the package manager doesn’t determine which should be active.

A Function that only has external revisions has no spec.package. Its status.externalRevisionRefs lists its revisions:

 1apiVersion: pkg.crossplane.io/v1
 2kind: Function
 3metadata:
 4  name: crossplane-contrib-function-go-templating
 5spec:
 6  # No package
 7  # Removed for brevity
 8status:
 9  conditions:
10  # Removed for brevity
11  externalRevisionRefs:
12  - name: crossplane-contrib-function-go-templating-91622b9260e8
13  - name: crossplane-contrib-function-go-templating-d66b8d13aa14

This Function reports HEALTHY as True only when all its external revisions are healthy. It has no current revision.

A Function can have both a spec.package and external revisions. This happens when you install a function and also reference it by digest in a pipeline. The package manager manages the revisions for spec.package as usual and lists the others in status.externalRevisionRefs. Pipeline steps that use functionRef call only the revision the package manager manages.

If another package depends on a function that has only external revisions, the package manager takes over the Function and sets its spec.package.