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
Note that in this case the type of
parameterfield used in the for-loop must be a map.
Below is an example that will render multiple Kubernetes Services in one trait:
The usage of this trait could be:
The trait definition can send a HTTP request and capture the response to help you rendering the resource with keyword
You can define HTTP request
trailer in the
processing.http section, and the returned data will be stored in
Please ensure the target HTTP server returns a JSON data.
Then you can reference the returned data from
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.
A trait definition can read the generated API resources (rendered from
outputs) of given component definition.
KubeVela will ensure the component definitions are always rendered before traits definitions.
context.output contains the rendered workload API resource (whose GVK is indicated by
spec.workloadin 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
- the rendered Kubernetes Deployment resource will be stored in the
- all other rendered resources will be stored in
<xx>is the unique name in every
TraitDefinition, it can read the rendered API resources (e.g.
context.outputs.gameconfig.data.enemies) from the