python-k8s-e2e-ingress.sh
1 #!/bin/bash 2 # Copyright 2026 Alibaba Group Holding Ltd. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 # Kubernetes E2E (Python) with server ingress.mode=gateway and the chart-deployed 17 # ingress-gateway (components/ingress). See kubernetes/charts/opensandbox-server/README.md. 18 # 19 # Compared to scripts/python-k8s-e2e.sh: 20 # - Builds/opensandbox/ingress image and sets server.gateway.* so Helm deploys opensandbox-ingress-gateway. 21 # - Port-forwards both the lifecycle API and the gateway. 22 # - Sets OPENSANDBOX_TEST_USE_SERVER_PROXY=false so the SDK uses gateway routes + headers from the API. 23 # 24 # Route mode (Helm server.gateway.gatewayRouteMode + ingress --mode): 25 # Default header. For URI path routing: E2E_GATEWAY_ROUTE_MODE=uri ./scripts/python-k8s-e2e-ingress.sh 26 27 set -euxo pipefail 28 29 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 30 # shellcheck source=common/kubernetes-e2e.sh 31 source "${SCRIPT_DIR}/common/kubernetes-e2e.sh" 32 33 REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" 34 35 export E2E_SERVER_GATEWAY_ENABLED=true 36 export E2E_GATEWAY_ROUTE_MODE="${E2E_GATEWAY_ROUTE_MODE:-header}" 37 38 KIND_CLUSTER="${KIND_CLUSTER:-opensandbox-e2e}" 39 KIND_K8S_VERSION="${KIND_K8S_VERSION:-v1.30.4}" 40 KUBECONFIG_PATH="${KUBECONFIG_PATH:-/tmp/opensandbox-kind-kubeconfig}" 41 E2E_NAMESPACE="${E2E_NAMESPACE:-opensandbox-e2e}" 42 SERVER_NAMESPACE="${SERVER_NAMESPACE:-opensandbox-system}" 43 PVC_NAME="${PVC_NAME:-opensandbox-e2e-pvc-test}" 44 PV_NAME="${PV_NAME:-opensandbox-e2e-pv-test}" 45 CONTROLLER_IMG="${CONTROLLER_IMG:-opensandbox/controller:e2e-local}" 46 SERVER_IMG="${SERVER_IMG:-opensandbox/server:e2e-local}" 47 EXECD_IMG="${EXECD_IMG:-opensandbox/execd:e2e-local}" 48 EGRESS_IMG="${EGRESS_IMG:-opensandbox/egress:e2e-local}" 49 INGRESS_IMG="${INGRESS_IMG:-opensandbox/ingress:e2e-local}" 50 SERVER_RELEASE="${SERVER_RELEASE:-opensandbox-server}" 51 SERVER_VALUES_FILE="${SERVER_VALUES_FILE:-/tmp/opensandbox-server-values-ingress.yaml}" 52 PORT_FORWARD_LOG="${PORT_FORWARD_LOG:-/tmp/opensandbox-server-port-forward.log}" 53 GATEWAY_PORT_FORWARD_LOG="${GATEWAY_PORT_FORWARD_LOG:-/tmp/opensandbox-ingress-gateway-port-forward.log}" 54 SANDBOX_TEST_IMAGE="${SANDBOX_TEST_IMAGE:-ubuntu:latest}" 55 56 GATEWAY_LOCAL_PORT="${GATEWAY_LOCAL_PORT:-8081}" 57 INGRESS_GATEWAY_ADDRESS="${INGRESS_GATEWAY_ADDRESS:-127.0.0.1:${GATEWAY_LOCAL_PORT}}" 58 LIFECYCLE_LOCAL_PORT="${LIFECYCLE_LOCAL_PORT:-8080}" 59 60 SERVER_IMG_REPOSITORY="${SERVER_IMG%:*}" 61 SERVER_IMG_TAG="${SERVER_IMG##*:}" 62 INGRESS_IMG_REPOSITORY="${INGRESS_IMG%:*}" 63 INGRESS_IMG_TAG="${INGRESS_IMG##*:}" 64 65 k8s_e2e_export_kubeconfig 66 k8s_e2e_setup_kind_and_controller 67 k8s_e2e_build_runtime_images 68 k8s_e2e_kind_load_runtime_images 69 k8s_e2e_apply_pvc_and_seed 70 k8s_e2e_write_server_helm_values 71 k8s_e2e_helm_install_server 72 73 kubectl port-forward -n "${SERVER_NAMESPACE}" svc/opensandbox-server "${LIFECYCLE_LOCAL_PORT}:80" >"${PORT_FORWARD_LOG}" 2>&1 & 74 PORT_FORWARD_PID=$! 75 kubectl port-forward -n "${SERVER_NAMESPACE}" svc/opensandbox-ingress-gateway "${GATEWAY_LOCAL_PORT}:80" >"${GATEWAY_PORT_FORWARD_LOG}" 2>&1 & 76 GATEWAY_PORT_FORWARD_PID=$! 77 cleanup_port_forwards() { 78 kill "${PORT_FORWARD_PID}" >/dev/null 2>&1 || true 79 kill "${GATEWAY_PORT_FORWARD_PID}" >/dev/null 2>&1 || true 80 } 81 trap cleanup_port_forwards EXIT 82 83 k8s_e2e_wait_http_ok "http://127.0.0.1:${LIFECYCLE_LOCAL_PORT}/health" 84 k8s_e2e_wait_http_ok "http://127.0.0.1:${GATEWAY_LOCAL_PORT}/status.ok" 85 86 export OPENSANDBOX_TEST_DOMAIN="localhost:${LIFECYCLE_LOCAL_PORT}" 87 export OPENSANDBOX_TEST_PROTOCOL="http" 88 export OPENSANDBOX_TEST_API_KEY="kubernetes-e2e" 89 export OPENSANDBOX_SANDBOX_DEFAULT_IMAGE="${SANDBOX_TEST_IMAGE}" 90 export OPENSANDBOX_E2E_RUNTIME="kubernetes" 91 export OPENSANDBOX_TEST_USE_SERVER_PROXY="false" 92 export OPENSANDBOX_TEST_SECURE_ACCESS_VERIFIABLE="true" 93 export OPENSANDBOX_TEST_PVC_NAME="${PVC_NAME}" 94 95 k8s_e2e_export_sandbox_resource_env 96 97 k8s_e2e_generate_sdk_and_run_kubernetes_mini