clusterpedia-io / clusterpedia

The Encyclopedia of Kubernetes clusters
https://clusterpedia.io
Apache License 2.0
801 stars 121 forks source link

support list field filtering #48

Open scydas opened 2 years ago

scydas commented 2 years ago

support list field filtering

kubectl get po --field-selector="spec.containers[].name!=container1"

kubectl get po --field-selector="spec.containers[].name == container1"

kubectl get po --field-selector="spec.containers[1].name in (container1,container2)"

PostgreSQL

SELECT *
FROM "resources",
     jsonb_array_elements(object -> 'status' -> 'conditions') as obj
WHERE "group" = 'apps'
  AND "resource" = 'deployments'
  AND "version" = 'v1'
  AND obj ->> 'status' = 'True'
ORDER BY namespace, name
LIMIT 10;

MySQL

SELECT *
FROM resources
WHERE `group` = 'apps'
  AND resource = 'deployments'
  AND version = 'v1'
  AND json_contains(object, '{"status": "True"}', '$.status.conditions')
ORDER BY namespace, name
LIMIT 10;
Iceber commented 2 years ago

@scydas Thanks for your work. The sql statements in postgres can seriously break sql generation, we can see if others have a need for this feature.

feeltimeQ commented 2 years ago

hi! I think this is a very necessary feature, in a multi-cluster environment, there are bound to be a lot of pods, and if there is a problem with the service and I need to check the status of the pods. I need this feature to retrieve the unhealthy pods, but pod.stauts.conditions is an array, so I can't do it. Only search by myself 😣.

`status: conditions:

Iceber commented 2 years ago

For mysql, array fields can be filtered using raw sql. For pg, we may add a fromSQL query parameter in the future to override the pg syntax