Advanced Features

    As a Data Configuration Language, CUE allows you to do some advanced templating magic in definition objects.

    You can define the for-loop inside the .

    Below is an example that will render multiple Kubernetes Services in one trait:

    The usage of this trait could be:

    You can define HTTP request method, url, body, header and trailer in the processing.http section, and the returned data will be stored in .

    Then you can reference the returned data from processing.output in patch or output/outputs.

    Below is an example:

    In above example, this trait definition will send request to get the token data, and then patch the data to given component instance.

    Specifically, the context.output contains the rendered workload API resource (whose GVK is indicated by in component definition), and use context.outputs.<xx> to contain all the other rendered API resources.

    Below is an example for data passing:

    In detail, during rendering worker ComponentDefinition:

    1. all other rendered resources will be stored in context.outputs.<xx>, with <xx> is the unique name in every template.outputs.

    Thus, in TraitDefinition, it can read the rendered API resources (e.g. ) from the context.