Generating OpenAPI Schema
For any capabilities installed via Definition Objects, KubeVela will automatically generate OpenAPI v3 JSON schema based on its parameter list, and store it in a ConfigMap in the same namespace with the definition object.
The default KubeVela system
namespaceisvela-system, the built-in capabilities and schemas are laid there.
KubeVela support generate different versions of Component/Trait Definition. Thus, we use ConfigMap to store the parameter information of different versions of Definition. This ConfigMap will have a common label definition.oam.dev=schema, the default ConfigMap without a version suffix will point to the latest version, you can find easily by:
kubectl get configmap -n vela-system -l definition.oam.dev=schema
NAME DATA AGEschema-ingress 1 46mschema-scaler 1 50mschema-webservice 1 2m26sschema-webservice-v1 1 40sschema-worker 1 1m45sschema-worker-v1 1 55sschema-worker-v2 1 20s
For the sack of convenience, we also specify a unified label for the ConfigMap which stores the parameter information of the same Definition. And we can list the ConfigMap which stores the parameter of the same Definition by specifying the label like definition.oam.dev/name=definitionName, where the definitionName is the specific name of your component or trait.
kubectl get configmap -l definition.oam.dev/name=worker
NAME DATA AGEschema-worker 1 1m50sschema-worker-v1 1 1mschema-worker-v2 1 25s
The ConfigMap name is in the format of schema-<your-definition-name>, and the data key is openapi-v3-json-schema.
For example, we can use the following command to get the JSON schema of webservice.
kubectl get configmap schema-webservice -n vela-system -o yaml
apiVersion: v1kind: ConfigMapmetadata:name: schema-webservicenamespace: vela-systemdata:openapi-v3-json-schema: '{"properties":{"cmd":{"description":"Commands to run inthe container","items":{"type":"string"},"title":"cmd","type":"array"},"cpu":{"description":"Numberof CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core)","title":"cpu","type":"string"},"env":{"description":"Definearguments by using environment variables","items":{"properties":{"name":{"description":"Environmentvariable name","title":"name","type":"string"},"value":{"description":"The valueof the environment variable","title":"value","type":"string"},"valueFrom":{"description":"Specifiesa source the value of this var should come from","properties":{"secretKeyRef":{"description":"Selectsa key of a secret in the pod''s namespace","properties":{"key":{"description":"Thekey of the secret to select from. Must be a valid secret key","title":"key","type":"string"},"name":{"description":"Thename 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":"Whichimage would you like to use for your service","title":"image","type":"string"},"port":{"default":80,"description":"Whichport do you want customer traffic sent to","title":"port","type":"integer"}},"required":["image","port"],"type":"object"}'
Specifically, this schema is generated based on parameter section in capability definition:
- For CUE based definition: the
parameteris a keyword in CUE template. - For Terraform based definition: the
variableis the keyword in TF template.
Refer to UX of Definition
Last updated on Feb 9, 2023 by dependabot[bot]