fix: use dynamic namespace in port-forward URLs instead of hardcoded - #109
Open
Utkarshpandey0001 wants to merge 1 commit into
Open
Conversation
…'gadget' Port-forward URLs were hardcoded to the 'gadget' namespace, which caused the plugin to be non-functional when Inspektor Gadget is installed in a different namespace (e.g. kube-system, ig-system). Changes: - Add buildPortForwardURL() helper in helper.ts that derives the namespace from the pod's own metadata - Update conn.tsx to use buildPortForwardURL() - Update resourcegadgets.tsx to use buildPortForwardURL() and fix the empty-string fallback to null so usePortForward correctly skips connection when no IG pod is found - Update GenericGadgetRenderer to accept a podNamespace prop and use buildPortForwardURL() - Pass podNamespace from gadgetDetails.tsx to GenericGadgetRenderer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #107
fix: Use dynamic namespace in port-forward URLs instead of hardcoding
gadgetPort-forward URLs across the plugin were hardcoded to the
gadgetnamespace (e.g.api/v1/namespaces/gadget/pods/<name>/portforward?ports=8080). This means the plugin is completely non-functional for any cluster where Inspektor Gadget is installed in a namespace other thangadget— for examplekube-system,ig-system, or any custom namespace. The WebSocket connection either returns a404from the Kubernetes API server or times out after 10 seconds, and no gadget data is ever displayed.This PR introduces a
buildPortForwardURL(podName, podNamespace)helper inhelper.tsthat constructs the port-forward path dynamically from the IG pod's own metadata. All three call sites (conn.tsx,resourcegadgets.tsx, andGenericGadgetRenderer/index.tsx) are updated to use this helper. ForGenericGadgetRenderer, which previously only received the pod name as a string, a newpodNamespaceprop is added and passed fromgadgetDetails.tsx.Additionally, this fixes a secondary bug in
resourcegadgets.tsxwhere the fallback value forusePortForwardwas an empty string''instead ofnull. SinceusePortForwardonly skips connection initialization when the URL is strictlynull, the empty string caused a bogus WebSocket connection attempt and a 10-second timeout on every render where no IG pod was found for the current node.How to use
gadget(e.g.ig-system):