@@ -143,40 +143,57 @@ install_envoy_gateway() {
143143}
144144
145145wait_for_envoy_service () {
146- local svc=" "
146+ local svc_ref=" "
147+ local svc_namespace=" "
147148
148149 for _ in $( seq 1 60) ; do
149- svc=" $( kctl -n " ${NAMESPACE} " get svc \
150- -l " gateway.envoyproxy.io/owning-gateway-name=${RELEASE_NAME} " \
151- -o jsonpath=' {.items[0].metadata.name}' 2> /dev/null || true) "
152- if [ -n " ${svc} " ]; then
153- printf ' %s\n' " ${svc} "
154- return 0
150+ svc_ref=" $( kctl get svc -A \
151+ -l " gateway.envoyproxy.io/owning-gateway-name=${RELEASE_NAME} ,gateway.envoyproxy.io/owning-gateway-namespace=${NAMESPACE} " \
152+ -o jsonpath=' {range .items[0]}{.metadata.namespace}{"/"}{.metadata.name}{end}' \
153+ 2> /dev/null || true) "
154+ if [ -n " ${svc_ref} " ]; then
155+ svc_namespace=" ${svc_ref%%/* } "
156+ if kctl -n " ${svc_namespace} " wait --for=condition=Ready pod \
157+ -l " gateway.envoyproxy.io/owning-gateway-name=${RELEASE_NAME} ,gateway.envoyproxy.io/owning-gateway-namespace=${NAMESPACE} " \
158+ --timeout=5s > /dev/null 2>&1 ; then
159+ printf ' %s\n' " ${svc_ref} "
160+ return 0
161+ fi
155162 fi
156163 sleep 2
157164 done
158165
159- echo " ERROR: Envoy proxy Service for Gateway ${RELEASE_NAME} was not created." >&2
160- kctl -n " ${NAMESPACE} " get gateway,grpcroute,svc -o wide >&2 || true
166+ echo " ERROR: Envoy proxy Service for Gateway ${RELEASE_NAME} was not ready." >&2
167+ kctl -n " ${NAMESPACE} " get gateway,grpcroute -o wide >&2 || true
168+ kctl get svc -A \
169+ -l " gateway.envoyproxy.io/owning-gateway-name=${RELEASE_NAME} ,gateway.envoyproxy.io/owning-gateway-namespace=${NAMESPACE} " \
170+ -o wide >&2 || true
171+ kctl get pods -A \
172+ -l " gateway.envoyproxy.io/owning-gateway-name=${RELEASE_NAME} ,gateway.envoyproxy.io/owning-gateway-namespace=${NAMESPACE} " \
173+ -o wide >&2 || true
161174 return 1
162175}
163176
164177start_gateway_portforward () {
165178 local elapsed=0
166179 local pf_timeout=30
167180 local target_port=8080
181+ local target_namespace=" ${NAMESPACE} "
168182 local target_service=" ${RELEASE_NAME} "
183+ local target_service_ref=" "
169184
170185 LOCAL_PORT=" $( e2e_pick_port) "
171186 if use_envoy_gateway; then
172- target_service=" $( wait_for_envoy_service) "
187+ target_service_ref=" $( wait_for_envoy_service) "
188+ target_namespace=" ${target_service_ref%%/* } "
189+ target_service=" ${target_service_ref#*/ } "
173190 target_port=80
174- echo " Starting kubectl port-forward svc/${target_service} ${LOCAL_PORT} :${target_port} (Envoy Gateway)..."
191+ echo " Starting kubectl port-forward -n ${target_namespace} svc/${target_service} ${LOCAL_PORT} :${target_port} (Envoy Gateway)..."
175192 else
176193 echo " Starting kubectl port-forward svc/${target_service} ${LOCAL_PORT} :${target_port} ..."
177194 fi
178195
179- kctl -n " ${NAMESPACE } " port-forward " svc/${target_service} " \
196+ kctl -n " ${target_namespace } " port-forward " svc/${target_service} " \
180197 " ${LOCAL_PORT} :${target_port} " > " ${PORTFORWARD_LOG} " 2>&1 &
181198 PORTFORWARD_PID=$!
182199
@@ -198,6 +215,21 @@ start_gateway_portforward() {
198215 return 1
199216}
200217
218+ stop_gateway_portforward () {
219+ [ -n " ${PORTFORWARD_PID} " ] || return 0
220+
221+ kill " ${PORTFORWARD_PID} " > /dev/null 2>&1 || true
222+ for _ in $( seq 1 10) ; do
223+ if ! kill -0 " ${PORTFORWARD_PID} " > /dev/null 2>&1 ; then
224+ break
225+ fi
226+ sleep 0.5
227+ done
228+ kill -KILL " ${PORTFORWARD_PID} " > /dev/null 2>&1 || true
229+ wait " ${PORTFORWARD_PID} " > /dev/null 2>&1 || true
230+ PORTFORWARD_PID=" "
231+ }
232+
201233cleanup_postgres_fixture () {
202234 local secret_name=" $1 "
203235
@@ -216,10 +248,7 @@ cleanup_postgres_fixture() {
216248cleanup () {
217249 local exit_code=$?
218250
219- if [ -n " ${PORTFORWARD_PID} " ]; then
220- kill " ${PORTFORWARD_PID} " > /dev/null 2>&1 || true
221- wait " ${PORTFORWARD_PID} " > /dev/null 2>&1 || true
222- fi
251+ stop_gateway_portforward
223252
224253 if [ " ${exit_code} " -ne 0 ] && [ -n " ${KUBE_CONTEXT} " ] && [ -n " ${NAMESPACE} " ]; then
225254 if command -v kubectl > /dev/null 2>&1 \
@@ -242,20 +271,6 @@ cleanup() {
242271 fi
243272 fi
244273
245- if [ " ${EXTERNAL_PG_FIXTURE_DEPLOYED} " = " 1" ]; then
246- cleanup_postgres_fixture " ${EXTERNAL_PG_FIXTURE_SECRET} "
247- fi
248-
249- if [ " ${ENVOY_GATEWAY_CONFIG_APPLIED} " = " 1" ] && [ -n " ${KUBE_CONTEXT} " ]; then
250- if command -v kubectl > /dev/null 2>&1 ; then
251- kctl -n " ${NAMESPACE} " delete backendtrafficpolicy.gateway.envoyproxy.io \
252- openshell-grpc-timeouts --ignore-not-found > /dev/null 2>&1 || true
253- kctl delete gatewayclass.gateway.networking.k8s.io eg \
254- --ignore-not-found > /dev/null 2>&1 || true
255- fi
256- ENVOY_GATEWAY_CONFIG_APPLIED=0
257- fi
258-
259274 if [ " ${HELM_INSTALLED} " = " 1" ] && [ -n " ${KUBE_CONTEXT} " ] && [ -n " ${NAMESPACE} " ]; then
260275 if command -v helm > /dev/null 2>&1 ; then
261276 helmctl uninstall " ${RELEASE_NAME} " --namespace " ${NAMESPACE} " --wait \
@@ -269,6 +284,21 @@ cleanup() {
269284 fi
270285 fi
271286
287+ if [ " ${EXTERNAL_PG_FIXTURE_DEPLOYED} " = " 1" ]; then
288+ cleanup_postgres_fixture " ${EXTERNAL_PG_FIXTURE_SECRET} "
289+ fi
290+
291+ if [ " ${ENVOY_GATEWAY_CONFIG_APPLIED} " = " 1" ] && [ -n " ${KUBE_CONTEXT} " ]; then
292+ if command -v kubectl > /dev/null 2>&1 ; then
293+ kctl -n " ${NAMESPACE} " delete backendtrafficpolicy.gateway.envoyproxy.io \
294+ openshell-grpc-timeouts --ignore-not-found --wait=false \
295+ > /dev/null 2>&1 || true
296+ kctl delete gatewayclass.gateway.networking.k8s.io eg \
297+ --ignore-not-found --wait=false > /dev/null 2>&1 || true
298+ fi
299+ ENVOY_GATEWAY_CONFIG_APPLIED=0
300+ fi
301+
272302 if [ " ${ENVOY_HELM_INSTALLED} " = " 1" ] && [ -n " ${KUBE_CONTEXT} " ]; then
273303 if command -v helm > /dev/null 2>&1 ; then
274304 helmctl uninstall " ${ENVOY_RELEASE_NAME} " --namespace " ${ENVOY_NAMESPACE} " \
@@ -296,11 +326,7 @@ trap cleanup EXIT
296326# --- DB-scenario helpers (used only when OPENSHELL_E2E_KUBE_DB_SCENARIOS=1) ---
297327
298328scenario_stop_portforward () {
299- if [ -n " ${PORTFORWARD_PID} " ]; then
300- kill " ${PORTFORWARD_PID} " > /dev/null 2>&1 || true
301- wait " ${PORTFORWARD_PID} " > /dev/null 2>&1 || true
302- PORTFORWARD_PID=" "
303- fi
329+ stop_gateway_portforward
304330}
305331
306332scenario_cleanup_release () {
0 commit comments