What problem are you facing?
crossplane xrd generate --from simpleschema cannot define named, reusable
nested object types.
The root cause is in cmd/crossplane/xrd/generate.go,
newXRDFromSimpleSchema. It calls:
specSchema, err := simpleschema.ToOpenAPISpec(simpleInput.Spec, nil)
...
statusSchema, err = simpleschema.ToOpenAPISpec(processedStatus, nil)
The second argument to ToOpenAPISpec is customTypes. The CLI hardcodes it
to nil. The vendored library, github.com/kubernetes-sigs/kro/pkg/simpleschema,
supports named custom types through this parameter, including per-field markers.
Concrete case: an XRD for a cluster resource with a nodePools field. Each
node pool is a typed object (name, instanceType, minSize, maxSize,
labels).
With --from simpleschema today, the only option is an inline anonymous
object under spec. An inline object cannot carry its own markers, and cannot be reused by another field.
How could Crossplane help solve your problem?
Add a types top-level key to the SimpleSchema input format, and pass it to
simpleschema.ToOpenAPISpec instead of nil.
Example input:
apiVersion: platform.example.org/v1alpha1
kind: XCluster
types:
NodePool:
name: string | required=true description="Name of the node pool"
instanceType: string | required=true description="Cloud instance type, e.g. m5.large"
minSize: integer | default=1 minimum=0 description="Minimum number of nodes in this pool"
maxSize: integer | default=3 minimum=1 description="Maximum number of nodes in this pool"
labels: map[string]string | description="Labels applied to nodes in this pool"
spec:
region: string | required=true description="Cloud region to deploy into"
nodePools: "[]NodePool | required=true listType=map listMapKey=name minItems=1 description=\"Node pools to provision\""
status:
clusterEndpoint: string | description="API endpoint of the created cluster"
This produces spec.nodePools as an array of the named NodePool type, with
x-kubernetes-list-type: map and x-kubernetes-list-map-keys: [name] set on
the array, and a description on every field.
What problem are you facing?
crossplane xrd generate --from simpleschemacannot define named, reusablenested object types.
The root cause is in
cmd/crossplane/xrd/generate.go,newXRDFromSimpleSchema. It calls:The second argument to
ToOpenAPISpeciscustomTypes. The CLI hardcodes itto
nil. The vendored library,github.com/kubernetes-sigs/kro/pkg/simpleschema,supports named custom types through this parameter, including per-field markers.
Concrete case: an XRD for a cluster resource with a
nodePoolsfield. Eachnode pool is a typed object (
name,instanceType,minSize,maxSize,labels).With
--from simpleschematoday, the only option is an inline anonymousobject under
spec. An inline object cannot carry its own markers, and cannot be reused by another field.How could Crossplane help solve your problem?
Add a
typestop-level key to the SimpleSchema input format, and pass it tosimpleschema.ToOpenAPISpecinstead ofnil.Example input:
This produces
spec.nodePoolsas an array of the namedNodePooltype, withx-kubernetes-list-type: mapandx-kubernetes-list-map-keys: [name]set onthe array, and a
descriptionon every field.