Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3771

Is there a way to filter/limit the fields returned from a kubernetes REST API?

$
0
0

In order to display a dashboard which has the count of the number if certain kinds of resources in kubernetes we need to query the REST API.

For example: If we need to count the number of secrets across all namespaces you have to query every namespace with a REST call like the following

GET serverurl:port/api/v1/namespaces/default/secrets

Which returns a large JSON response

HTTP/1.1 200 OKAudit-Id: d8cee777-36e8-4701-8fa4-458a1fd97c00Cache-Control: no-cache, privateContent-Type: application/jsonDate: Fri, 27 Jan 2023 00:10:03 GMTPortainer-Agent: 2.16.2Portainer-Agent-Api-Version: 2Portainer-Agent-Platform: 2X-Content-Type-Options: nosniffX-Kubernetes-Pf-Flowschema-Uid: c7548afd-c218-4585-a126-2c2eef24b173X-Kubernetes-Pf-Prioritylevel-Uid: a127b956-d11a-40f5-910f-bb6ec5a43216X-Xss-Protection: 1; mode=blockTransfer-Encoding: chunked{"kind": "SecretList","apiVersion": "v1","metadata": {"resourceVersion": "2844355"  },"items": [    {"metadata": {"name": "sh.helm.release.v1.nfs-provisioner.v1","namespace": "default","uid": "baf592c1-4955-41fe-ac73-a0cfc73fa360","resourceVersion": "107753","creationTimestamp": "2022-11-18T00:35:47Z","labels": {"modifiedAt": "1668731747","name": "nfs-provisioner","owner": "helm","status": "failed",...

I then count the number of items and basically throw away everything else.The problem is, I don't need all that information. It's the classic overfetching problem of REST API's.

I had thought perhaps fieldSelector might do it. But it doesn't look like it. Is there a known method? Because currently across 8 namespaces and 800 config maps and secrets we're fetching 32MB+ of data and that's compressed. This means the dashboard is taking about 30+ seconds to load. The other option is to have it load async in the background. But unless there is a way to reduce how much data is returned I'm thinking about applying a limit and putting something like 500+ instead of an exact count. Because loading 30MB each time is just terrible.


Viewing all articles
Browse latest Browse all 3771

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>