Q: Your platform team has 3,000 lines of complex Crossplane YAML compositions with brittle patch-and-transforms, complex string transforms, and duplicate conditionals. How do you migrate to Crossplane Composition Functions (KRM Functions) using KCL or Python without downtime to active resources?
Migrating complex, unmaintainable YAML patch-and-transform Crossplane compositions to modern, typed Composition Functions using KCL or Python.
Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Deploy the Composition Function Runner
Install the KCL or Python function package in Crossplane using a `Function` custom resource.
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-kcl
spec:
package: xpkg.upbound.io/crossplane-contrib/function-kcl:v0.8.0
Convert Brittle YAML Patches to Modular KCL Script
Replace hundreds of nested `toFieldPath` and `fromFieldPath` YAML blocks with concise, typed KCL logic with unit tests.
# Composition utilizing function-kcl
spec:
pipeline:
- step: render-resources
functionRef:
name: function-kcl
input:
apiVersion: kcl.fn.crossplane.io/v1beta1
kind: KCLInput
source: |
oxr = option("params").oxr
tier = oxr.spec.tier
instance_type = "db.t4g.micro" if tier == "small" else "db.r6g.large"
items = [{
apiVersion = "rds.aws.upjet.crossplane.io/v1beta1"
kind = "Instance"
metadata.name = oxr.metadata.name + "-rds"
spec.forProvider.instanceClass = instance_type
}]
Zero-Downtime Safe Cutover Using External-Name Anchoring
Ensure the new Composition generates exact matching external resource names (`crossplane.io/external-name`). Crossplane reconciles in place without tearing down live AWS resources.
- Install function-kcl to execute clean, typed configuration logic instead of sprawling YAML patches.
- Implement unit tests for complex composition branching logic before deploying to Kubernetes.
- Ensure external resource naming remains identical during migration to avoid cloud resource recreation.