|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +syslog() { |
| 4 | + echo ">>> ${1}" |
| 5 | +} |
| 6 | + |
| 7 | +panic() { |
| 8 | + local err_msg="${1}" |
| 9 | + syslog "backward compatibility test failed: ${err_msg}" |
| 10 | + exit 1 |
| 11 | +} |
| 12 | + |
| 13 | +check_control_plane_status() { |
| 14 | + echo "=== Unique image tags used by Fluid control plane ===" |
| 15 | + kubectl get pod -n fluid-system -o jsonpath=' |
| 16 | + {range .items[*]}{range .spec.containers[*]}{.image}{"\n"}{end}{range .spec.initContainers[*]}{.image}{"\n"}{end}{end}' \ |
| 17 | + | sed 's/.*://' \ |
| 18 | + | sort -u |
| 19 | + |
| 20 | + # Timeout counter (30 minutes = 360*5 seconds) |
| 21 | + local timeout=360 |
| 22 | + local counter=0 |
| 23 | + local status_interval=36 |
| 24 | + |
| 25 | + while true; do |
| 26 | + total_pods=$(kubectl get pod -n fluid-system --no-headers | grep -cv "Completed") |
| 27 | + running_pods=$(kubectl get pod -n fluid-system --no-headers | grep -c "Running") |
| 28 | + not_running_pods=$((total_pods - running_pods)) |
| 29 | + |
| 30 | + if ((counter % status_interval == 0)); then |
| 31 | + syslog "[Status Check $((counter / status_interval))] Pod status: ${running_pods}/${total_pods} running (${not_running_pods} not ready)" |
| 32 | + if [[ "${not_running_pods}" -gt 0 ]]; then |
| 33 | + echo "=== Not running pods ===" |
| 34 | + kubectl get pods -n fluid-system \ |
| 35 | + --field-selector=status.phase!=Running \ |
| 36 | + -o=custom-columns='NAME:.metadata.name,STATUS:.status.phase,REASON:.status.reason' |
| 37 | + fi |
| 38 | + fi |
| 39 | + |
| 40 | + if [[ "${total_pods}" -ne 0 ]] && [[ "${total_pods}" -eq "${running_pods}" ]]; then |
| 41 | + break |
| 42 | + fi |
| 43 | + |
| 44 | + if [[ "${counter}" -ge "${timeout}" ]]; then |
| 45 | + panic "Timeout waiting for control plane after ${counter} checks!" |
| 46 | + fi |
| 47 | + |
| 48 | + sleep 5 |
| 49 | + ((counter++)) |
| 50 | + done |
| 51 | + syslog "Fluid control plane is ready after ${counter} checks!" |
| 52 | +} |
| 53 | + |
| 54 | +wait_dataset_bound() { |
| 55 | + local dataset_name="${1}" |
| 56 | + local deadline=180 |
| 57 | + local log_interval=0 |
| 58 | + local log_times=0 |
| 59 | + while true; do |
| 60 | + # Use || true to prevent script from exiting if field is missing |
| 61 | + last_state=$(kubectl get dataset "${dataset_name}" -ojsonpath='{.status.phase}' 2>/dev/null || echo "") |
| 62 | + |
| 63 | + if [[ "${log_interval}" -eq 3 ]]; then |
| 64 | + ((log_times++)) |
| 65 | + syslog "checking dataset.status.phase==Bound (already $((log_times * 3 * 5))s, last state: ${last_state:-None})" |
| 66 | + if [[ $((log_times * 3 * 5)) -ge "${deadline}" ]]; then |
| 67 | + panic "timeout for ${deadline}s waiting for dataset bound!" |
| 68 | + fi |
| 69 | + log_interval=0 |
| 70 | + fi |
| 71 | + |
| 72 | + if [[ "${last_state}" == "Bound" ]]; then |
| 73 | + break |
| 74 | + fi |
| 75 | + ((log_interval++)) |
| 76 | + sleep 5 |
| 77 | + done |
| 78 | + syslog "Found dataset ${dataset_name} status.phase==Bound" |
| 79 | +} |
| 80 | + |
| 81 | +wait_job_completed() { |
| 82 | + local job_name="${1}" |
| 83 | + local deadline=600 # 10 minutes |
| 84 | + local counter=0 |
| 85 | + while true; do |
| 86 | + # Handle missing fields gracefully |
| 87 | + succeed=$(kubectl get job "${job_name}" -ojsonpath='{.status.succeeded}' 2>/dev/null || echo "0") |
| 88 | + failed=$(kubectl get job "${job_name}" -ojsonpath='{.status.failed}' 2>/dev/null || echo "0") |
| 89 | + |
| 90 | + # Ensure variables are treated as integers |
| 91 | + [[ -z "${succeed}" ]] && succeed=0 |
| 92 | + [[ -z "${failed}" ]] && failed=0 |
| 93 | + |
| 94 | + if [[ "${failed}" -gt 0 ]]; then |
| 95 | + panic "job ${job_name} failed when accessing data" |
| 96 | + fi |
| 97 | + if [[ "${succeed}" -gt 0 ]]; then |
| 98 | + break |
| 99 | + fi |
| 100 | + |
| 101 | + ((counter++)) |
| 102 | + if [[ $((counter * 5)) -ge "${deadline}" ]]; then |
| 103 | + panic "timeout for ${deadline}s waiting for job ${job_name} completion!" |
| 104 | + fi |
| 105 | + sleep 5 |
| 106 | + done |
| 107 | + syslog "Found succeeded job ${job_name}" |
| 108 | +} |
| 109 | + |
| 110 | +setup_old_fluid() { |
| 111 | + syslog "Setting up older version of Fluid from charts" |
| 112 | + helm repo add fluid https://fluid-cloudnative.github.io/charts |
| 113 | + helm repo update fluid |
| 114 | + |
| 115 | + # We ignore errors in case namespace exists |
| 116 | + kubectl create ns fluid-system || true |
| 117 | + |
| 118 | + helm install fluid fluid/fluid --namespace fluid-system --wait |
| 119 | + check_control_plane_status |
| 120 | +} |
| 121 | + |
| 122 | +create_dataset() { |
| 123 | + syslog "Creating alluxio dataset..." |
| 124 | + kubectl apply -f test/gha-e2e/alluxio/dataset.yaml |
| 125 | + # give it 10s to let the API server and controller settle |
| 126 | + sleep 10 |
| 127 | + wait_dataset_bound "zookeeper" |
| 128 | +} |
| 129 | + |
| 130 | +upgrade_fluid() { |
| 131 | + syslog "Upgrading Fluid to the locally built current version..." |
| 132 | + ./.github/scripts/deploy-fluid-to-kind.sh |
| 133 | + check_control_plane_status |
| 134 | +} |
| 135 | + |
| 136 | +verify_backward_compatibility() { |
| 137 | + syslog "Verifying backward compatibility..." |
| 138 | + # Ensure the dataset created earlier is still bound |
| 139 | + wait_dataset_bound "zookeeper" |
| 140 | + |
| 141 | + # create job to access data over the runtime |
| 142 | + kubectl apply -f test/gha-e2e/alluxio/job.yaml |
| 143 | + wait_job_completed "fluid-test" |
| 144 | + |
| 145 | + # Clean up |
| 146 | + kubectl delete -f test/gha-e2e/alluxio/ |
| 147 | +} |
| 148 | + |
| 149 | +main() { |
| 150 | + set -e |
| 151 | + syslog "[BACKWARD COMPATIBILITY TEST STARTS AT $(date)]" |
| 152 | + |
| 153 | + setup_old_fluid |
| 154 | + create_dataset |
| 155 | + upgrade_fluid |
| 156 | + verify_backward_compatibility |
| 157 | + |
| 158 | + syslog "[BACKWARD COMPATIBILITY TEST SUCCEEDED AT $(date)]" |
| 159 | +} |
| 160 | + |
| 161 | +main |
0 commit comments