Skip to content

Commit d71867d

Browse files
authored
A few low-hanging fruit docs fixes (#971)
* Realtime compositions are beta now Signed-off-by: Nic Cope <[email protected]> * Composition functions don't run on delete Signed-off-by: Nic Cope <[email protected]> * You can't patch XR metadata Signed-off-by: Nic Cope <[email protected]> * Document function response cache Signed-off-by: Nic Cope <[email protected]> --------- Signed-off-by: Nic Cope <[email protected]>
1 parent b652a64 commit d71867d

File tree

5 files changed

+79
-9
lines changed

5 files changed

+79
-9
lines changed

content/master/composition/compositions.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ reports `True`.
140140

141141
Crossplane calls a Function to determine what resources it should create when
142142
you create a composite resource. The Function also tells Crossplane what to do
143-
with these resources when you update or delete a composite resource.
143+
with these resources when you update a composite resource.
144+
145+
{{<hint "note" >}}
146+
Composition functions don't run when you delete a composite resource.
147+
Crossplane handles deletion of composed resources automatically.
148+
{{< /hint >}}
144149

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

579-
When you create, update, or delete a composite resource that uses composition
584+
When you create or update a composite resource that uses composition
580585
functions Crossplane calls each function in the order they appear in the
581586
Composition's pipeline. Crossplane calls each function by sending it a gRPC
582587
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
769774
write to the pipeline context. Crossplane passes the context to all following
770775
functions. When Crossplane has called all functions it discards the pipeline
771776
context.
777+
778+
### Function response cache
779+
780+
{{<hint "note" >}}
781+
Function response caching is an alpha feature. Enable it by setting the
782+
`--enable-function-response-cache` feature flag.
783+
{{< /hint >}}
784+
785+
Crossplane can cache function responses to improve performance by reducing
786+
repeated function calls. When enabled, Crossplane caches responses from
787+
composition functions that include a Time-To-Live (TTL) value.
788+
789+
The cache works by:
790+
- Storing function responses on disk based on a hash of the request
791+
- Only caching responses with a non-zero TTL
792+
- Automatically removing expired cache entries
793+
- Reusing cached responses for identical requests until they expire
794+
795+
This feature is particularly useful for functions that:
796+
- Perform expensive computations or external API calls
797+
- Return stable results for the same inputs
798+
- Include appropriate TTL values in their responses
799+
800+
#### Cache configuration
801+
802+
Control the cache behavior with these Crossplane pod arguments:
803+
804+
- `--xfn-cache-max-ttl` - Maximum cache duration (default: 24 hours)
805+
806+
The cache stores files in the `/cache/xfn/` directory within the Crossplane pod.
807+
For better performance, consider using an in-memory cache by mounting an
808+
emptyDir volume with `medium: Memory`.

content/master/get-started/install.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ at the table below.
106106
| --- | --- | --- |
107107
| Beta | `--enable-deployment-runtime-configs` | Enable support for DeploymentRuntimeConfigs. |
108108
| Beta | `--enable-usages` | Enable support for Usages. |
109-
| Alpha | `--enable-realtime-compositions` | Enable support for real time compositions. |
109+
| Beta | `--enable-realtime-compositions` | Enable support for real time compositions. |
110110
| Alpha | `--enable-dependency-version-upgrades ` | Enable automatic version upgrades of dependencies when updating packages. |
111+
| Alpha | `--enable-function-response-cache` | Enable caching of composition function responses to improve performance. |
111112
| Alpha | `--enable-signature-verification` | Enable support for package signature verification via ImageConfig API. |
112113
{{< /table >}}
113114
{{< /expand >}}

content/master/guides/function-patch-and-transform.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ environment:
424424
patches:
425425
- type: ToCompositeFieldPath
426426
fromFieldPath: tags
427-
toFieldPath: metadata.labels[envTag]
427+
toFieldPath: status.envTag
428428
- type: FromCompositeFieldPath
429429
fromFieldPath: metadata.name
430430
toFieldPath: newEnvironmentKey
@@ -667,7 +667,12 @@ Composition and use it in a second composed resource in the same Composition.
667667
{{< /hint >}}
668668

669669
For example, after Crossplane creates a new managed resource, take the value
670-
`hostedZoneID` and apply it as a `label` in the composite resource.
670+
`hostedZoneID` and store it in the composite resource's status.
671+
672+
{{< hint "important" >}}
673+
To patch to composite resource status fields, you must first define the custom
674+
status fields in the CompositeResourceDefinition.
675+
{{< /hint >}}
671676

672677
```yaml {label="toComposite",copy-lines="9-11"}
673678
apiVersion: pt.fn.crossplane.io/v1beta1
@@ -683,7 +688,7 @@ resources:
683688
patches:
684689
- type: ToCompositeFieldPath
685690
fromFieldPath: status.atProvider.hostedZoneId
686-
toFieldPath: metadata.labels['ZoneID']
691+
toFieldPath: status.hostedZoneId
687692
```
688693

689694
View the created managed resource to see the
@@ -698,12 +703,14 @@ Status:
698703
# Removed for brevity
699704
```
700705

701-
Next view the composite resource and confirm the patch applied the `label`
706+
Next view the composite resource and confirm the patch applied to the status
702707

703708
```yaml {label="toCompositeXR",copy-lines="none"}
704709
$ kubectl describe composite
705710
Name: my-example-p5pxf
706-
Labels: ZoneID=Z2O1EMRO9K5GLX
711+
# Removed for brevity
712+
Status:
713+
Hosted Zone Id: Z2O1EMRO9K5GLX
707714
```
708715

709716
<!-- vale Google.Headings = NO -->

content/master/guides/pods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Kubernetes API server when a composed resource changes. For example, when
137137
a provider sets the `Ready` condition to `true`.
138138

139139
{{<hint "important" >}}
140-
Real time compositions are an alpha feature. Alpha features aren't enabled by
140+
Real time compositions are a beta feature. Beta features are enabled by
141141
default.
142142
{{< /hint >}}
143143

content/master/operations/operation.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,31 @@ For more details on RBAC configuration, see the
297297
[Compositions RBAC documentation]({{<ref "../composition/compositions#grant-access-to-composed-resources">}}).
298298
{{</hint>}}
299299

300+
### Function response cache
301+
302+
{{<hint "note" >}}
303+
Function response caching is an alpha feature. Enable it by setting the
304+
`--enable-function-response-cache` feature flag.
305+
{{< /hint >}}
306+
307+
Operations can benefit from function response caching to improve performance,
308+
especially for operations that:
309+
- Call the same functions repeatedly with identical inputs
310+
- Use functions that perform expensive computations or external API calls
311+
- Run frequently through CronOperation or WatchOperation
312+
313+
The cache works the same way as for Compositions - function responses with
314+
time to live values are cached and reused for identical requests until
315+
they expire.
316+
317+
This is particularly useful for Operations that:
318+
- Validate configurations using expensive checks
319+
- Query external systems for status information
320+
- Perform complex calculations that don't change frequently
321+
322+
For cache configuration details, see the
323+
[Function response cache documentation]({{<ref "../composition/compositions#function-response-cache">}}).
324+
300325
### Required resources
301326

302327
Operations can preload resources for functions to access:

0 commit comments

Comments
 (0)