VelaQL - Query Resources behind Application
#
IntroductionVelaQL(Vela Query Language) is a resource query language for KubeVela, used to query status of any extended resources in application-level.
KubeVela's Application encapsulates the underlying resources from the infrastructure. It brings the infrastructure agonistic experience to app developers but also makes challenges for platform builders to maintain. For example, the monitoring of the resource status created by KubeVela Application can be hard. Moreover, the status information within Application is not detailed enough for trouble shooting and the real-time feedback is poor.
The purpose of VelaQL is to help users and platform builders to uncover the mysterious of the Application. Users can query application deployment status through VelaQL, or use the extensible interface provided by VelaQL to customize query information to improve the observability of one Application.
#
Usage#
InstallAt 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 http://127.0.0.1:8000
, you can use VelaQL like:
Below we explain how to write VelaQL. The basic syntax of VelaQL is as follows:
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 viewVelaUX has built-in 3 general query views. Below we will introduce the usage of these views:
#
component-pod-viewcomponent-pod-view
indicates the status query of pods which created by a component.
Parameter List
name | type | describe |
---|---|---|
appName | string | application name |
appNs | string | application namespace |
name | string | component name |
cluster | string | the cluster the pod is deployed to |
clusterNs | string | the namespace the pod is deployed to |
Let's show how to use component-pod-view
to query resources.
podList includes a list of pods created by the application.
#
pod-viewpod-view
queries the detailed status of a pod, including container status and pod-related events.
name | type | describe |
---|---|---|
name | string | pod name |
namespace | string | pod namespace |
cluster | string | the cluster the pod is deployed to |
Let's show how to use pod-view
to query resources.
The query result contains the status information of the container and various events associated with the pod when it is created.
#
resource-viewresource-view
get a list of certain types of resources in the cluster。
name | type | describe |
---|---|---|
type | string | Resource type, optional types are "ns", "secret", "configMap", "pvc", "storageClass" |
namespace | string | namespace |
cluster | string | cluster |
Let's show how to use resource-view
to query resources.
#
Advanced viewIn 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/kubevela/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:
We provide the vela/ql
package to help you query resources. The following explains the cue operators that can be used:
#
ListResourcesInAppList 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.
#
Usage#
CollectPodsList 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.
#
Usage#
ReadGet 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.
#
Usage#
ListList 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.