Author a Crossplane Composition function in KCL to generate managed resources

domain: docs.crossplane.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Install function-kcl by applying a Function resource (apiVersion: pkg.crossplane.io/v1, kind: Function, spec.package: xpkg.crossplane.io/crossplane-contrib/function-kcl:v0.11.2) and confirm INSTALLED/HEALTHY.
  2. Add a pipeline step to a mode: Pipeline Composition that sets functionRef.name to the installed function, with input.apiVersion: krm.kcl.dev/v1alpha1, input.kind: KCLInput.
  3. Write KCL in spec.source that reads the observed XR via option("params").oxr, the desired XR via option("params").dxr, and observed composed resources via option("params").ocds, then builds one or more desired resource objects.
  4. Return the desired resources by assigning them to items = [...], giving each one a metadata.annotations["krm.kcl.dev/composition-resource-name"] (or a unique metadata.name) so Crossplane can distinguish multiple resources from one step, and add "krm.kcl.dev/ready": "True" to mark a resource ready.
  5. For connection secrets on Crossplane v2 XRs, compose an explicit v1/Secret resource with base64-encoded data fields (the special meta.krm.kcl.dev/v1alpha1 CompositeConnectionDetails resource only works for legacy v1 XRs).
  6. Render the pipeline locally with `crossplane composition render xr.yaml composition.yaml functions.yaml` to check the generated resources before applying the Composition, Function, and XR to a live cluster.

Known gotchas

Related routes

Write a Crossplane Composition using pipeline mode with function-go-templating to generate conditional managed resources based on composite resource spec fields
crossplane.io · 5 steps · unrated
Build a Crossplane CompositeResourceDefinition (XRD) with schema validation and a matching Composition that provisions a managed database with a connection secret claim
crossplane.io · 5 steps · unrated
Create a Crossplane function pipeline Composition using function-patch-and-transform
docs.crossplane.io · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans