Skip to content

Commit e3acb3a

Browse files
committed
[tests] Fix port-forward leak and LB retry off-by-one
- Add EXIT trap in run-kubernetes.sh to clean up port-forward process and tenantkubeconfig file on any exit path - Fix LoadBalancer retry loop: success on attempt 20 was falsely reported as failure due to $i -eq 20 check after break - Kill stale port-forward in bucket.bats before retry Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 18961de commit e3acb3a

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎hack/e2e-apps/bucket.bats‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Create the bucket resource with readwrite and readonly users
55
name='test'
66
kubectl -n tenant-test delete bucket.apps.cozystack.io $name --ignore-not-found --timeout=2m || true
7+
pkill -f "port-forward.*8333:" 2>/dev/null || true
78
kubectl apply -f - <<EOF
89
apiVersion: apps.cozystack.io/v1alpha1
910
kind: Bucket

‎hack/e2e-apps/run-kubernetes.sh‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ run_kubernetes_test() {
44
local port="$3"
55
local k8s_version=$(yq "$version_expr" packages/apps/kubernetes/files/versions.yaml)
66

7+
# Ensure port-forward and temp files are cleaned up on any exit
8+
trap 'pkill -f "port-forward.*${port}:" 2>/dev/null || true; rm -f "tenantkubeconfig-${test_name}"' EXIT
9+
710
# Clean up stale resources from a previous failed retry to ensure fresh provisioning
811
kubectl delete kuberneteses.apps.cozystack.io "${test_name}" \
912
-n tenant-test --ignore-not-found --timeout=2m || true
@@ -224,13 +227,17 @@ if [ -z "$LB_ADDR" ]; then
224227
exit 1
225228
fi
226229

230+
lb_ok=false
227231
for i in $(seq 1 20); do
228232
echo "Attempt $i"
229-
curl --silent --fail "http://${LB_ADDR}" && break
233+
if curl --silent --fail "http://${LB_ADDR}"; then
234+
lb_ok=true
235+
break
236+
fi
230237
sleep 3
231238
done
232239

233-
if [ "$i" -eq 20 ]; then
240+
if [ "$lb_ok" != true ]; then
234241
echo "LoadBalancer not reachable" >&2
235242
exit 1
236243
fi

0 commit comments

Comments
 (0)