Skip to content

Add script to start proxy locally#36

Merged
metalice merged 1 commit intokubevirt-ui:mainfrom
adamviktora:local-proxy
Nov 18, 2025
Merged

Add script to start proxy locally#36
metalice merged 1 commit intokubevirt-ui:mainfrom
adamviktora:local-proxy

Conversation

@adamviktora
Copy link
Member

@adamviktora adamviktora commented Nov 10, 2025

Adds start-proxy.sh script to run proxy locally

Summary by CodeRabbit

  • New Features

    • Introduced development mode with environment-based API endpoint and TLS behavior.
    • Added a local development script to build and run the proxy locally.
  • Bug Fixes

    • Improved error handling: failures contacting the cluster now return structured error responses.
  • Documentation

    • Added local development guide with cluster login and proxy execution instructions.

@coderabbitai
Copy link

coderabbitai bot commented Nov 10, 2025

Walkthrough

Adds local development support: new start-proxy.sh script, README instructions, .gitignore entry for the built binary, environment-driven API server URL, and APP_ENV-based TLS toggle; handlers now read KUBE_API_SERVER and return JSON 500 on API connection failures.

Changes

Cohort / File(s) Summary
Ignore rules
.gitignore
Adds kubevirt-apiserver-proxy binary to ignore list
Documentation
README.md
Adds "Local development" subsection with steps to log into cluster, build, and run the proxy locally on localhost:8080
Proxy handlers
handlers/handlers.go
Reads KUBE_API_SERVER via new getEnvOrDefault() helper (defaults to kubernetes.default.svc); adds os import; returns JSON error (HTTP 500) on API server connection failure
Application entrypoint
main.go
Adds os import and branches server startup on APP_ENV: runs non-TLS in dev, otherwise starts TLS with certificates
Local dev tooling
start-proxy.sh
New script: sets APP_ENV=dev, extracts API server from oc config, validates and exports KUBE_API_SERVER, builds the binary, and runs kubevirt-apiserver-proxy

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Script as start-proxy.sh
    participant App as kubevirt-apiserver-proxy
    participant Kube as Kubernetes API

    Dev->>Script: run start-proxy.sh
    Script->>Script: export APP_ENV=dev\nextract KUBE_API_SERVER from oc config
    Script->>Script: go build
    Script->>App: execute binary

    App->>App: read APP_ENV and KUBE_API_SERVER
    alt APP_ENV == "dev"
        App->>App: start HTTP server (no TLS)
    else
        App->>App: start HTTPS server (TLS)
    end

    Dev->>App: HTTP request
    App->>Kube: forward request to API_SERVER_URL
    alt success
        Kube-->>App: response
        App-->>Dev: proxied response
    else failure
        App-->>Dev: HTTP 500 JSON error
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Inspect handlers/handlers.go for correct env fallback and JSON error formatting.
  • Verify main.go APP_ENV branching and TLS invocation logic.
  • Check start-proxy.sh parsing of oc config output and build error handling.

Poem

🐇 I nibble code and hop on logs so spry,
I fetch the server from your oc reply,
In dev I skip the cloak of TLS night,
I build, I run, I forward with delight,
A tiny proxy carrot brightens local sky.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add script to start proxy locally' directly aligns with the main change: adding start-proxy.sh for local development, though it also encompasses supporting changes to .gitignore, README, handlers, and main.go.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e40577 and c479067.

📒 Files selected for processing (5)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • handlers/handlers.go (2 hunks)
  • main.go (2 hunks)
  • start-proxy.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • main.go
  • .gitignore
  • README.md
  • handlers/handlers.go
🔇 Additional comments (3)
start-proxy.sh (3)

7-14: Excellent error handling for API server detection.

The script properly separates variable assignment from export and validates the result before use, which correctly addresses the previous SC2155 warning. The error message is clear and actionable for users who haven't authenticated with oc.


18-22: Build error handling is correct.

The explicit check of the build exit status prevents execution of a stale or non-existent binary and provides clear feedback on build failures.


1-24: LGTM—well-structured local development script.

The script properly detects the Kubernetes API server from the current oc context, exports the necessary environment variables for dev mode, validates critical prerequisites, and builds with appropriate error handling. All previous review concerns have been addressed.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62bf96c and 1e40577.

📒 Files selected for processing (5)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • handlers/handlers.go (2 hunks)
  • main.go (2 hunks)
  • start-proxy.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.11.0)
start-proxy.sh

[warning] 7-7: Declare and assign separately to avoid masking return values.

(SC2155)

🔇 Additional comments (6)
.gitignore (1)

11-12: LGTM!

Good practice to ignore the built binary. The placement and comment are appropriate.

README.md (1)

7-11: LGTM!

Clear and concise documentation for the local development workflow.

main.go (1)

29-34: Environment-based TLS toggle looks good.

The dev/prod separation using APP_ENV is appropriate for local development. In production mode, ensure the certificate files exist at ./cert/tls.crt and ./cert/tls.key (which aligns with the volume mount configuration shown in the README).

handlers/handlers.go (3)

19-24: LGTM!

The getEnvOrDefault helper is simple, clear, and follows standard patterns for environment variable handling.


15-15: Good improvement for flexibility.

Using environment-based configuration for the API server URL makes the proxy more flexible for different deployment scenarios. The default kubernetes.default.svc is appropriate for in-cluster usage.


74-75: Improved error handling.

Returning a JSON error response in addition to logging provides better feedback to API clients when the connection to the Kubernetes API server fails.

@openshift-ci
Copy link

openshift-ci bot commented Nov 18, 2025

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: adamviktora, metalice

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@metalice metalice merged commit 3e2b595 into kubevirt-ui:main Nov 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants