版本:v1.6

Definition 生成 OpenAPI 描述

对于任何通过定义对象 安装的 capability, KubeVela 会自动根据 OpenAPI v3 JSON schema 的参数列表来生成 OpenAPI v3 JSON schema,并把它储存到一个和定义对象处于同一个 namespaceConfigMap 中。

默认的 KubeVela 系统 namespacevela-system,内置的 capability 和 schema 位于此处。

这个 ConfigMap 会有一个通用的标签 definition.oam.dev=schema,所以你可以轻松地通过下述方法找到他们:

  1. $ kubectl get configmap -n vela-system -l definition.oam.dev=schema
  2. NAME DATA AGE
  3. schema-ingress 1 19s
  4. schema-scaler 1 19s
  5. schema-task 1 19s
  6. schema-webservice 1 19s
  7. schema-worker 1 20s

ConfigMap 命名的格式为 schema-<your-definition-name>,数据键为 openapi-v3-json-schema.

举个例子,我们可以使用以下命令来获取 webservice 的JSON schema。

  1. $ kubectl get configmap schema-webservice -n vela-system -o yaml
  2. apiVersion: v1
  3. kind: ConfigMap
  4. metadata:
  5. name: schema-webservice
  6. namespace: vela-system
  7. data:
  8. openapi-v3-json-schema: '{"properties":{"cmd":{"description":"Commands to run in
  9. the container","items":{"type":"string"},"title":"cmd","type":"array"},"cpu":{"description":"Number
  10. of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core)","title":"cpu","type":"string"},"env":{"description":"Define
  11. arguments by using environment variables","items":{"properties":{"name":{"description":"Environment
  12. variable name","title":"name","type":"string"},"value":{"description":"The value
  13. of the environment variable","title":"value","type":"string"},"valueFrom":{"description":"Specifies
  14. a source the value of this var should come from","properties":{"secretKeyRef":{"description":"Selects
  15. a key of a secret in the pod''s namespace","properties":{"key":{"description":"The
  16. key of the secret to select from. Must be a valid secret key","title":"key","type":"string"},"name":{"description":"The
  17. name of the secret in the pod''s namespace to select from","title":"name","type":"string"}},"required":["name","key"],"title":"secretKeyRef","type":"object"}},"required":["secretKeyRef"],"title":"valueFrom","type":"object"}},"required":["name"],"type":"object"},"title":"env","type":"array"},"image":{"description":"Which
  18. image would you like to use for your service","title":"image","type":"string"},"port":{"default":80,"description":"Which
  19. port do you want customer traffic sent to","title":"port","type":"integer"}},"required":["image","port"],"type":"object"}'

具体来说,该 schema 是根据capability 定义中的 parameter 部分生成的:

  • 对于基于 CUE 的定义:parameter CUE 模板中的关键词。
  • 对于基于 Terraform 的定义:读取 TF 模块配置中的 variable 关键词。

参考 UI 扩展

Last updated on 2022年12月1日 by Somefive