Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions content/master/composition/compositions.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ reports `True`.

Crossplane calls a Function to determine what resources it should create when
you create a composite resource. The Function also tells Crossplane what to do
with these resources when you update or delete a composite resource.
with these resources when you update a composite resource.

{{<hint "note" >}}
Composition functions don't run when you delete a composite resource.
Crossplane handles deletion of composed resources automatically.
{{< /hint >}}

When Crossplane calls a Function it sends it the current state of the composite
resource. It also sends it the current state of any resources the composite
Expand Down Expand Up @@ -576,7 +581,7 @@ sequenceDiagram
Crossplane Pod->>+API Server: Apply desired composed resources
```

When you create, update, or delete a composite resource that uses composition
When you create or update a composite resource that uses composition
functions Crossplane calls each function in the order they appear in the
Composition's pipeline. Crossplane calls each function by sending it a gRPC
RunFunctionRequest. The function must respond with a gRPC RunFunctionResponse.
Expand Down Expand Up @@ -769,3 +774,35 @@ that isn't desired state. Functions can use context for this. Any function can
write to the pipeline context. Crossplane passes the context to all following
functions. When Crossplane has called all functions it discards the pipeline
context.

### Function response cache

{{<hint "note" >}}
Function response caching is an alpha feature. Enable it by setting the
`--enable-function-response-cache` feature flag.
{{< /hint >}}

Crossplane can cache function responses to improve performance by reducing
repeated function calls. When enabled, Crossplane caches responses from
composition functions that include a Time-To-Live (TTL) value.

The cache works by:
- Storing function responses on disk based on a hash of the request
- Only caching responses with a non-zero TTL
- Automatically removing expired cache entries
- Reusing cached responses for identical requests until they expire

This feature is particularly useful for functions that:
- Perform expensive computations or external API calls
- Return stable results for the same inputs
- Include appropriate TTL values in their responses

#### Cache configuration

Control the cache behavior with these Crossplane pod arguments:

- `--xfn-cache-max-ttl` - Maximum cache duration (default: 24 hours)

The cache stores files in the `/cache/xfn/` directory within the Crossplane pod.
For better performance, consider using an in-memory cache by mounting an
emptyDir volume with `medium: Memory`.
3 changes: 2 additions & 1 deletion content/master/get-started/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ at the table below.
| --- | --- | --- |
| Beta | `--enable-deployment-runtime-configs` | Enable support for DeploymentRuntimeConfigs. |
| Beta | `--enable-usages` | Enable support for Usages. |
| Alpha | `--enable-realtime-compositions` | Enable support for real time compositions. |
| Beta | `--enable-realtime-compositions` | Enable support for real time compositions. |
| Alpha | `--enable-dependency-version-upgrades ` | Enable automatic version upgrades of dependencies when updating packages. |
| Alpha | `--enable-function-response-cache` | Enable caching of composition function responses to improve performance. |
| Alpha | `--enable-signature-verification` | Enable support for package signature verification via ImageConfig API. |
{{< /table >}}
{{< /expand >}}
Expand Down
17 changes: 12 additions & 5 deletions content/master/guides/function-patch-and-transform.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ environment:
patches:
- type: ToCompositeFieldPath
fromFieldPath: tags
toFieldPath: metadata.labels[envTag]
toFieldPath: status.envTag
- type: FromCompositeFieldPath
fromFieldPath: metadata.name
toFieldPath: newEnvironmentKey
Expand Down Expand Up @@ -667,7 +667,12 @@ Composition and use it in a second composed resource in the same Composition.
{{< /hint >}}

For example, after Crossplane creates a new managed resource, take the value
`hostedZoneID` and apply it as a `label` in the composite resource.
`hostedZoneID` and store it in the composite resource's status.

{{< hint "important" >}}
To patch to composite resource status fields, you must first define the custom
status fields in the CompositeResourceDefinition.
{{< /hint >}}

```yaml {label="toComposite",copy-lines="9-11"}
apiVersion: pt.fn.crossplane.io/v1beta1
Expand All @@ -683,7 +688,7 @@ resources:
patches:
- type: ToCompositeFieldPath
fromFieldPath: status.atProvider.hostedZoneId
toFieldPath: metadata.labels['ZoneID']
toFieldPath: status.hostedZoneId
```

View the created managed resource to see the
Expand All @@ -698,12 +703,14 @@ Status:
# Removed for brevity
```

Next view the composite resource and confirm the patch applied the `label`
Next view the composite resource and confirm the patch applied to the status

```yaml {label="toCompositeXR",copy-lines="none"}
$ kubectl describe composite
Name: my-example-p5pxf
Labels: ZoneID=Z2O1EMRO9K5GLX
# Removed for brevity
Status:
Hosted Zone Id: Z2O1EMRO9K5GLX
```

<!-- vale Google.Headings = NO -->
Expand Down
2 changes: 1 addition & 1 deletion content/master/guides/pods.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Kubernetes API server when a composed resource changes. For example, when
a provider sets the `Ready` condition to `true`.

{{<hint "important" >}}
Real time compositions are an alpha feature. Alpha features aren't enabled by
Real time compositions are a beta feature. Beta features are enabled by
default.
{{< /hint >}}

Expand Down
25 changes: 25 additions & 0 deletions content/master/operations/operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,31 @@ For more details on RBAC configuration, see the
[Compositions RBAC documentation]({{<ref "../composition/compositions#grant-access-to-composed-resources">}}).
{{</hint>}}

### Function response cache

{{<hint "note" >}}
Function response caching is an alpha feature. Enable it by setting the
`--enable-function-response-cache` feature flag.
{{< /hint >}}

Operations can benefit from function response caching to improve performance,
especially for operations that:
- Call the same functions repeatedly with identical inputs
- Use functions that perform expensive computations or external API calls
- Run frequently through CronOperation or WatchOperation

The cache works the same way as for Compositions - function responses with
time to live values are cached and reused for identical requests until
they expire.

This is particularly useful for Operations that:
- Validate configurations using expensive checks
- Query external systems for status information
- Perform complex calculations that don't change frequently

For cache configuration details, see the
[Function response cache documentation]({{<ref "../composition/compositions#function-response-cache">}}).

### Required resources

Operations can preload resources for functions to access:
Expand Down
Loading