diff --git a/content/master/composition/compositions.md b/content/master/composition/compositions.md index d0e00217f..0bdba3430 100644 --- a/content/master/composition/compositions.md +++ b/content/master/composition/compositions.md @@ -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. + +{{}} +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 @@ -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. @@ -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 + +{{}} +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`. diff --git a/content/master/get-started/install.md b/content/master/get-started/install.md index 7b2de8363..ef9f8e658 100644 --- a/content/master/get-started/install.md +++ b/content/master/get-started/install.md @@ -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 >}} diff --git a/content/master/guides/function-patch-and-transform.md b/content/master/guides/function-patch-and-transform.md index 9a86c837f..d4046066a 100644 --- a/content/master/guides/function-patch-and-transform.md +++ b/content/master/guides/function-patch-and-transform.md @@ -424,7 +424,7 @@ environment: patches: - type: ToCompositeFieldPath fromFieldPath: tags - toFieldPath: metadata.labels[envTag] + toFieldPath: status.envTag - type: FromCompositeFieldPath fromFieldPath: metadata.name toFieldPath: newEnvironmentKey @@ -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 @@ -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 @@ -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 ``` diff --git a/content/master/guides/pods.md b/content/master/guides/pods.md index 716c1a03e..b1d2f0f31 100644 --- a/content/master/guides/pods.md +++ b/content/master/guides/pods.md @@ -137,7 +137,7 @@ Kubernetes API server when a composed resource changes. For example, when a provider sets the `Ready` condition to `true`. {{}} -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 >}} diff --git a/content/master/operations/operation.md b/content/master/operations/operation.md index bdd69c02d..94ffc761f 100644 --- a/content/master/operations/operation.md +++ b/content/master/operations/operation.md @@ -297,6 +297,31 @@ For more details on RBAC configuration, see the [Compositions RBAC documentation]({{}}). {{}} +### Function response cache + +{{}} +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]({{}}). + ### Required resources Operations can preload resources for functions to access: