Skip to content

Commit a8ed016

Browse files
authored
fix(test): Fix flaky e2e tests (#560)
* fix(test): Fix `get-nb-id` script to retrieve IP directly from service status Signed-off-by: Moshe Vayner <moshe@vayner.me> * fix(test): Replace hard sleeps with polling loops in flaky e2e tests Two tests were doing a fixed sleep after annotating a service, then making a single API call to verify CCM had reconciled. Replace both with the established polling pattern (10 retries × 10s) used across the rest of the e2e suite. Signed-off-by: Moshe Vayner <moshe@vayner.me> --------- Signed-off-by: Moshe Vayner <moshe@vayner.me>
1 parent b1427c6 commit a8ed016

3 files changed

Lines changed: 40 additions & 30 deletions

File tree

e2e/test/lb-with-proxyprotocol-override/chainsaw-test.yaml

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ spec:
4343
set -euo pipefail
4444
kubectl annotate svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-port-80='{"proxy-protocol": "v1"}'
4545
kubectl annotate svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-port-8080='{"proxy-protocol": "v2"}'
46-
sleep 10
4746
- name: Check NodeBalancerConfig for port 80 to have ProxyProtocol v1 and port 8080 to have ProxyProtocol v2
4847
try:
4948
- script:
@@ -52,19 +51,23 @@ spec:
5251
5352
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
5453
55-
nbconfig=$(curl -s \
56-
-H "Authorization: Bearer $LINODE_TOKEN" \
57-
-H "Content-Type: application/json" --fail-early --retry 3 \
58-
"$LINODE_URL/v4/nodebalancers/$nbid/configs")
54+
for i in {1..10}; do
55+
nbconfig=$(curl -s \
56+
-H "Authorization: Bearer $LINODE_TOKEN" \
57+
-H "Content-Type: application/json" --fail-early --retry 3 \
58+
"$LINODE_URL/v4/nodebalancers/$nbid/configs")
5959
60-
port_80_v1=$(echo $nbconfig | jq -r '.data[] | select(.port == 80) | .proxy_protocol == "v1"')
61-
port_8080_v2=$(echo $nbconfig | jq -r '.data[] | select(.port == 8080) | .proxy_protocol == "v2"')
60+
port_80_v1=$(echo $nbconfig | jq -r '.data[] | select(.port == 80) | .proxy_protocol == "v1"')
61+
port_8080_v2=$(echo $nbconfig | jq -r '.data[] | select(.port == 8080) | .proxy_protocol == "v2"')
6262
63-
if [[ $port_80_v1 == "true" && $port_8080_v2 == "true" ]]; then
64-
echo "Conditions met"
65-
else
66-
echo "Conditions not met"
67-
fi
63+
if [[ $port_80_v1 == "true" && $port_8080_v2 == "true" ]]; then
64+
echo "Conditions met"
65+
break
66+
else
67+
echo "Conditions not met"
68+
fi
69+
sleep 10
70+
done
6871
check:
6972
($error): ~
7073
(contains($stdout, 'Conditions met')): true
@@ -76,7 +79,6 @@ spec:
7679
kubectl annotate svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-default-proxy-protocol=v2
7780
kubectl annotate svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-port-80-
7881
kubectl annotate --overwrite svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-port-8080='{"proxy-protocol": "v1"}'
79-
sleep 10
8082
check:
8183
($error == null): true
8284
- name: Check NodeBalancerConfig for port 80 to have ProxyProtocol v2 and port 8080 to have ProxyProtocol v1
@@ -87,19 +89,23 @@ spec:
8789
8890
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
8991
90-
nbconfig=$(curl -s \
91-
-H "Authorization: Bearer $LINODE_TOKEN" \
92-
-H "Content-Type: application/json" --fail-early --retry 3 \
93-
"$LINODE_URL/v4/nodebalancers/$nbid/configs")
92+
for i in {1..10}; do
93+
nbconfig=$(curl -s \
94+
-H "Authorization: Bearer $LINODE_TOKEN" \
95+
-H "Content-Type: application/json" --fail-early --retry 3 \
96+
"$LINODE_URL/v4/nodebalancers/$nbid/configs")
9497
95-
port_80_v2=$(echo $nbconfig | jq -r '.data[] | select(.port == 80) | .proxy_protocol == "v2"')
96-
port_8080_v1=$(echo $nbconfig | jq -r '.data[] | select(.port == 8080) | .proxy_protocol == "v1"')
98+
port_80_v2=$(echo $nbconfig | jq -r '.data[] | select(.port == 80) | .proxy_protocol == "v2"')
99+
port_8080_v1=$(echo $nbconfig | jq -r '.data[] | select(.port == 8080) | .proxy_protocol == "v1"')
97100
98-
if [[ $port_80_v2 == "true" && $port_8080_v1 == "true" ]]; then
99-
echo "Conditions met"
100-
else
101-
echo "Conditions not met"
102-
fi
101+
if [[ $port_80_v2 == "true" && $port_8080_v1 == "true" ]]; then
102+
echo "Conditions met"
103+
break
104+
else
105+
echo "Conditions not met"
106+
fi
107+
sleep 10
108+
done
103109
check:
104110
($error): ~
105111
(contains($stdout, 'Conditions met')): true

e2e/test/lb-with-udp-ports-change-port/chainsaw-test.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,17 @@ spec:
5353
echo "Nodebalancer config found, updating config udp_check_port"
5454
5555
kubectl annotate --overwrite svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-udp-check-port=4500
56-
sleep 5s
5756
5857
echo "Verifying that udp_check_port is set to 4500"
59-
nbconfig=$(LINODE_TOKEN=$LINODE_TOKEN NBID=$nbid ../scripts/get-nb-config.sh)
60-
udp_check_port=$(echo $nbconfig | jq -r '.udp_check_port')
61-
echo "udp_check_port is $udp_check_port"
58+
for i in {1..10}; do
59+
nbconfig=$(LINODE_TOKEN=$LINODE_TOKEN NBID=$nbid ../scripts/get-nb-config.sh)
60+
udp_check_port=$(echo $nbconfig | jq -r '.udp_check_port')
61+
echo "udp_check_port is $udp_check_port"
62+
if [[ "$udp_check_port" == "4500" ]]; then
63+
break
64+
fi
65+
sleep 10
66+
done
6267
check:
6368
($error == null): true
6469
(contains($stdout, 'udp_check_port is 4500')): true

e2e/test/scripts/get-nb-id.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ if [[ -n "$1" ]]; then
99
svcname="$1"
1010
fi
1111

12-
hostname=$(kubectl get svc $svcname -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname)
13-
ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}')
12+
ip=$(kubectl get svc "$svcname" -n "$NAMESPACE" -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
1413
nbid=$(curl -s \
1514
-H "Authorization: Bearer $LINODE_TOKEN" \
1615
-H "Content-Type: application/json" --fail-early --retry 3 \

0 commit comments

Comments
 (0)