Skip to content

Commit bff4ec8

Browse files
Merge branch 'main' into bugfixes/add-missing-permissions-on-upgrade-test
2 parents 0731577 + f0c08d3 commit bff4ec8

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

build/e2e_upgrade_test.sh

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set -o pipefail
1919

2020
BASE_VERSION=$1
2121
PROJECT_ID=$2
22-
logBucketName="upgrade-test-container-logs"
22+
BUCKET_NAME="upgrade-test-container-logs"
2323

2424
apt-get update && apt-get install -y jq
2525
export SHELL="/bin/bash"
@@ -30,28 +30,33 @@ cd /go/src/agones.dev/agones/test/upgrade
3030

3131
# --- Function to print failure logs ---
3232
print_failure_logs() {
33-
local cluster_name=$1
34-
echo "ERROR: Upgrade test failed on cluster: $cluster_name"
35-
33+
local testCluster=$1
34+
local testClusterLocation=$2
35+
echo "ERROR: Upgrade test failed on cluster: $testCluster"
36+
gcloud container clusters get-credentials "$testCluster" --region="$testClusterLocation" --project="$PROJECT_ID"
3637
job_pods=$(kubectl get pods -l job-name=upgrade-test-runner -o jsonpath="{.items[*].metadata.name}")
37-
kubectl logs --tail=20 "$job_pods" || echo "Unable to retrieve logs for pod: $job_pods"
38-
for pod in $job_pods; do
39-
containers=$(kubectl get pod "$pod" -o jsonpath='{.spec.containers[*].name}')
40-
for container in $containers; do
41-
if [[ "$container" == "sdk-client-test" || "$container" == "upgrade-test-controller" ]]; then
42-
echo "----- Logs from pod: $pod, container: $container -----"
43-
kubectl logs "$pod" -c "$container" || echo "Failed to retrieve logs from $pod/$container"
44-
fi
38+
if [[ -z "$job_pods" ]]; then
39+
echo "No pods found for job upgrade-test-runner. They might have failed to schedule or were deleted."
40+
else
41+
kubectl logs --tail=20 "$job_pods" || echo "Unable to retrieve logs for pod: $job_pods"
42+
for pod in $job_pods; do
43+
containers=$(kubectl get pod "$pod" -o jsonpath='{.spec.containers[*].name}')
44+
for container in $containers; do
45+
if [[ "$container" == "sdk-client-test" || "$container" == "upgrade-test-controller" ]]; then
46+
echo "----- Logs from pod: $pod, container: $container -----"
47+
kubectl logs "$pod" -c "$container" || echo "Failed to retrieve logs from $pod/$container"
48+
fi
49+
done
4550
done
46-
done
51+
fi
4752

48-
log_url="https://console.cloud.google.com/logs/query;storageScope=storage,projects%2F${PROJECT_ID}%2Flocations%2Fglobal%2Fbuckets%2Fupgrade-test-container-logs%2Fviews%2F_AllLogs;query=$(printf 'resource.labels.container_name=(\"upgrade-test-controller\" OR \"sdk-client-test\")' | jq -sRr @uri);cursorTimestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ);duration=PT10M?project=${PROJECT_ID}"
49-
echo "Logs from log bucket: $log_url"
53+
echo "Logs from log bucket: https://console.cloud.google.com/logs/query;storageScope=storage,projects%2F${PROJECT_ID}%2Flocations%2Fglobal%2Fbuckets%2F${BUCKET_NAME}%2Fviews%2F_AllLogs?hl=en&inv=1&invt=Ab4o5A&mods=logs_tg_prod&project=${PROJECT_ID}"
5054
}
5155
# ------------------------------------------------------
5256

5357
pids=()
5458
typeset -A waitPids # Associative array for mapping `kubectl wait job` pid -> `kubectl wait job` output log name
59+
declare -A clusterRegionMap # Associative array for mapping cluster name -> cluster location
5560
tmpdir=$(mktemp -d)
5661
trap 'rm -rf -- "$tmpdir"' EXIT SIGTERM
5762

@@ -79,6 +84,9 @@ do
7984
fi
8085
testClusterLocation="${region}"
8186

87+
# Store mapping for later lookup
88+
clusterRegionMap["$testCluster"]="$testClusterLocation"
89+
8290
echo "===== Processing cluster: $testCluster in $testClusterLocation ====="
8391

8492
gcloud container clusters get-credentials "$testCluster" --region="$testClusterLocation" --project="$PROJECT_ID"
@@ -146,15 +154,16 @@ do
146154
# Wait for the pod to become ready (or timeout)
147155
if ! kubectl wait --for=condition=ready pod -l job-name=upgrade-test-runner --timeout=5m; then
148156
echo "ERROR: The pod for job 'upgrade-test-runner' did not become ready within the timeout period."
149-
print_failure_logs "$testCluster"
157+
print_failure_logs "$testCluster" "$testClusterLocation"
150158
exit 1
151159
fi
152160

153161
echo Wait for job upgrade-test-runner to complete or fail on cluster "${testCluster}"
154-
kubectl wait job/upgrade-test-runner --timeout=30m --for jsonpath='{.status.conditions[*].status}'=True -o jsonpath='{.status.conditions[*]}' | tee "${tmpdir}"/"${testCluster}".log &
162+
logPath="${tmpdir}/${testCluster}.log"
163+
kubectl wait job/upgrade-test-runner --timeout=30m --for jsonpath='{.status.conditions[*].status}'=True -o jsonpath='{.status.conditions[*]}' | tee "$logPath" &
155164
waitPid=$!
156165
pids+=( "$waitPid" )
157-
waitPids[$waitPid]="${tmpdir}"/"${testCluster}".log
166+
waitPids[$waitPid]="$logPath"
158167

159168
done
160169
done
@@ -180,15 +189,17 @@ for pid in "${pids[@]}"; do
180189
continue
181190
else
182191
echo "Unexpected job status: '$job_condition_type' with message: '$job_condition_message' in log $outputLog"
183-
print_failure_logs "$(basename "$outputLog" .log)"
192+
clusterName="$(basename "$outputLog" .log)"
193+
print_failure_logs "$clusterName" "${clusterRegionMap[$clusterName]}"
184194
exit 1
185195
fi
186196
# This block executes when the process exits and pid status!=0
187197
else
188198
status=$?
189199
outputLog="${waitPids[$pid]}"
200+
clusterName="$(basename "$outputLog" .log)"
190201
echo "One of the upgrade tests pid $pid from cluster log $outputLog exited with a non-zero status ${status}."
191-
print_failure_logs "$(basename "$outputLog" .log)"
202+
print_failure_logs "$clusterName" "${clusterRegionMap[$clusterName]}"
192203
exit $status
193204
fi
194205
done

0 commit comments

Comments
 (0)