Skip to main content
Compositions (XRs and XRDs) define the structure of composed infrastructure, but they need programmable logic to flow values from the composite resource (XR) into the composed managed resources. For example: how does a developer-specified spec.size: small on an XR become spec.forProvider.instanceClass: db.t3.micro on an AWS RDS resource? Crossplane functions implement this mapping and conditional logic. In this lesson we will:
  • Explain why compositions need programmable logic.
  • Describe the pipeline architecture used by function-based compositions.
  • Master the Patch-and-Transform function: its structure, configuration, patch types, and transforms.
  • Trace a complete patch-with-transform example end-to-end.
Why functions? A static composition that hard-codes values (e.g., always db.t3.micro, always us-east-1, always 20 GB) is not a real platform. Real self-service platforms accept simple, intent-oriented inputs like size: small, environment: prod, and name: orders, and then translate those into provider-specific configuration. Typical runtime mappings:
  • smalldb.t3.micro (AWS) or db-f1-micro (GCP)
  • name: orders + environment: prodorders-prod for unique resource names
  • environment: prod → 3 replicas; dev → 1 replica
Functions provide these mappings and conditional behaviors. They execute in a pipeline that typically follows this flow:
  1. Render base resources (templates).
  2. Apply patches and transforms to move and convert data.
  3. Optionally run custom logic (filters, readiness checks, additional transforms).
Each function receives the XR and the accumulated output, then returns an updated output to the next function. The pipeline supports three primary capabilities: patches & transforms, conditional logic, and value mapping.
The image depicts a function pipeline for dynamic composition, consisting of four stages: XR (Input), Render Base, Patch & Transform, and Custom Logic, each with specific tasks such as generating resources and applying policies.
Function types Core Crossplane function types to know:
The image shows two utility function types, "function-auto-ready" for automatically setting XR ready status and "function-cel-filter" for filtering resources using CEL expressions.
Pipeline and Patch-and-Transform structure In pipeline mode, each step references a function and provides the function’s input. For Patch-and-Transform the input typically uses API version pt.fn.crossplane.io/v1beta1 and kind Resources. The top-level resources array lists each composed resource: a name, a base template for the managed resource, and a list of patches (with optional transforms) to apply. Example pipeline step (YAML):
A composition often contains multiple pipeline steps. Each step calls a function with an input that tells it which resources to create and which patches / transforms to apply. Patch-and-Transform is the most common function because it enables declarative, composition-friendly mapping. Patch types Patch-and-Transform supports copying data in both directions and from environment configs. The most common patch types: Example: basic FromCompositeFieldPath
Example: Combine fields into a metadata name
Focus on FromCompositeFieldPath and CombineFromComposite first — these cover the majority of practical composition needs.
Transforms Patches copy values; transforms convert or format those values between reading and writing. Common transform types: Examples String format transform:
Map transform (map developer-friendly sizes to provider instance classes):
Convert transform:
Math transform:
String and map transforms are the most commonly used in platform compositions because they let you translate compact, human-friendly inputs into provider-specific configuration. End-to-end example: size → instance class A common pattern converts a simple XR field (spec.size) to a provider instance class:
  1. Developer submits an XR with spec.size: small.
  2. A FromCompositeFieldPath patch reads spec.size.
  3. A map transform maps smalldb.t3.micro.
  4. The mapped value is written to the composed resource at spec.forProvider.instanceClass.
Patch example:
This FromCompositeFieldPath + map transform pattern is the bread-and-butter of Crossplane compositions. Mastering it enables most practical platform workflows. Summary
  • Use pipeline-mode functions for programmable mappings in compositions.
  • Patch-and-Transform (apiVersion: pt.fn.crossplane.io/v1beta1, kind: Resources) is the primary, declarative function for most use cases.
  • Focus first on FromCompositeFieldPath and CombineFromComposite patches.
  • Use string and map transforms for name formatting and mapping developer-friendly values to provider-specific configuration.
  • Reserve GoTemplating, KCL, or custom functions for cases where Patch-and-Transform is not expressive enough.
The image is a presentation slide titled "Key Takeaways," summarizing points about compositional functions and key patch types. It uses a colorful gradient design and bullet points numbered 01 to 03.
Links and references

Watch Video