Skip to content

Commit 882a767

Browse files
committed
test(helm-e2e): run host-gateway tests on the kube driver
Six tests previously skipped on the kubernetes driver — three in host_gateway_alias.rs plus the forward_proxy_l7 + graphql_l7 cases — relied on `host.openshell.internal` reaching either a host process or a sibling docker container. The Helm chart already supports this via `server.hostGatewayIP`, but the e2e wrapper never set it. - with-kube-gateway.sh: auto-detect the host-routable IP (CoreDNS `host.k3d.internal` first to handle Docker Desktop, docker network gateway as a fallback for kind on Linux CI) and pass it to helm install. Also import locally-built images into existing k3d clusters and wait for namespace deletion to complete before exit. - e2e/rust/Cargo.toml + e2e-helm.sh: add an `e2e-host-gateway` feature that gates the three test files; docker and podman runs imply it, helm runs opt in by default (overridable via OPENSHELL_E2E_HELM_FEATURES for remote clusters where the test host is unreachable from pods). - Drop the `skip_if_kube` helper and its callers — feature gating now decides whether the tests compile in. Verified against a local k3d cluster: all six previously-skipped tests pass, smoke regression intact.
1 parent 7c6abc5 commit 882a767

8 files changed

Lines changed: 118 additions & 51 deletions

File tree

‎e2e/rust/Cargo.toml‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ publish = false
1717

1818
[features]
1919
e2e = []
20-
e2e-docker = ["e2e"]
20+
# Selects tests that rely on `host.openshell.internal` (the sandbox's stable
21+
# alias to the host running test fixtures). docker and podman wire the alias
22+
# unconditionally; the kube driver only does so when the chart's
23+
# `server.hostGatewayIP` is set, so `e2e-kubernetes` does NOT imply this and
24+
# the helm wrapper opts in explicitly when it has resolved an IP.
25+
e2e-host-gateway = ["e2e"]
26+
e2e-docker = ["e2e", "e2e-host-gateway"]
2127
e2e-gpu = ["e2e"]
2228
e2e-docker-gpu = ["e2e-docker", "e2e-gpu"]
2329
e2e-kubernetes = ["e2e"]
24-
e2e-podman = ["e2e"]
30+
e2e-podman = ["e2e", "e2e-host-gateway"]
2531
e2e-podman-gpu = ["e2e-podman", "e2e-gpu"]
2632

2733
[[test]]
@@ -44,6 +50,21 @@ name = "user_namespaces"
4450
path = "tests/user_namespaces.rs"
4551
required-features = ["e2e-kubernetes"]
4652

53+
[[test]]
54+
name = "host_gateway_alias"
55+
path = "tests/host_gateway_alias.rs"
56+
required-features = ["e2e-host-gateway"]
57+
58+
[[test]]
59+
name = "forward_proxy_l7_bypass"
60+
path = "tests/forward_proxy_l7_bypass.rs"
61+
required-features = ["e2e-host-gateway"]
62+
63+
[[test]]
64+
name = "forward_proxy_graphql_l7"
65+
path = "tests/forward_proxy_graphql_l7.rs"
66+
required-features = ["e2e-host-gateway"]
67+
4768
[[test]]
4869
name = "gpu_device_selection"
4970
path = "tests/gpu_device_selection.rs"

‎e2e/rust/e2e-helm.sh‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77
# ephemeral k3d cluster is created and torn down by with-kube-gateway.sh.
88
# Set OPENSHELL_E2E_KUBE_TEST to scope to a single integration test
99
# (e.g. smoke) for local debugging.
10+
#
11+
# Features: the default set includes `e2e-host-gateway` so tests that rely on
12+
# the sandbox-side `host.openshell.internal` alias compile and run. The Helm
13+
# wrapper detects the cluster's host-routable IP and wires it into the chart
14+
# via `server.hostGatewayIP`. Targeting a cluster where the test host is
15+
# unreachable from pods? Set OPENSHELL_E2E_HELM_FEATURES=e2e to drop the
16+
# alias-dependent tests entirely.
1017

1118
set -euo pipefail
1219

1320
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
1421

22+
E2E_FEATURES="${OPENSHELL_E2E_HELM_FEATURES:-e2e,e2e-host-gateway}"
23+
1524
cargo build -p openshell-cli --features openshell-core/dev-settings
1625

1726
test_filter=()
@@ -21,7 +30,7 @@ fi
2130

2231
exec "${ROOT}/e2e/with-kube-gateway.sh" \
2332
cargo test --manifest-path "${ROOT}/e2e/rust/Cargo.toml" \
24-
--features e2e \
33+
--features "${E2E_FEATURES}" \
2534
--no-fail-fast \
2635
${test_filter[@]+"${test_filter[@]}"} \
2736
-- --nocapture

‎e2e/rust/src/harness/driver.rs‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎e2e/rust/src/harness/mod.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
pub mod binary;
77
pub mod container;
8-
pub mod driver;
98
pub mod gateway;
109
pub mod output;
1110
pub mod port;

‎e2e/rust/tests/forward_proxy_graphql_l7.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use std::io::Write;
1414

1515
use openshell_e2e::harness::container::ContainerHttpServer;
16-
use openshell_e2e::harness::driver::skip_if_kube;
1716
use openshell_e2e::harness::sandbox::SandboxGuard;
1817
use tempfile::NamedTempFile;
1918

@@ -132,9 +131,6 @@ network_policies:
132131
#[tokio::test]
133132
#[allow(clippy::too_many_lines)]
134133
async fn graphql_l7_enforces_allow_and_deny_rules_on_forward_and_connect_paths() {
135-
if skip_if_kube("uses host.openshell.internal to reach a sibling container") {
136-
return;
137-
}
138134
let server = start_test_server().await.expect("start test server");
139135
let policy = write_graphql_policy(&server.host, server.port).expect("write custom policy");
140136
let policy_path = policy

‎e2e/rust/tests/forward_proxy_l7_bypass.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use std::io::Write;
1212

1313
use openshell_e2e::harness::container::ContainerHttpServer;
14-
use openshell_e2e::harness::driver::skip_if_kube;
1514
use openshell_e2e::harness::sandbox::SandboxGuard;
1615
use tempfile::NamedTempFile;
1716

@@ -99,9 +98,6 @@ network_policies:
9998
/// GET /allowed should succeed — the L7 policy explicitly allows it.
10099
#[tokio::test]
101100
async fn forward_proxy_allows_l7_permitted_request() {
102-
if skip_if_kube("uses host.openshell.internal to reach a sibling container") {
103-
return;
104-
}
105101
let server = start_test_server().await.expect("start test server");
106102
let policy =
107103
write_policy_with_l7_rules(&server.host, server.port).expect("write custom policy");
@@ -142,9 +138,6 @@ except Exception as e:
142138
/// POST /allowed should be denied — the L7 policy only allows GET.
143139
#[tokio::test]
144140
async fn forward_proxy_denies_l7_blocked_request() {
145-
if skip_if_kube("uses host.openshell.internal to reach a sibling container") {
146-
return;
147-
}
148141
let server = start_test_server().await.expect("start test server");
149142
let policy =
150143
write_policy_with_l7_rules(&server.host, server.port).expect("write custom policy");

‎e2e/rust/tests/host_gateway_alias.rs‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::process::Stdio;
88
use std::sync::Mutex;
99

1010
use openshell_e2e::harness::binary::openshell_cmd;
11-
use openshell_e2e::harness::driver::skip_if_kube;
1211
use openshell_e2e::harness::sandbox::SandboxGuard;
1312
use tempfile::NamedTempFile;
1413
use tokio::io::AsyncReadExt;
@@ -191,9 +190,6 @@ network_policies:
191190

192191
#[tokio::test]
193192
async fn sandbox_reaches_host_openshell_internal_via_host_gateway_alias() {
194-
if skip_if_kube("requires host.openshell.internal alias") {
195-
return;
196-
}
197193
let server = HostServer::start(r#"{"message":"hello-from-host"}"#)
198194
.await
199195
.expect("start host echo server");
@@ -229,9 +225,6 @@ async fn sandbox_reaches_host_openshell_internal_via_host_gateway_alias() {
229225

230226
#[tokio::test]
231227
async fn sandbox_inference_local_routes_to_host_openshell_internal() {
232-
if skip_if_kube("requires host.openshell.internal alias") {
233-
return;
234-
}
235228
let _inference_lock = INFERENCE_ROUTE_LOCK
236229
.lock()
237230
.unwrap_or_else(std::sync::PoisonError::into_inner);
@@ -308,9 +301,6 @@ async fn sandbox_inference_local_routes_to_host_openshell_internal() {
308301

309302
#[tokio::test]
310303
async fn inference_set_supports_no_verify_for_unreachable_endpoint() {
311-
if skip_if_kube("uses host.openshell.internal as the unreachable target") {
312-
return;
313-
}
314304
let _inference_lock = INFERENCE_ROUTE_LOCK
315305
.lock()
316306
.unwrap_or_else(std::sync::PoisonError::into_inner);

‎e2e/with-kube-gateway.sh‎

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ cleanup() {
9191
--timeout 60s >/dev/null 2>&1 || true
9292
fi
9393
if command -v kubectl >/dev/null 2>&1; then
94-
kctl delete namespace "${NAMESPACE}" --wait=false \
94+
# Wait for the namespace to fully delete so back-to-back runs don't hit
95+
# "namespace is being terminated" when helm install creates it again.
96+
kctl delete namespace "${NAMESPACE}" --wait=true --timeout=60s \
9597
--ignore-not-found >/dev/null 2>&1 || true
9698
fi
9799
fi
@@ -142,16 +144,87 @@ IMAGE_TAG_VALUE="${IMAGE_TAG:-latest}"
142144
REGISTRY_VALUE="${OPENSHELL_REGISTRY:-ghcr.io/nvidia/openshell}"
143145
REGISTRY_VALUE="${REGISTRY_VALUE%/}"
144146

145-
# When this script created the cluster, import locally-available gateway and
146-
# supervisor images so devs without a registry login can iterate. Best-effort:
147-
# missing images fall through to the cluster's pull behavior at install time.
147+
# Resolve a host-gateway IP that sandbox pods can dial to reach test fixtures
148+
# running on the developer/CI host (HTTP fixtures bound to 0.0.0.0 plus sibling
149+
# Docker containers with published ports). The Helm chart wires this into pod
150+
# hostAliases for host.openshell.internal / host.docker.internal — without it,
151+
# every test that relies on the alias has to skip on the kube driver.
152+
#
153+
# Preference order:
154+
# 1. OPENSHELL_E2E_HOST_GATEWAY_IP — operator override (remote clusters where
155+
# auto-detection has no signal).
156+
# 2. Gateway of the cluster's Docker network (k3d-<cluster> for ephemeral
157+
# clusters, `kind` for kind clusters used in CI). Pods SNAT through their
158+
# node to this IP, which lands on the host's bridge interface and reaches
159+
# any 0.0.0.0-bound listener / published container port.
160+
HOST_GATEWAY_IP="${OPENSHELL_E2E_HOST_GATEWAY_IP:-}"
161+
162+
# k3d primes CoreDNS with `host.k3d.internal` pointing at the IP that pods can
163+
# use to reach the host (Docker Desktop's gvisor-net loopback on macOS/Windows,
164+
# the docker bridge gateway on Linux). That mapping handles Docker Desktop
165+
# correctly; the docker network gateway alone does not.
166+
if [ -z "${HOST_GATEWAY_IP}" ] && command -v kubectl >/dev/null 2>&1; then
167+
detected="$(kctl -n kube-system get configmap coredns -o jsonpath='{.data.NodeHosts}' 2>/dev/null \
168+
| awk '$2 == "host.k3d.internal" { print $1; exit }')"
169+
if [ -n "${detected}" ]; then
170+
HOST_GATEWAY_IP="${detected}"
171+
echo "Detected host gateway IP ${HOST_GATEWAY_IP} from CoreDNS host.k3d.internal entry."
172+
fi
173+
fi
174+
175+
# Fallback for non-k3d clusters (kind in CI, etc.): use the docker network
176+
# gateway IP. Works on Linux where the bridge is reachable from pods; on macOS
177+
# Docker Desktop without k3d, this will likely not route to the host.
178+
if [ -z "${HOST_GATEWAY_IP}" ] && command -v docker >/dev/null 2>&1; then
179+
candidate_networks=()
180+
if [ "${CLUSTER_CREATED_BY_US}" = "1" ]; then
181+
candidate_networks+=("k3d-${CLUSTER_NAME}")
182+
elif [[ "${KUBE_CONTEXT}" == k3d-* ]]; then
183+
candidate_networks+=("k3d-${KUBE_CONTEXT#k3d-}")
184+
elif [[ "${KUBE_CONTEXT}" == kind-* ]]; then
185+
candidate_networks+=("kind")
186+
else
187+
candidate_networks+=("kind" "k3d-${KUBE_CONTEXT#k3d-}")
188+
fi
189+
for net in "${candidate_networks[@]}"; do
190+
[ -n "${net}" ] || continue
191+
detected="$(docker network inspect "${net}" \
192+
-f '{{range .IPAM.Config}}{{.Gateway}}{{"\n"}}{{end}}' 2>/dev/null \
193+
| awk 'NF { print; exit }')"
194+
if [ -n "${detected}" ]; then
195+
HOST_GATEWAY_IP="${detected}"
196+
echo "Detected host gateway IP ${HOST_GATEWAY_IP} from docker network '${net}'."
197+
break
198+
fi
199+
done
200+
fi
201+
if [ -z "${HOST_GATEWAY_IP}" ]; then
202+
echo "WARNING: could not resolve a host gateway IP for the active cluster." >&2
203+
echo " Tests that require host.openshell.internal will be skipped." >&2
204+
echo " Set OPENSHELL_E2E_HOST_GATEWAY_IP to override." >&2
205+
fi
206+
207+
# Import locally-available gateway/supervisor images into the k3d cluster so
208+
# devs working off local builds don't depend on the configured registry. For
209+
# kind clusters (used by CI), images must be loaded before this script runs —
210+
# the workflow handles that via `kind load docker-image`. Best-effort: when an
211+
# image isn't present locally, the cluster falls back to its pull behavior.
212+
import_cluster_name=""
148213
if [ "${CLUSTER_CREATED_BY_US}" = "1" ]; then
214+
import_cluster_name="${CLUSTER_NAME}"
215+
elif [[ "${KUBE_CONTEXT}" == k3d-* ]] && command -v k3d >/dev/null 2>&1; then
216+
candidate="${KUBE_CONTEXT#k3d-}"
217+
if k3d cluster list "${candidate}" >/dev/null 2>&1; then
218+
import_cluster_name="${candidate}"
219+
fi
220+
fi
221+
if [ -n "${import_cluster_name}" ]; then
149222
for image in \
150223
"${REGISTRY_VALUE}/gateway:${IMAGE_TAG_VALUE}" \
151224
"${REGISTRY_VALUE}/supervisor:${IMAGE_TAG_VALUE}"; do
152225
if docker image inspect "${image}" >/dev/null 2>&1; then
153-
echo "Importing ${image} into k3d cluster ${CLUSTER_NAME}..."
154-
k3d image import "${image}" --cluster "${CLUSTER_NAME}" \
226+
echo "Importing ${image} into k3d cluster ${import_cluster_name}..."
227+
k3d image import "${image}" --cluster "${import_cluster_name}" \
155228
--mode direct >/dev/null
156229
fi
157230
done
@@ -165,6 +238,11 @@ kctl apply -f "${ROOT}/deploy/kube/manifests/agent-sandbox.yaml"
165238
kctl wait --for=condition=Established crd/sandboxes.agents.x-k8s.io --timeout=120s
166239
kctl -n agent-sandbox-system rollout status statefulset/agent-sandbox-controller --timeout=300s
167240

241+
helm_extra_args=()
242+
if [ -n "${HOST_GATEWAY_IP}" ]; then
243+
helm_extra_args+=(--set "server.hostGatewayIP=${HOST_GATEWAY_IP}")
244+
fi
245+
168246
echo "Installing Helm chart (release=${RELEASE_NAME}, namespace=${NAMESPACE}, tag=${IMAGE_TAG_VALUE})..."
169247
helmctl install "${RELEASE_NAME}" "${ROOT}/deploy/helm/openshell" \
170248
--namespace "${NAMESPACE}" --create-namespace \
@@ -174,6 +252,7 @@ helmctl install "${RELEASE_NAME}" "${ROOT}/deploy/helm/openshell" \
174252
--set "image.tag=${IMAGE_TAG_VALUE}" \
175253
--set "supervisor.image.repository=${REGISTRY_VALUE}/supervisor" \
176254
--set "supervisor.image.tag=${IMAGE_TAG_VALUE}" \
255+
"${helm_extra_args[@]}" \
177256
--wait --timeout 5m
178257
HELM_INSTALLED=1
179258

0 commit comments

Comments
 (0)