Skip to main content

Designing your Promise API for Cortex

The Portal Controller turns the spec of your Promise's API into the form of the generated Create and Update workflows. What you write in the CRD decides which fields the form shows, what they are pre-filled with, which ones are required or locked, and which values are rejected before anything is committed to Git.

Name and namespace​

Every Create workflow asks for a name and a namespace, both required. They become the resource request's metadata.name and metadata.namespace, so on submit the form checks that each one:

  • uses only lowercase letters, numbers and hyphens, and starts and ends with a letter or number
  • is 63 characters or fewer

The rule is shown under both fields. On the Update workflow both are filled in from the entity and cannot be changed.

To change their labels and descriptions, or to fix the namespace and hide its field, see the Cortex overview.

Fields​

Each property in spec becomes one form field, labelled with the property name. Its description is shown under the field.

CRD typeForm field
stringText input
string with enumDropdown of the listed values
integerNumber input, whole numbers only
numberNumber input, decimals allowed
booleanToggle
object with propertiesA nested form with its own fields
array of strings, integers, numbers, booleans or objectsA list the requester adds items to
x-kubernetes-int-or-stringText input

Any other type, or a property with no type (for example one using anyOf), stops the workflows from being generated. The error names the field.

Required fields​

List the property as required. Cortex will not submit the form until the field has a value.

spec:
type: object
required:
- size
properties:
size:
type: string

Default values​

default pre-fills the field on the Create workflow.

replicas:
type: integer
description: How many instances to run.
default: 3
size:
type: string
description: How much CPU and memory the database gets.
enum: [small, medium, large]
default: small # for an enum, the default option is selected

On the Update workflow, every field is pre-filled with the request's current value instead.

Immutable fields​

Make a field immutable with a CEL validation rule:

region:
type: string
x-kubernetes-validations:
- rule: self == oldSelf
message: region cannot be changed

The field can be set on create and is read-only on update. Only self == oldSelf (or oldSelf == self) is recognised. Other CEL rules are not supported.

Validation​

Cortex checks these itself:

CRD schemaCheck
requiredThe field must have a value
enumOnly the listed values can be picked
patternStrings must match. Cortex shows the pattern itself in the message
minimum, maximumNumbers must be in range
minItems, maxItemsLists of strings, numbers or booleans must have that many items

The workflows also check these when the form is submitted, and show the message under the field:

CRD schemaApplies toMessage
minLengthTop-level spec string fieldsmust be at least <N> characters
maxLengthTop-level spec string fieldsmust be <N> characters or fewer

An optional field left empty is not checked, so it can stay blank even if it has a minLength.

Anything else, such as a length rule inside a nested object or a CEL rule, is not checked by the form. A value that breaks it is committed to Git and then rejected by the platform. See Troubleshooting on the Send resource requests page.

Next steps​