Skip to content

Commit c399342

Browse files
authored
feat(dev): unify local Kubernetes gateway workflow (#2914)
Make the local k3s gateway workflow match the Docker and Podman flows by registering and selecting successful plaintext Skaffold deployments with the OpenShell CLI. Derive the registration name from the worktree-specific k3d cluster name so parallel worktrees retain independent gateway metadata. Add helm:k3s:forward as the standard way to expose the Kubernetes gateway on localhost:8090, and update the development and debugging guidance to use the active registered gateway instead of one-off endpoint flags. Signed-off-by: Kris Hicks <khicks@nvidia.com>
1 parent 8d16a59 commit c399342

4 files changed

Lines changed: 87 additions & 13 deletions

File tree

‎.agents/skills/debug-openshell-cluster/SKILL.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,14 @@ kubectl -n openshell get endpoints openshell
435435
For local port-forward testing:
436436

437437
```bash
438-
kubectl -n openshell port-forward svc/openshell 8080:8080
439-
openshell gateway add http://127.0.0.1:8080 --local --name local
438+
mise run helm:k3s:forward
439+
openshell gateway list
440440
openshell status
441441
```
442442

443+
A successful plaintext `helm:skaffold:run` registers and selects the local
444+
gateway; the forwarding task does not modify gateway metadata.
445+
443446
If the gateway is healthy but sandbox creation fails:
444447

445448
```bash

‎.agents/skills/helm-dev-environment/SKILL.md‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,17 @@ sidecar-mTLS profile reuses `ci/values-sidecar.yaml` and restores
8181
Job that runs `openshell-gateway generate-certs`) generates mTLS secrets on first
8282
install. Envoy Gateway opt-in; see the Optional Add-ons section below.
8383

84-
The gateway Service uses ClusterIP. Access is via Envoy Gateway (port `8080`) or `kubectl port-forward`.
84+
The gateway Service uses ClusterIP. Access is via Envoy Gateway (port `8080`) or
85+
the local forwarding task:
86+
87+
```bash
88+
mise run helm:k3s:forward
89+
```
90+
91+
The task forwards the Kubernetes gateway to `http://127.0.0.1:8090`. A
92+
successful plaintext `helm:skaffold:run` or `helm:skaffold:run:sidecar`
93+
registers and selects the gateway under the worktree-specific k3d cluster name.
94+
Keep the forwarding task running while using the endpoint.
8595

8696
**HA test deploy** (two gateway replicas + external PostgreSQL Secret): uncomment
8797
`#- ci/values-high-availability.yaml` in `deploy/helm/openshell/skaffold.yaml`,
@@ -99,19 +109,20 @@ plaintext by default. To test sidecar topology with TLS enabled, use
99109
| Skaffold dev (default) | `true` | `http://` |
100110
| TLS enabled | `false` (or omitted) | `https://` |
101111

102-
### Connecting via port-forward
112+
### Connecting through the forwarding task
103113

104-
Port `8080` is already bound by the k3d load balancer when Envoy Gateway is active, so
105-
the port-forward uses local port `8090` to avoid a collision:
114+
Port `8080` is already bound by the k3d load balancer when Envoy Gateway is
115+
active, so the forwarding task uses local port `8090` for the gateway. In a
116+
second terminal, confirm that the gateway is registered and active:
106117

107118
```bash
108-
KUBECONFIG=kubeconfig kubectl port-forward -n openshell svc/openshell 8090:8080
119+
openshell gateway list
109120
```
110121

111122
**Plaintext (default Skaffold deploy):**
112123

113124
```bash
114-
openshell sandbox list --gateway-endpoint http://localhost:8090
125+
openshell sandbox list
115126
```
116127

117128
**With mTLS enabled** — extract the client cert the PKI hook wrote to the cluster,

‎tasks/helm.toml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ dir = "deploy/helm/openshell"
6969
run = "skaffold dev -p sidecar-mtls"
7070

7171
["helm:skaffold:run"]
72-
description = "Run skaffold run for deploy/helm/openshell (one-shot deploy)"
72+
description = "Run a one-shot Skaffold deploy and register its local plaintext gateway"
7373
dir = "deploy/helm/openshell"
74-
run = "skaffold run"
74+
run = "skaffold run && ../../../tasks/scripts/helm-k3s-local.sh register"
7575

7676
["helm:skaffold:run:sidecar"]
77-
description = "Run skaffold run with the Kubernetes supervisor sidecar topology"
77+
description = "Run a sidecar Skaffold deploy and register its local plaintext gateway"
7878
dir = "deploy/helm/openshell"
79-
run = "skaffold run -p sidecar"
79+
run = "skaffold run -p sidecar && ../../../tasks/scripts/helm-k3s-local.sh register"
8080

8181
["helm:skaffold:run:sidecar-mtls"]
8282
description = "Run skaffold run with the Kubernetes supervisor sidecar topology and TLS/mTLS enabled"
@@ -130,6 +130,10 @@ description = "List local k3d clusters"
130130
run = "tasks/scripts/helm-k3s-local.sh status"
131131
hide = true
132132

133+
["helm:k3s:forward"]
134+
description = "Forward the local Kubernetes gateway to port 8090"
135+
run = "tasks/scripts/helm-k3s-local.sh forward"
136+
133137
# Install Envoy Gateway's GatewayClass into the cluster
134138

135139
["helm:gateway:apply"]

‎tasks/scripts/helm-k3s-local.sh‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ PRELOAD_SANDBOX_IMAGE="${HELM_K3S_PRELOAD_SANDBOX_IMAGE-${DEFAULT_SANDBOX_PRELOA
3838
# exercise the v1alpha1 controller release.
3939
AGENT_SANDBOX_VERSION="${AGENT_SANDBOX_VERSION:-v0.5.0}"
4040

41+
# Host endpoint registered for the Skaffold-deployed gateway. Derive the
42+
# gateway name from the worktree-specific cluster name so concurrent local
43+
# clusters do not overwrite each other's CLI metadata.
44+
GATEWAY_NAMESPACE="openshell"
45+
GATEWAY_HOST_PORT="${HELM_K3S_GATEWAY_HOST_PORT:-8090}"
46+
GATEWAY_NAME="${HELM_K3S_GATEWAY_NAME:-${CLUSTER_NAME}}"
47+
4148
default_kubeconfig="${ROOT}/kubeconfig"
4249
if [[ -n "${HELM_K3S_KUBECONFIG:-}" ]]; then
4350
KUBECONFIG_TARGET="${HELM_K3S_KUBECONFIG}"
@@ -54,7 +61,7 @@ fi
5461

5562
usage() {
5663
cat >&2 <<EOF
57-
usage: $(basename "$0") <create|delete|start|stop|status>
64+
usage: $(basename "$0") <create|delete|start|stop|status|register|forward>
5865
5966
Environment:
6067
HELM_K3S_CLUSTER_NAME k3d cluster name (default: openshell-dev-<branch-suffix>)
@@ -65,6 +72,9 @@ Environment:
6572
HELM_K3S_PRELOAD_SANDBOX_IMAGE
6673
Sandbox image to docker pull and import into k3d
6774
(default: ${DEFAULT_SANDBOX_PRELOAD_IMAGE}; set empty to skip)
75+
HELM_K3S_GATEWAY_HOST_PORT Host port forwarded to the gateway (default: 8090)
76+
HELM_K3S_GATEWAY_NAME CLI gateway registration name
77+
(default: worktree-specific k3d cluster name)
6878
6979
macOS uses k3d from mise (Docker required). Linux can use this flow only when
7080
k3d is installed explicitly; otherwise use kind or an existing cluster context.
@@ -312,6 +322,50 @@ cmd_status() {
312322
k3d cluster list
313323
}
314324

325+
register_local_gateway() {
326+
local config_home openshell_dir gateway_dir endpoint
327+
328+
if [[ ! "${GATEWAY_NAME}" =~ ^[A-Za-z0-9._-]+$ ]]; then
329+
echo "error: HELM_K3S_GATEWAY_NAME must contain only letters, numbers, dots, underscores, or dashes" >&2
330+
return 2
331+
fi
332+
333+
config_home="${XDG_CONFIG_HOME:-${HOME}/.config}"
334+
openshell_dir="${config_home}/openshell"
335+
gateway_dir="${openshell_dir}/gateways/${GATEWAY_NAME}"
336+
endpoint="http://127.0.0.1:${GATEWAY_HOST_PORT}"
337+
338+
mkdir -p "${gateway_dir}"
339+
chmod 700 "${gateway_dir}" 2>/dev/null || true
340+
cat >"${gateway_dir}/metadata.json" <<EOF
341+
{
342+
"name": "${GATEWAY_NAME}",
343+
"gateway_endpoint": "${endpoint}",
344+
"is_remote": false,
345+
"gateway_port": ${GATEWAY_HOST_PORT},
346+
"auth_mode": "plaintext"
347+
}
348+
EOF
349+
chmod 600 "${gateway_dir}/metadata.json" 2>/dev/null || true
350+
printf '%s' "${GATEWAY_NAME}" >"${openshell_dir}/active_gateway"
351+
chmod 600 "${openshell_dir}/active_gateway" 2>/dev/null || true
352+
353+
echo "Registered and selected local gateway '${GATEWAY_NAME}' at ${endpoint}."
354+
}
355+
356+
cmd_forward() {
357+
require_supported_os
358+
require_kubectl
359+
360+
echo "Forwarding gateway to http://127.0.0.1:${GATEWAY_HOST_PORT}"
361+
echo "Press Ctrl-C to stop."
362+
kubectl \
363+
--kubeconfig="${KUBECONFIG_TARGET}" \
364+
--context="$(k3d_context_name)" \
365+
--namespace="${GATEWAY_NAMESPACE}" \
366+
port-forward service/openshell "${GATEWAY_HOST_PORT}:8080"
367+
}
368+
315369
main() {
316370
local sub="${1:-}"
317371
case "${sub}" in
@@ -320,6 +374,8 @@ main() {
320374
start) cmd_start ;;
321375
stop) cmd_stop ;;
322376
status) cmd_status ;;
377+
register) register_local_gateway ;;
378+
forward) cmd_forward ;;
323379
-h | --help | help | "") usage ; [[ -n "${sub}" ]] || exit 1 ;;
324380
*)
325381
echo "error: unknown command '${sub}'" >&2

0 commit comments

Comments
 (0)