Created
October 29, 2025 10:12
-
-
Save oshoval/f183371b2aec97450c9affaa2ef030dd to your computer and use it in GitHub Desktop.
log fetcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # Script to fetch KubeVirt PR logs from Google Cloud Storage | |
| # Usage: ./fetch_logs.sh <type> <url> | |
| # Example: ./fetch_logs.sh good https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_kubevirt/15955/pull-kubevirt-e2e-k8s-1.34-ipv6-sig-network/1983266997290405888 | |
| # Check if all required arguments are provided | |
| if [ $# -ne 2 ]; then | |
| echo "Error: Missing required arguments" | |
| echo "Usage: $0 <type> <url>" | |
| echo "" | |
| echo "Parameters:" | |
| echo " type - good or bad (organizes the download location)" | |
| echo " url - Prow dashboard URL" | |
| echo "" | |
| echo "Example:" | |
| echo " $0 good https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_kubevirt/15955/pull-kubevirt-e2e-k8s-1.34-ipv6-sig-network/1983266997290405888" | |
| exit 1 | |
| fi | |
| TYPE=$1 | |
| PROW_URL=$2 | |
| # Validate type parameter | |
| if [ "$TYPE" != "good" ] && [ "$TYPE" != "bad" ]; then | |
| echo "Error: type must be either 'good' or 'bad'" | |
| exit 1 | |
| fi | |
| # Parse the URL to extract PR number, job name, and instance | |
| # Expected format: https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_kubevirt/{PR}/{JOB_NAME}/{INSTANCE} | |
| URL_PATH=$(echo "$PROW_URL" | sed 's|https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_kubevirt/||') | |
| # Extract components | |
| PR_NUMBER=$(echo "$URL_PATH" | cut -d'/' -f1) | |
| JOB_NAME=$(echo "$URL_PATH" | cut -d'/' -f2) | |
| INSTANCE=$(echo "$URL_PATH" | cut -d'/' -f3) | |
| # Validate that we successfully parsed all components | |
| if [ -z "$PR_NUMBER" ] || [ -z "$JOB_NAME" ] || [ -z "$INSTANCE" ]; then | |
| echo "Error: Failed to parse URL. Please provide a valid Prow dashboard URL." | |
| echo "Expected format: https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_kubevirt/{PR}/{JOB_NAME}/{INSTANCE}" | |
| exit 1 | |
| fi | |
| # Construct the GCS path | |
| GCS_PATH="gs://kubevirt-prow/pr-logs/pull/kubevirt_kubevirt/${PR_NUMBER}/${JOB_NAME}/${INSTANCE}" | |
| # Create output directory structure | |
| OUTPUT_DIR="logs/${PR_NUMBER}/${TYPE}/${JOB_NAME}/${INSTANCE}" | |
| COPY_DEST="logs/${PR_NUMBER}/${TYPE}/${JOB_NAME}" | |
| # Remove existing directory if it exists | |
| if [ -d "$OUTPUT_DIR" ]; then | |
| echo "Removing existing directory: $OUTPUT_DIR" | |
| rm -rf "$OUTPUT_DIR" | |
| fi | |
| mkdir -p "$COPY_DEST" | |
| echo "========================================" | |
| echo "Fetching ${TYPE} run logs" | |
| echo "========================================" | |
| echo "PR Number: $PR_NUMBER" | |
| echo "Job Name: $JOB_NAME" | |
| echo "Instance: $INSTANCE" | |
| echo "GCS Path: $GCS_PATH" | |
| echo "Output Dir: $OUTPUT_DIR" | |
| echo "========================================" | |
| echo "" | |
| # Run the docker command to fetch logs | |
| # gsutil will create the instance directory at the destination | |
| docker run -it --rm \ | |
| -v "$PWD:/data" \ | |
| google/cloud-sdk:latest \ | |
| gsutil -m cp -r "$GCS_PATH" "/data/$COPY_DEST/" | |
| echo "" | |
| echo "========================================" | |
| echo "Logs downloaded successfully!" | |
| echo "Location: $OUTPUT_DIR" | |
| echo "========================================" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment