-
Notifications
You must be signed in to change notification settings - Fork 445
backend: Refactor createHeadlampHandler to reduce complexity #3390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backend: Refactor createHeadlampHandler to reduce complexity #3390
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: SinghaAnirban005 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
867e4af
to
1361368
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Refactors createHeadlampHandler
by extracting helper functions to improve readability and reduce complexity.
- Extracted server logging and configuration setup into
logServerConfiguration
andsetup*
functions. - Modularized route definitions (metrics, proxy, OIDC, frontend) into dedicated
setup*
functions. - Segregated proxy and OIDC handling into discrete functions for clarity.
Comments suppressed due to low confidence (3)
backend/cmd/headlamp.go:643
- New helper functions like
getProxyURL
,isURLAllowed
, andgetResponseReader
lack unit tests. Adding tests for these will ensure correctness and prevent regressions.
func getProxyURL(r *http.Request) string {
backend/cmd/headlamp.go:634
- [nitpick] The error message has a trailing space. Removing it will produce cleaner output.
http.Error(w, "no allowed proxy url match, request denied ", http.StatusBadRequest)
backend/cmd/headlamp.go:703
- The
writeProxyResponse
function reads and logs the response body but never writes the status, headers, or body back to the client. You should copyresp.Header
tow.Header()
, set the appropriate status code, and writerespBody
tow
.
func writeProxyResponse(w http.ResponseWriter, resp *http.Response) {
1f945d7
to
9bc7a47
Compare
/cc @illume |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like there's a merge conflict, a rebase should fix that
9bc7a47
to
59326d0
Compare
d1333a4
to
4b0457c
Compare
/cc @illume |
To reduce the risk of this change, and to help make verifying this is correct... it would be good to break this up into separate commits. Additionally, if a bug is introduced we can more easily bisect the changes to see which part caused the issue. |
4b0457c
to
b077b38
Compare
55bdf7c
to
ce49912
Compare
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
be65352
to
b5cd6b4
Compare
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Closing in favour of |
The createHeadlampHandler function was too long and complex making it
hard to maintain.
fixes #3273
Changes made -> Split logic into smaller helper functions where appropriate