Skip to content

fix: use dynamic namespace in port-forward URLs instead of hardcoded - #109

Open
Utkarshpandey0001 wants to merge 1 commit into
inspektor-gadget:mainfrom
Utkarshpandey0001:fix/dynamic-namespace-port-forward
Open

fix: use dynamic namespace in port-forward URLs instead of hardcoded#109
Utkarshpandey0001 wants to merge 1 commit into
inspektor-gadget:mainfrom
Utkarshpandey0001:fix/dynamic-namespace-port-forward

Conversation

@Utkarshpandey0001

Copy link
Copy Markdown
Contributor

fixes #107

fix: Use dynamic namespace in port-forward URLs instead of hardcoding gadget

Port-forward URLs across the plugin were hardcoded to the gadget namespace (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 than gadget — for example kube-system, ig-system, or any custom namespace. The WebSocket connection either returns a 404 from 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 in helper.ts that constructs the port-forward path dynamically from the IG pod's own metadata. All three call sites (conn.tsx, resourcegadgets.tsx, and GenericGadgetRenderer/index.tsx) are updated to use this helper. For GenericGadgetRenderer, which previously only received the pod name as a string, a new podNamespace prop is added and passed from gadgetDetails.tsx.

Additionally, this fixes a secondary bug in resourcegadgets.tsx where the fallback value for usePortForward was an empty string '' instead of null. Since usePortForward only skips connection initialization when the URL is strictly null, 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

  1. Install Inspektor Gadget into a namespace other than gadget (e.g. ig-system):
    kubectl create namespace ig-system
    helm install gadget gadget/gadget --namespace ig-system
    

…'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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG:Hardcoded gadget Namespace in Port-Forward URLs Breaks Non-Default Installations

1 participant