CGO_ENABLED=0 go install github.com/imuxin/ksql
More jsonpath support details, please check kubernetes kubectl jsonpath support.
- ps1:
NS
is abbreviation forNAMESPACE
- ps2:
NAME
andLABEL
are allowed to have multiple inputs - ps3:
NS
orNAMESPACE
is required onceNAME
is used.
SELECT
ksql> SELECT * FROM service NAMESPACE default NAME kubernetes
+------------+-----------+
| NAME | NAMESPACE |
+------------+-----------+
| kubernetes | default |
+------------+-----------+
ksql> SELECT "{ .metadata.name }" AS NAME, "{ .spec.clusterIP }" AS "CLUSTER-IP", "{ .spec.ports }" FROM svc NAMESPACE default NAME kubernetes
+------------+------------+------------------------------------------------------------------+
| NAME | CLUSTER-IP | { .SPEC.PORTS } |
+------------+------------+------------------------------------------------------------------+
| kubernetes | 10.8.0.1 | [{"name":"https","port":443,"protocol":"TCP","targetPort":6443}] |
+------------+------------+------------------------------------------------------------------+
DESC
ksql> DESC envoyfilters.networking.istio.io
+-------------------------------------------------------------------------------------------------+----------+
| SCHEMA | VERSION |
+-------------------------------------------------------------------------------------------------+----------+
| type EnvoyFilter struct { | v1alpha3 |
| // Customizing Envoy configuration generated by Istio. See more details at: | |
| // https://istio.io/docs/reference/config/networking/envoy-filter.html | |
| spec struct { | |
| // One or more patches with match conditions. | |
| configPatches []struct { | |
| applyTo string | |
| // Match on listener/route configuration/cluster. | |
| match struct { | |
| // Match on envoy cluster attributes. | |
| cluster struct { | |
| // The exact name of the cluster to match. | |
| name string | |
| // The service port for which this cluster was generated. | |
| portNumber int | |
| // The fully qualified service name for this cluster. | |
| service string | |
| // The subset associated with the service. | |
| subset string | |
| } | |
| | |
| ... | |
| | |
| status map[string]interface{} | |
| } | |
+-------------------------------------------------------------------------------------------------+----------+
more usages, see EBNF description:
ksql/pkg/parser/parser_test.go
Lines 11 to 23 in 86e6270
client-go |
ksql |
---|---|
func list() ([]T, error) {
kubeConfig := getKubeConfig()
client, err := dynamic.
NewForConfig(kubeConfig)
if err != nil {
return nil, err
}
gvr :=
schema.GroupVersionResource{
Group: "k8s.io",
Version: "v1alpha1",
Resource: "tttt",
}
s := labels.NewSelector()
req, err := labels.NewRequirement(
"key",
selection.Equals,
[]string{"val"})
if err != nil {
return nil, err
}
s = s.Add(*req)
us, err := client.
Resource(gvr).
List(context.TODO(),
metav1.ListOptions{
LabelSelector: s.String(),
})
if err != nil {
return nil, err
}
var results []T
for _, item := range us.Items {
obj := &T{}
if err := FromUnstructured(
item.Object, obj); err != nil {
return nil, err
}
results = append(results, *obj)
}
return results, nil
} |
import "github.com/imuxin/ksql/pkg/executor"
func list() ([]T, error) {
kubeConfig := getKubeConfig()
sql := `SELECT * FROM
tttt.v1alpha1.k8s.io
LABEL key = val`
return executor.Execute[T](sql, kubeConfig)
} |
- Support
SELECT
stat - Support
FROM
- Support
AS
LABEL
NAMESPACE
NAME
- Support
WHERE
expr - Support
DESC
expr - Support
USE
stat - Support
DELETE
stat - Support
UPDATE
stat - Support custom TABLE extensions
- ...