Alternate KuboCD Schema Format
In our previous examples, we defined schema.parameters and schema.context using a standard OpenAPI/JSON schema.
While fully supported, it can be quite verbose.
KuboCD also supports a more concise schema syntax, specifically designed for this use case.
Here is one of our podinfo Package example from a previous chapter (Only the schema section)
podinfo-p02.yaml
apiVersion: v1alpha1
........
schema:
parameters:
$schema: http://json-schema.org/schema#
type: object
additionalProperties: false
properties:
host: { type: string }
required:
- host
context:
$schema: http://json-schema.org/schema#
additionalProperties: true
type: object
properties:
ingress:
type: object
additionalProperties: true
properties:
className: { type: string }
domain: { type: string }
required:
- domain
- className
required:
- ingress
modules:
.........
Here’s an identical version of this Package using the simplified KuboCD schema format:
podinfo-p02-alt.yaml
As you can see, the format is significantly more compact.
Info
This schema format is NOT standard OpenAPI
The presence or absence of the $schema: key is what KuboCD uses to distinguish between standard and KuboCD schema formats.
The difference are the following:
- No
$schema:key for the KuboCD format - The
requiredfields are not in an array anymore, but are now an attribute of the node. - The flag
additionalProperties: falseis set on all object and sub-object of aparametersschema. - The flag
additionalProperties: trueis set on all object and sub-object of acontextschema. - the
type: objectis now optional. It is deduced from the presence of thepropertiesattribute. - the
type: arrayis now optional. It is deduced from the presence of theitemsattribute. - All others attributes (
default,enums,pattern, ....) are left unchanged.
When a Package is build using this form, both schemas are converted to their standard OpenAPI/JSON and stored in this last form.
This normalized version will be accessible using kubocd dump package... or kubocd render.... CLI tools.
Warning
If you still use the standard form, setting additionalProperties: false on all objects of schema.parameters is important.
If not, any typo in a variable name will not be trapped and may lead tricky errors.
For the remaining of this manuel, we will use the KuboCD schema.