fix: limit pod queries using label selectors and dynamically resolve IG daemonset namespaces - #95
Conversation
|
Hi @illume, i have raised pr for this issue. Could you pls review it once and let me know your suggestion. Thanks! |
3878a37 to
2129b7b
Compare
3920e30 to
2129b7b
Compare
There was a problem hiding this comment.
Pull request overview
This PR optimizes Kubernetes Pod listing across the Headlamp Inspektor Gadget plugin by scoping pod queries to Inspektor Gadget pods via label selectors, and it removes hardcoded assumptions about the Inspektor Gadget namespace when establishing port-forward connections by deriving the namespace from the selected pod.
Changes:
- Scope
K8s.ResourceClasses.Pod.useList()calls using alabelSelectorfork8s-app=gadgetto avoid expensive cluster-wide pod listings. - Dynamically build port-forward URLs using the IG pod’s
metadata.namespaceinstead of assuming thegadgetnamespace. - Minor formatting/import ordering cleanup in a few utility/context files.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/index.tsx | Filters details-view pod list with labelSelector to reduce cluster-wide load. |
| src/gadgets/list.tsx | Filters gadget list pod query with labelSelector. |
| src/gadgets/gadgetGrid.tsx | Filters pod queries used by gadget grid/embed/run panels. |
| src/gadgets/gadgetDetails.tsx | Filters pod query and forwards selected pod namespace into renderer. |
| src/gadgets/backgroundgadgets.tsx | Filters pod query for background-running gadgets view. |
| src/common/NodeSelection/index.tsx | Filters pod query used for node/pod selection UI. |
| src/common/gadgetbackgroundinstanceform.tsx | Filters pod query used during background instance creation. |
| src/gadgets/resourcegadgets.tsx | Filters pod query and uses pod-derived namespace for port-forward URL. |
| src/gadgets/conn.tsx | Uses pod-derived namespace for port-forward URL in shared connection hook. |
| src/common/GenericGadgetRenderer/index.tsx | Uses selected pod namespace (fallbacking to gadget) for port-forward URL. |
| src/gadgets/utility.tsx | Formatting-only changes in helper utilities. |
| src/common/GadgetContext/index.tsx | Import ordering adjustment (no functional change). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Utkarshpandey0001 <rajutkarshpandey2003@gmail.com>
2129b7b to
bd473ff
Compare
|
@ashu8912 Hi , i have applies filter in k8s.Resourceclasses.pod.useList() also as suggested by copilot also resolved conflicts. Could you pls look into it once more. Thanks |
fixes #88
This PR heavily optimizes how the plugin queries Kubernetes for Inspektor Gadget pods, directly fixing issue #88. Previously, the plugin called
K8s.ResourceClasses.Pod.useList()without any filters across multiple components (including the globally injected resource details view). In large clusters, querying the entire cluster's pod list on every single resource page navigation caused severe network latency, excessive memory overhead, and unneeded load on thekube-apiserver.To solve this, all instances of Pod.useList() have been updated to include a labelSelector filter targeting the k8s-app=gadget label (utilizing existing IG_CONTAINER_KEY and IG_CONTAINER_VALUE constants).
Additionally, this PR removes the hardcoded [headlamp-plugin/src/common/GenericGadgetRenderer/index.tsx:53:2-110:3) namespace assumption when establishing port-forward connections. The plugin now dynamically reads the namespace directly from the retrieved pod metadata (
pod.jsonData.metadata.namespace), ensuring robust compatibility with custom namespace deployments of Inspektor Gadget.How to use
GET /api/v1/podsrequest now correctly scopes the query using the?labelSelector=k8s-app%3Dgadgetparameter, returning a significantly smaller JSON payload.Testing done
Executed local testing of the Headlamp UI to ensure the websocket port-forward connections start correctly under the new dynamic namespace logic. Also ran the automated code quality suite: