|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function syslog() { |
| 4 | + echo ">>> $1" |
| 5 | +} |
| 6 | + |
| 7 | +function panic() { |
| 8 | + err_msg=$1 |
| 9 | + syslog "backward compatibility test failed: $err_msg" |
| 10 | + exit 1 |
| 11 | +} |
| 12 | + |
| 13 | +function 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 >= 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 | +function 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 | + last_state=$(kubectl get dataset $dataset_name -ojsonpath='{@.status.phase}') |
| 61 | + if [[ $log_interval -eq 3 ]]; then |
| 62 | + log_times=$(expr $log_times + 1) |
| 63 | + syslog "checking dataset.status.phase==Bound (already $(expr $log_times \* $log_interval \* 5)s, last state: $last_state)" |
| 64 | + if [[ "$(expr $log_times \* $log_interval \* 5)" -ge "$deadline" ]]; then |
| 65 | + panic "timeout for ${deadline}s waiting for dataset bound!" |
| 66 | + fi |
| 67 | + log_interval=0 |
| 68 | + fi |
| 69 | + |
| 70 | + if [[ "$last_state" == "Bound" ]]; then |
| 71 | + break |
| 72 | + fi |
| 73 | + log_interval=$(expr $log_interval + 1) |
| 74 | + sleep 5 |
| 75 | + done |
| 76 | + syslog "Found dataset $dataset_name status.phase==Bound" |
| 77 | +} |
| 78 | + |
| 79 | +function wait_job_completed() { |
| 80 | + local job_name=$1 |
| 81 | + while true; do |
| 82 | + succeed=$(kubectl get job $job_name -ojsonpath='{@.status.succeeded}') |
| 83 | + failed=$(kubectl get job $job_name -ojsonpath='{@.status.failed}') |
| 84 | + if [[ "$failed" -ne "0" ]]; then |
| 85 | + panic "job $job_name failed when accessing data" |
| 86 | + fi |
| 87 | + if [[ "$succeed" -eq "1" ]]; then |
| 88 | + break |
| 89 | + fi |
| 90 | + sleep 5 |
| 91 | + done |
| 92 | + syslog "Found succeeded job $job_name" |
| 93 | +} |
| 94 | + |
| 95 | +function setup_old_fluid() { |
| 96 | + syslog "Setting up older version of Fluid from charts" |
| 97 | + helm repo add fluid https://fluid-cloudnative.github.io/charts |
| 98 | + helm repo update fluid |
| 99 | + |
| 100 | + # We ignore errors in case namespace exists |
| 101 | + kubectl create ns fluid-system || true |
| 102 | + |
| 103 | + helm install fluid fluid/fluid --namespace fluid-system |
| 104 | + check_control_plane_status |
| 105 | +} |
| 106 | + |
| 107 | +function create_dataset() { |
| 108 | + syslog "Creating alluxio dataset..." |
| 109 | + kubectl apply -f test/gha-e2e/alluxio/dataset.yaml |
| 110 | + wait_dataset_bound zookeeper |
| 111 | +} |
| 112 | + |
| 113 | +function upgrade_fluid() { |
| 114 | + syslog "Upgrading Fluid to the locally built current version..." |
| 115 | + ./.github/scripts/deploy-fluid-to-kind.sh |
| 116 | + check_control_plane_status |
| 117 | +} |
| 118 | + |
| 119 | +function verify_backward_compatibility() { |
| 120 | + syslog "Verifying backward compatibility..." |
| 121 | + # Ensure the dataset created earlier is still bound |
| 122 | + wait_dataset_bound zookeeper |
| 123 | + |
| 124 | + # create job to access data over the runtime |
| 125 | + kubectl apply -f test/gha-e2e/alluxio/job.yaml |
| 126 | + wait_job_completed fluid-test |
| 127 | + |
| 128 | + # Clean up |
| 129 | + kubectl delete -f test/gha-e2e/alluxio/ |
| 130 | +} |
| 131 | + |
| 132 | +function main() { |
| 133 | + set -e |
| 134 | + syslog "[BACKWARD COMPATIBILITY TEST STARTS AT $(date)]" |
| 135 | + |
| 136 | + setup_old_fluid |
| 137 | + create_dataset |
| 138 | + upgrade_fluid |
| 139 | + verify_backward_compatibility |
| 140 | + |
| 141 | + syslog "[BACKWARD COMPATIBILITY TEST SUCCEEDED AT $(date)]" |
| 142 | +} |
| 143 | + |
| 144 | +main |
0 commit comments