VelaQL

    velaQL(vela Query Language) is a resource query language for KubeVela, used to query application-level resource status. ​

    KubeVela’s Application encapsulates the underlying resources of the infra. Although it brings the convenience of shielding the underlying infrastructure to users, it also brings many inconveniences to platform developers: the monitoring of the resource status of Application creation can only rely on the CR object of Application. Moreover, the status information is simple and the real-time feedback is poor. ​

    The purpose of velaQL is to help users and platform developers uncover the mystery of Application. Users can query application deployment status through velaQL, or use the extensible interface provided by velaQL to customize query resource information to improve the observability of Application.

    At present, if you want to use the query capabilities of velaQL, you need to install velaux and query the resource status with the help of apiserver. In the future, we will provide more interactive methods. Now you can install velaux with a simple command.

    Assuming we started the apiserver at , you can use velaQL like:

    1. http://127.0.0.1:8000/api/v1/query?velaql="write velaQL here"

    Below we explain how to write velaQL. The basic syntax of velaQL is as follows:

    1. view{parameter1=value1,parameter2=value2}

    view represents a query view, which can be compared to the concept of a view in a database. The view in velaQL is a collection of resource queries on the k8s.

    Filter conditions are placed in {} as the form of key-value pairs, currently the value type only supports: string, int, float, boolean.

    Query view

    velaux has built-in 3 general query views. Below we will introduce the usage of these views:

    component-pod-view

    Parameter List

    Let’s show how to use component-pod-view to query resources.

    1. curl --location -g --request GET \
    2. http://127.0.0.1:8000/api/v1/query?velaql=component-pod-view{appNs=default,appName=demo,name=demo}

    podList includes a list of pods created by the application.

    pod-view

    pod-view queries the detailed status of a pod, including container status and pod-related events.

    Let’s show how to use pod-view to query resources.

    component-pod-view

    The query result contains the status information of the container and various events associated with the pod when it is created.

    resource-view

    resource-view get a list of certain types of resources in the cluster。

    1. curl --location -g --request GET \
    2. 'http://127.0.0.1:8000/api/v1/query?velaql=resource-view{type=ns}'

    In many scenarios, the built-in views cannot meet our needs, and the resources encapsulated under Application are not just the native resources of k8s. For many custom resources, users will have different query requirements. At this time, you need to write your own specific views to complete the query. This section will tell you how to write a custom view.

    The current view in velaQL relies on configMap in k8s as a storage medium, You can refer to https://github.com/oam-dev/kubevela/blob/master/test/e2e-apiserver-test/testdata/component-pod-view.yaml. The template in the configMap data field stores the core logic of the view, template is a query statement implemented in cue language.

    Every time you use velaQL, the system will look for the configMap with the same name as the view under the vela-system namespace, and extract the template for query operations, so please ensure that your custom view is stored under vela-system. ​ The structure of a template is as follows:

    1. import (
    2. "vela/ql"
    3. )
    4. // The parameter here corresponds to the parameter in velaQL
    5. parameter: {
    6. appName: string
    7. appNs: string
    8. name?: string
    9. cluster?: string
    10. clusterNs?: string
    11. }
    12. // query statement implemented with cue
    13. ...
    14. // The query result of velaQL will return the content of the status field by default,
    15. // so please summarize the results you need to query under the status field
    16. status: podList: {...}

    We provide the package to help you query resources. The following explains the cue operators that can be used:

    List all resources created by Application

    Action Parameter

    • app: fill in the basic information of the application that needs to be queried, including the application name and application namespace,The filter field is used to filter the resources created by the application. The options include the cluster where the resource is located, the cluster namespace, and the component to which it belongs
    • list: after the operation is successful, this field will be filled. list is a list of all resources, the k8s description of the resource is stored in the object field.
    • err: if an error occurs in the operation, the error message will be displayed as a string.
    1. #ListResourcesInApp: {
    2. app: {
    3. name: string
    4. namespace: string
    5. filter?: {
    6. cluster?: string
    7. clusterNamespace?: string
    8. components?: [...string]
    9. }
    10. }
    11. list?: [...{
    12. cluster: string
    13. component: string
    14. revision: string
    15. object: {...}
    16. }]
    17. err?: string
    18. }

    Usage

    CollectPods

    List all pods created by the workload

    Action Parameter

    • value: definition of the workload resource you want to query
    • cluster: cluster
    • list: after the operation is successful, this field will be filled. list is a list of all pod resources
    • err: if an error occurs in the operation, the error message will be displayed as a string.
    1. #CollectPods: {
    2. value: {...}
    3. cluster: string
    4. list?:[... v1.Pod]
    5. err?: string
    6. }

    Usage

    1. import (
    2. "vela/ql"
    3. )
    4. name: string
    5. }
    6. resources: ql.#CollectPods & {
    7. value: {
    8. kind: "Deployment"
    9. apiVersion: "apps/v1"
    10. metadata: name: parameter.name
    11. }
    12. }
    13. status: pods: resources.list

    Get resource in Kubernetes cluster.

    Action Parameter

    • value: the resource metadata to be get. And after successful execution, value will be updated with resource definition in cluster.
    • err: if an error occurs, the err will contain the error message.
    1. #Read: {
    2. value: {}
    3. err?: string
    4. }

    Usage

    List resources in the k8s cluster.

    Action Parameter

    • resource: the resource metadata to be get
    • filter: namespace is used to select a namespace, and the matchingLabels field is used to filter labels
    • err: if an error occurs, the err will contain the error message.
    1. #List: {
    2. cluster: *"" | string
    3. resource: {
    4. apiVersion: string
    5. kind: string
    6. }
    7. filter?: {
    8. namespace?: *"" | string
    9. matchingLabels?: {...}
    10. }
    11. list?: {...}
    12. err?: string
    13. }