- map — value mapping (e.g.,
tier->cpuLimit) - combine — join multiple XR fields into a single string (e.g.,
appId) - toCompositeFieldPath — write data from composed resources back into the XR
status - convert — type conversion (e.g., integer -> string)
tier, environment, and replicas. The platform (the Composition) decides how those values map to concrete resource configuration (here, a ConfigMap in the function-lab namespace).
Prerequisites
- A Crossplane control plane with the function
function-patch-and-transforminstalled. - A Kubernetes cluster where composed resources are created in the
function-labnamespace. - Familiarity with Crossplane CompositeResourceDefinitions (XRD) and Compositions.
mode: Pipeline and a single pipeline step that references the function-patch-and-transform function. The pipeline composes one resource: a Kubernetes Object that becomes a ConfigMap (in function-lab) whose data is populated via patches and transforms.
Important: when editing an existing Composition to add patches, always append to the patches array — do not replace it. This preserves previously defined mappings.
When adding new patches, append them to the existing
patches array. Replacing the array can remove previously defined mappings.- ConfigMap
datais string-keyed and string-valued; conversions are often necessary (e.g., integer -> string). ToCompositeFieldPathwrites back into the XRstatus; the XRD must declare the status field being written or Crossplane will reject the status update.
- Map transform (value mapping)
tier into a concrete CPU limit string that the composed ConfigMap expects.
Patch snippet (included above):
function-lab):
data:
- Combine transform (CombineFromComposite)
- ToCompositeFieldPath (write back to XR status)
Crossplane requires that any status field you write with Add the
ToCompositeFieldPath be declared in the XRD schema. If status.configName is not declared, Crossplane will reject the status patch with an error like:configName field to your XRD status properties before applying this patch.- Convert transform (type conversion)
data values must be strings. Convert integer spec.replicas to a string and place it in the ConfigMap data.
Patch snippet (included earlier):
data will include replicas as a string:
Putting it all together — expected results
- Map: maps
spec.tier->data.cpuLimitaccording to the map table. - Combine: concatenates
metadata.nameandspec.environment->data.appId. - ToCompositeFieldPath: writes the composed ConfigMap name back to
status.configNameon the XR (requires XRD declaration). - Convert: converts
spec.replicas(integer) ->data.replicas(string).
- Always append new patches to the end of the
patchesarray instead of replacing it to avoid accidental removal of existing mappings. - When writing back to XR
status, update the XRD first to include any new status properties you plan to set. - Verify composed resource types (e.g., ConfigMap expects string data) and use
converttransforms when necessary.
- Crossplane Composition docs: https://crossplane.io/docs/
- Crossplane Functions (patch-and-transform): check your installed function manifest and documentation for additional transform options.