Skip to content

Commit eb22bda

Browse files
authored
feat(service-proxy): local debug setup (#1619)
this adds env variables and a readme to help with dev/debug of service proxy
1 parent f8c3f65 commit eb22bda

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

cmd/service-proxy/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Running `service-proxy` service locally
2+
3+
You can run the `service-proxy` service locally to debug and test against a running greenhouse cluster.
4+
5+
## Prerequisites
6+
7+
Point the environment variable `KUBECONFIG` to the kubeconfig file of the target greenhouse cluster you want to test against.
8+
9+
The exposed service URLs generated on the target Greenhouse cluster need to be reachable from your local machine.
10+
Set the environment variable `GREENHOUSE_DNS_DOMAIN` to the DNS domain used in the target greenhouse cluster. For example: `myorg.greenhouse.tld`
11+
12+
In order to forward the requests to your local machine, you can use a service like `nip.io` that maps wildcard DNS to IP addresses.
13+
Set the environment variable `DEBUG_DOMAIN` to a domain that maps to your local machine. For example: `127.0.0.1.nip.io:8080`
14+
15+
This will override the DNS domain in the exposed service URLs generated on the target greenhouse cluster, allowing you to access them locally.
16+
17+
## Running the service
18+
19+
Run the service proxy locally passing the arguments for `--kubecontext` and `--kubenamespace` to point to the correct organization in the target greenhouse cluster.
20+
21+
In your browser you can now access the exposed services using the URLs generated by the service proxy, which will be redirected to your local machine. For this take the generated part `<cluster-name>--<service-hash>` and prepend it to the `DEBUG_DOMAIN`.
22+
23+
e.g. `http://testcluster--abcdefg.127.0.0.1.nip.io:8080/`

cmd/service-proxy/proxy.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net/http"
2525
"net/http/httputil"
2626
"net/url"
27+
"os"
2728
"regexp"
2829
"strings"
2930
"sync"
@@ -46,7 +47,9 @@ import (
4647

4748
func NewProxyManager() *ProxyManager {
4849
return &ProxyManager{
49-
clusters: make(map[string]clusterRoutes),
50+
dnsDomain: os.Getenv("GREENHOUSE_DNS_DOMAIN"),
51+
debugHost: os.Getenv("DEBUG_DOMAIN"),
52+
clusters: make(map[string]clusterRoutes),
5053
}
5154
}
5255

@@ -55,6 +58,10 @@ type ProxyManager struct {
5558
logger logr.Logger
5659
clusters map[string]clusterRoutes
5760
mu sync.RWMutex
61+
// dnsDomain used to construct exposed service URLs on the target greenhouse cluster
62+
dnsDomain string
63+
// debugshost used to override the domain for debugging exposed service URLs locally
64+
debugHost string
5865
}
5966

6067
type clusterRoutes struct {
@@ -132,6 +139,10 @@ func (pm *ProxyManager) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
132139
}
133140
for _, plugin := range plugins {
134141
for url, svc := range plugin.Status.ExposedServices {
142+
// If debugHost is set, replace the host on routes for local debugging
143+
if pm.debugHost != "" && pm.dnsDomain != "" {
144+
url = strings.ReplaceAll(url, pm.dnsDomain, pm.debugHost)
145+
}
135146
if svc.Type != greenhousev1alpha1.ServiceTypeService {
136147
continue
137148
}

0 commit comments

Comments
 (0)