fix(api): dynamically resolve backend URL for in-cluster deployments. - #104
Open
Utkarshpandey0001 wants to merge 1 commit into
Open
fix(api): dynamically resolve backend URL for in-cluster deployments.#104Utkarshpandey0001 wants to merge 1 commit into
Utkarshpandey0001 wants to merge 1 commit into
Conversation
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 #102
fix: resolve backend API url dynamically from browser origin
The Inspektor Gadget plugin contained an architectural flaw in how it resolved its backend API endpoint. The getServerURL() function was hardcoded to return
http://localhost:4466for all non-Docker Desktop environments. Because of this, when the plugin was used in any standard Kubernetes web deployment (like EKS, GKE, or Bare-metal), it incorrectly attempted to route its internal API traffic to the user's local machine, causing fatalERR_CONNECTION_REFUSEDerrors when attempting to use any gadgets.This PR addresses the issue by modifying getServerURL() to accurately check for the desktop application environments (isDockerDesktop() and isElectron()), and safely returning an empty string
""for everything else (in-cluster browser clients).By returning an empty string, we allow the fetch and
WebSocketcalls across the plugin codebase to safely resolve via relative paths. This empowers Headlamp's environment-aware API proxying to correctly route the traffic straight into the backend service regardless of the deployment configuration.How to use
Reviewers can validate this PR by doing the following:
/plugins/.../or/externalproxyendpoints without throwingERR_CONNECTION_REFUSEDonlocalhostendpoints, and confirm that the gadget streams data successfully.Testing done
All code formatting, linting, and TypeScript compilation CI workflows were successfully validated locally on the branch. Testing outputs are fully green.