addon context (#762)

* add context related

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

* fix comments

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
This commit is contained in:
wyike 2022-06-21 22:02:06 +08:00 committed by GitHub
parent c520bc3da1
commit 0c6fe90e94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 160 additions and 4 deletions

View File

@ -208,7 +208,45 @@ spec:
name: my-account
```
UX/CLI renders all CUE files and `parameter.cue` in one context when the addon is enabled, resulting in a set of components that are appended to the application template.
##### Use context render component
Besides using `parameter` to generate component dynamically, you can also use `context` to render runtime variable.
For example, you can define the component with cue like this:
```cue
output: {
type: "webservice"
properties: {
image: "oamdev/vela-apiserver:" + context.metadata.version
....
}
}
```
And the `metadata.yaml` is:
```yaml
...
name: velaux
version: 1.2.4
...
```
The render will be:
```yaml
kind: Application
...
# application header in template
spec:
components:
- type: webservice
properties:
image: "oamdev/vela-apiserver:v1.2.4"
```
The image tag becomes the addon's version due to the `context.metadata.version` points to. The real example is [VelaUX](https://github.com/kubevela/catalog/blob/master/addons/velaux/resources/apiserver.cue).
Other available fields please refer to [metadata](#metadata.yaml(Required)).
UX/CLI renders all CUE files , `parameter.cue` and data defined in `metadata.yaml` in one context when the addon is enabled, resulting in a set of components that are appended to the application template.
#### YAML format resource

View File

@ -204,7 +204,47 @@ spec:
name: my-account
```
背后的机制是,在启用时 UX/CLI 会把 CUE 定义的资源文件和参数文件放在一个上下文中渲染,得到一系列组件追加到应用当中去。
##### 使用 context 中的变量渲染组件
除了定义参数动态渲染组件外,你还可以使用运行时自动填充到 `context` 中的变量来做渲染。
例如你可以定义一个这样的 CUE 组件:
```cue
output: {
type: "webservice"
properties: {
image: "oamdev/vela-apiserver:" + context.metadata.version
....
}
}
```
同时你的 `metadata.yaml` 为:
```yaml
...
name: velaux
version: 1.2.4
...
```
渲染的结果为:
```yaml
kind: Application
...
# application header in template
spec:
components:
- type: webservice
properties:
image: "oamdev/vela-apiserver:v1.2.4"
```
这个例子中,使用了插件的版本来填充镜像的 tag。一个例子是 [VelaUX](https://github.com/kubevela/catalog/blob/master/addons/velaux/resources/apiserver.cue) 插件。
其他字段请参考元数据文件定义。
插件渲染的机制是,在启用时 UX/CLI 会把 CUE 定义的资源文件、参数文件和 `metadata.yaml` 中定义的数据放在一个上下文中渲染,得到一系列组件追加到应用当中去。
#### YAML 格式的资源

View File

@ -204,7 +204,47 @@ spec:
name: my-account
```
背后的机制是,在启用时 UX/CLI 会把 CUE 定义的资源文件和参数文件放在一个上下文中渲染,得到一系列组件追加到应用当中去。
##### 使用 context 中的变量渲染组件
除了定义参数动态渲染组件外,你还可以使用运行时自动填充到 `context` 中的变量来做渲染。
例如你可以定义一个这样的 CUE 组件:
```cue
output: {
type: "webservice"
properties: {
image: "oamdev/vela-apiserver:" + context.metadata.version
....
}
}
```
同时你的 `metadata.yaml` 为:
```yaml
...
name: velaux
version: 1.2.4
...
```
渲染的结果为:
```yaml
kind: Application
...
# application header in template
spec:
components:
- type: webservice
properties:
image: "oamdev/vela-apiserver:v1.2.4"
```
这个例子中,使用了插件的版本来填充镜像的 tag。一个例子是 [VelaUX](https://github.com/kubevela/catalog/blob/master/addons/velaux/resources/apiserver.cue) 插件。
其他字段请参考元数据文件定义。
插件渲染的机制是,在启用时 UX/CLI 会把 CUE 定义的资源文件、参数文件和 `metadata.yaml` 中定义的数据放在一个上下文中渲染,得到一系列组件追加到应用当中去。
#### YAML 格式的资源

View File

@ -208,7 +208,45 @@ spec:
name: my-account
```
UX/CLI renders all CUE files and `parameter.cue` in one context when the addon is enabled, resulting in a set of components that are appended to the application template.
##### Use context render component
Besides using `parameter` to generate component dynamically, you can also use `context` to render runtime variable.
For example, you can define the component with cue like this:
```cue
output: {
type: "webservice"
properties: {
image: "oamdev/vela-apiserver:" + context.metadata.version
....
}
}
```
And the `metadata.yaml` is:
```yaml
...
name: velaux
version: 1.2.4
...
```
The render will be:
```yaml
kind: Application
...
# application header in template
spec:
components:
- type: webservice
properties:
image: "oamdev/vela-apiserver:v1.2.4"
```
The image tag becomes the addon's version due to the `context.metadata.version` points to. The real example is [VelaUX](https://github.com/kubevela/catalog/blob/master/addons/velaux/resources/apiserver.cue).
Other available fields please refer to [metadata](#metadata.yaml(Required)).
UX/CLI renders all CUE files , `parameter.cue` and data defined in `metadata.yaml` in one context when the addon is enabled, resulting in a set of components that are appended to the application template.
#### YAML format resource