Skip to content

Conversation

SinghaAnirban005
Copy link
Contributor

@SinghaAnirban005 SinghaAnirban005 commented May 29, 2025

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 29, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: SinghaAnirban005
Once this PR has been reviewed and has the lgtm label, please assign joaquimrocha for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from ashu8912 and illume May 29, 2025 17:46
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 29, 2025
@illume illume requested review from Copilot June 17, 2025 08:42
Copy link
Contributor

@Copilot Copilot AI left a 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.

Copilot

This comment was marked as outdated.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 25, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 25, 2025
@illume illume requested a review from Copilot July 3, 2025 08:55
Copy link
Contributor

@Copilot Copilot AI left a 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 and setup* 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, and getResponseReader 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 copy resp.Header to w.Header(), set the appropriate status code, and write respBody to w.
func writeProxyResponse(w http.ResponseWriter, resp *http.Response) {

@SinghaAnirban005 SinghaAnirban005 force-pushed the refactor/func branch 3 times, most recently from 1f945d7 to 9bc7a47 Compare July 3, 2025 20:16
@SinghaAnirban005
Copy link
Contributor Author

/cc @illume

Copy link
Contributor

@skoeva skoeva left a 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

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 11, 2025
@SinghaAnirban005 SinghaAnirban005 force-pushed the refactor/func branch 2 times, most recently from d1333a4 to 4b0457c Compare July 12, 2025 15:12
@SinghaAnirban005
Copy link
Contributor Author

/cc @illume

@SinghaAnirban005 SinghaAnirban005 requested a review from skoeva July 12, 2025 15:53
@illume
Copy link
Contributor

illume commented Jul 14, 2025

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.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 14, 2025
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 14, 2025
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
Signed-off-by: SinghaAnirban005 <[email protected]>
@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 4, 2025
@illume
Copy link
Contributor

illume commented Sep 26, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
Development

Successfully merging this pull request may close these issues.

backend: Refactor headlamp.go createHeadlampHandler to be shorter
4 participants