diff --git a/docs/platform-engineers/addon/intro.md b/docs/platform-engineers/addon/intro.md index c895e051..f67742fa 100644 --- a/docs/platform-engineers/addon/intro.md +++ b/docs/platform-engineers/addon/intro.md @@ -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 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/platform-engineers/addon/intro.md b/i18n/zh/docusaurus-plugin-content-docs/current/platform-engineers/addon/intro.md index 05646bbc..46ad9077 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/platform-engineers/addon/intro.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/platform-engineers/addon/intro.md @@ -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 格式的资源 diff --git a/i18n/zh/docusaurus-plugin-content-docs/version-v1.4/platform-engineers/addon/intro.md b/i18n/zh/docusaurus-plugin-content-docs/version-v1.4/platform-engineers/addon/intro.md index 05646bbc..46ad9077 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/version-v1.4/platform-engineers/addon/intro.md +++ b/i18n/zh/docusaurus-plugin-content-docs/version-v1.4/platform-engineers/addon/intro.md @@ -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 格式的资源 diff --git a/versioned_docs/version-v1.4/platform-engineers/addon/intro.md b/versioned_docs/version-v1.4/platform-engineers/addon/intro.md index c895e051..f67742fa 100644 --- a/versioned_docs/version-v1.4/platform-engineers/addon/intro.md +++ b/versioned_docs/version-v1.4/platform-engineers/addon/intro.md @@ -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