|
| 1 | +# OpenSandbox Router |
| 2 | + |
| 3 | +## Overview |
| 4 | +- HTTP/WebSocket reverse proxy that routes to sandbox Pods by `OPEN-SANDBOX-INGRESS` header or Host. |
| 5 | +- Watches Pods in a target Namespace filtered by an ingress label, and routes only when exactly one ready Pod matches. |
| 6 | +- Exposes `/status.ok` health check; prints build metadata (version, commit, time, Go/platform) at startup. |
| 7 | + |
| 8 | +## Quick Start |
| 9 | +```bash |
| 10 | +go run main.go \ |
| 11 | + --namespace <target-namespace> \ |
| 12 | + --ingress-label-key <label-key> \ |
| 13 | + --port 28888 \ |
| 14 | + --log-level info |
| 15 | +``` |
| 16 | +Endpoints: `/` (proxy), `/status.ok` (health). |
| 17 | + |
| 18 | +## Build |
| 19 | +```bash |
| 20 | +cd components/router |
| 21 | +make build |
| 22 | +# override build metadata if needed |
| 23 | +VERSION=1.2.3 GIT_COMMIT=$(git rev-parse HEAD) BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") make build |
| 24 | +``` |
| 25 | + |
| 26 | +## Docker Build |
| 27 | +Dockerfile already wires ldflags via build args: |
| 28 | +```bash |
| 29 | +docker build \ |
| 30 | + --build-arg VERSION=$(git describe --tags --always --dirty) \ |
| 31 | + --build-arg GIT_COMMIT=$(git rev-parse HEAD) \ |
| 32 | + --build-arg BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ |
| 33 | + -t opensandbox/router:local . |
| 34 | +``` |
| 35 | + |
| 36 | +## Multi-arch Publish Script |
| 37 | +`build.sh` uses buildx to build/push linux/amd64 and linux/arm64: |
| 38 | +```bash |
| 39 | +cd components/router |
| 40 | +TAG=local VERSION=1.2.3 GIT_COMMIT=abc BUILD_TIME=2025-01-01T00:00:00Z bash build.sh |
| 41 | +``` |
| 42 | + |
| 43 | +## Runtime Requirements |
| 44 | +- Access to Kubernetes API (in-cluster or via KUBECONFIG). |
| 45 | +- Pods in the specified Namespace labeled with the configured ingress label; Pod IPs must be reachable. |
| 46 | + |
| 47 | +## Behavior Notes |
| 48 | +- Routing key priority: `OPEN-SANDBOX-INGRESS` header first, otherwise Host parsing `<ingress>-<port>.*`. |
| 49 | +- Multiple matching Pods → HTTP 409; no matching Pod → HTTP 404. |
| 50 | +- WebSocket path forwards essential headers and X-Forwarded-*; HTTP path strips `OPEN-SANDBOX-INGRESS` before proxying. |
| 51 | + |
| 52 | +## Development & Tests |
| 53 | +```bash |
| 54 | +cd components/router |
| 55 | +go test ./... |
| 56 | +``` |
| 57 | +Key code: |
| 58 | +- `main.go`: entrypoint and handlers. |
| 59 | +- `pkg/proxy/`: HTTP/WebSocket proxy logic, pod watching, health check. |
| 60 | +- `version/`: build metadata output (populated via ldflags). |
| 61 | + |
0 commit comments