From 6639b4e24076422c7f57efcc5f6eaf09248d735b Mon Sep 17 00:00:00 2001 From: Jianbo Sun Date: Sat, 15 Oct 2022 14:14:06 +0800 Subject: [PATCH 1/2] fix search Signed-off-by: Jianbo Sun --- .../components/custom-component.md | 33 ++++++++++++++----- docusaurus.config.js | 1 + 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/docs/platform-engineers/components/custom-component.md b/docs/platform-engineers/components/custom-component.md index 63bbe917..40ec7999 100644 --- a/docs/platform-engineers/components/custom-component.md +++ b/docs/platform-engineers/components/custom-component.md @@ -69,7 +69,7 @@ template: { ``` In detail: -- `.spec.workload` is required to indicate the workload type of this component. +- `.spec.workload` indicates the workload type of this component, it can help integrate with traits that apply to this kind of workload. - `.spec.schematic.cue.template` is a CUE template, specifically: * The `output` filed defines the template for the abstraction. * The `parameter` filed defines the template parameters, i.e. the configurable properties exposed in the `Application`abstraction (and JSON schema will be automatically generated based on them). @@ -195,7 +195,7 @@ $ vela def apply task.cue ComponentDefinition task created in namespace vela-system. ``` -## Declare an `Application` +## Declare an `Application` using this component The `ComponentDefinition` can be instantiated in `Application` abstraction as below: @@ -221,8 +221,8 @@ The `ComponentDefinition` can be instantiated in `Application` abstraction as be - "for i in 9 8 7 6 5 4 3 2 1 ; do echo $i ; done" ``` -### Under The Hood
+ Learn Details Under The Hood Above application resource will generate and manage following Kubernetes resources in your target cluster based on the `output` in CUE template and user input in `Application` properties. @@ -299,17 +299,34 @@ output: { } ``` -> Note that `context` information are auto-injected before resources are applied to target cluster. +:::tip +Note that `context` information are auto-injected before resources are applied to target cluster. +::: -### Full available `context` information can be used +### Full available `context` in Component -* Check the reference docs of [definition protocol](../../platform-engineers/oam/x-definition#definition-runtime-context) to see all of the available information in KubeVela `context`. -## Composition +| Context Variable | Description | Type | Scope | +| :------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------: | :----------------------------------------------------: | +| `context.appName` | The app name corresponding to the current instance of the application. | string | ComponentDefinition, TraitDefinition | +| `context.namespace` | The target namespace of the current resource is going to be deployed, not it can be different with the namespace of application if overridden by some policies. | string | ComponentDefinition, TraitDefinition | +| `context.appRevision` | The app version name corresponding to the current instance of the application | string | ComponentDefinition, TraitDefinition | +| `context.appRevisionNum` | The app version number corresponding to the current instance of the application. | int | ComponentDefinition, TraitDefinition | +| `context.name` | The component name corresponding to the current instance of the application. | string | ComponentDefinition, TraitDefinition, PolicyDefinition | +| `context.revision` | The version name of the current component instance. | string | ComponentDefinition, TraitDefinition | +| `context.output` | The object structure after instantiation of current component. | Object Map | ComponentDefinition, TraitDefinition | +| `context.outputs.` | Structure after instantiation of current component and trait | Object Map | ComponentDefinition, TraitDefinition | + +`context.workflowName` +`context.publishVersion` + +## Compose resources in one Component It's common that a component definition is composed by multiple API resources, for example, a `webserver` component that is composed by a Deployment and a Service. CUE is a great solution to achieve this in simplified primitives. -> Another approach to do composition in KubeVela of course is [using Helm](../../tutorials/helm). +:::tip +Compare to [using Helm](../../tutorials/helm), this approach gives your more flexibility as you can control the abstraction any time and integrate with traits, workflows in KubeVela better. +::: ## How-to diff --git a/docusaurus.config.js b/docusaurus.config.js index 6e1cbc99..34736f7f 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -32,6 +32,7 @@ module.exports = { appId: 'PXMFHFWUGZ', apiKey: '2d1f4924c15d2cc0947820c01e65521f', indexName: 'kubevela', + contextualSearch: false, }, navbar: { title: 'KubeVela', From 4d3a84b1d7601809e79f6d6f601636f3740a20a1 Mon Sep 17 00:00:00 2001 From: Jianbo Sun Date: Sun, 16 Oct 2022 00:16:11 +0800 Subject: [PATCH 2/2] refine component and trait definition docs Signed-off-by: Jianbo Sun --- .../components/custom-component.md | 333 ++++++++++--- .../traits/customize-trait.md | 228 ++++++++- docs/platform-engineers/traits/status.md | 138 +----- .../components/custom-component.md | 351 ++++++++++++-- .../traits/customize-trait.md | 444 +++++++++++++----- .../components/custom-component.md | 351 ++++++++++++-- .../traits/customize-trait.md | 444 +++++++++++++----- .../version-v1.5/reference/topology-rule.md | 6 +- sidebars.js | 1 - .../cloud-services/terraform/aws-config.md | 2 +- .../components/custom-component.md | 332 +++++++++++-- .../traits/customize-trait.md | 228 ++++++++- .../platform-engineers/traits/status.md | 138 +----- .../version-v1.5/reference/topology-rule.md | 4 +- versioned_sidebars/version-v1.5-sidebars.json | 1 - 15 files changed, 2239 insertions(+), 762 deletions(-) diff --git a/docs/platform-engineers/components/custom-component.md b/docs/platform-engineers/components/custom-component.md index 40ec7999..c355c7af 100644 --- a/docs/platform-engineers/components/custom-component.md +++ b/docs/platform-engineers/components/custom-component.md @@ -10,7 +10,7 @@ First, generate `ComponentDefinition` scaffolds via `vela def init` with existed The YAML file: -```yaml +```yaml title="stateless.yaml" apiVersion: "apps/v1" kind: "Deployment" spec: @@ -35,8 +35,7 @@ vela def init stateless -t component --template-yaml ./stateless.yaml -o statele It generates a file: -```cue -// $ cat stateless.cue +```cue title="stateless.cue" stateless: { annotations: {} attributes: workload: definition: { @@ -69,10 +68,11 @@ template: { ``` In detail: -- `.spec.workload` indicates the workload type of this component, it can help integrate with traits that apply to this kind of workload. -- `.spec.schematic.cue.template` is a CUE template, specifically: - * The `output` filed defines the template for the abstraction. - * The `parameter` filed defines the template parameters, i.e. the configurable properties exposed in the `Application`abstraction (and JSON schema will be automatically generated based on them). +- The `stateless` is the name of component definition, it can be defined by yourself when initialize the component. +- `stateless.attributes.workload` indicates the workload type of this component, it can help integrate with traits that apply to this kind of workload. +- `template` is a CUE template, specifically: + * The `output` and `outputs` fields define the resources that the component will be composed. + * The `parameter` field defines the parameters of the component, i.e. the configurable properties exposed in the `Application` (and schema will be automatically generated based on them for end users to learn this component). Add parameters in this auto-generated custom component file : @@ -80,8 +80,8 @@ Add parameters in this auto-generated custom component file : stateless: { annotations: {} attributes: workload: definition: { - apiVersion: " apps/v1" - kind: " Deployment" + apiVersion: "apps/v1" + kind: "Deployment" } description: "" labels: {} @@ -114,11 +114,56 @@ template: { You can use `vela def vet` to validate the format: ```shell -$ vela def vet stateless.cue -Validation succeed. +vela def vet stateless.cue ``` -Declare another component named `task` which is an abstraction for run-to-completion workload. +
+expected output + +``` +Validation succeed. +``` +
+ +Apply above `ComponentDefinition` to your Kubernetes cluster to make it work: + +```shell +vela def apply stateless.cue +``` + +
+expected output + +``` +ComponentDefinition stateless created in namespace vela-system. +``` +
+ +Then the end user can check the schema and use it in an application now: + +``` +vela show stateless +``` + +
+expected output + +``` +# Specification ++-------+-------------+--------+----------+---------+ +| NAME | DESCRIPTION | TYPE | REQUIRED | DEFAULT | ++-------+-------------+--------+----------+---------+ +| name | | string | true | | +| image | | string | true | | ++-------+-------------+--------+----------+---------+ +``` +
+ + +Declare another component named `task` which is an abstraction for run-to-completion workload works the same. + +
+Check the details for another example to define a task based component. ```shell vela def init task -t component -o task.cue @@ -186,14 +231,15 @@ template: { } ``` -Apply above `ComponentDefinition` files to your Kubernetes cluster: +Apply above `ComponentDefinition` files to your Kubernetes cluster to make it work: ```shell -$ vela def apply stateless.cue -ComponentDefinition stateless created in namespace vela-system. $ vela def apply task.cue ComponentDefinition task created in namespace vela-system. ``` +
+ +Now let's use the `stateless` and `task` component type. ## Declare an `Application` using this component @@ -268,7 +314,10 @@ spec: ```
-## CUE `Context` +You can also use [dry run](../debug/dry-run) to show what the yaml results will be rendered for debugging. + + +## CUE `Context` for runtime information KubeVela allows you to reference the runtime information of your application via `context` keyword. @@ -303,24 +352,9 @@ output: { Note that `context` information are auto-injected before resources are applied to target cluster. ::: -### Full available `context` in Component +The list of [all available context variables](#full-available-context-in-component) are listed at last of this doc. - -| Context Variable | Description | Type | Scope | -| :------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------: | :----------------------------------------------------: | -| `context.appName` | The app name corresponding to the current instance of the application. | string | ComponentDefinition, TraitDefinition | -| `context.namespace` | The target namespace of the current resource is going to be deployed, not it can be different with the namespace of application if overridden by some policies. | string | ComponentDefinition, TraitDefinition | -| `context.appRevision` | The app version name corresponding to the current instance of the application | string | ComponentDefinition, TraitDefinition | -| `context.appRevisionNum` | The app version number corresponding to the current instance of the application. | int | ComponentDefinition, TraitDefinition | -| `context.name` | The component name corresponding to the current instance of the application. | string | ComponentDefinition, TraitDefinition, PolicyDefinition | -| `context.revision` | The version name of the current component instance. | string | ComponentDefinition, TraitDefinition | -| `context.output` | The object structure after instantiation of current component. | Object Map | ComponentDefinition, TraitDefinition | -| `context.outputs.` | Structure after instantiation of current component and trait | Object Map | ComponentDefinition, TraitDefinition | - -`context.workflowName` -`context.publishVersion` - -## Compose resources in one Component +## Compose resources in one component It's common that a component definition is composed by multiple API resources, for example, a `webserver` component that is composed by a Deployment and a Service. CUE is a great solution to achieve this in simplified primitives. @@ -328,20 +362,26 @@ It's common that a component definition is composed by multiple API resources, f Compare to [using Helm](../../tutorials/helm), this approach gives your more flexibility as you can control the abstraction any time and integrate with traits, workflows in KubeVela better. ::: -## How-to - -KubeVela requires you to define the template of workload type in `output` section, and leave all the other resource templates in `outputs` section with format as below: +KubeVela requires you to define the template of main workload in `output` section, and leave all the other resource templates in `outputs` section with format as below: ```cue -outputs: : - +output: { +