-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path049-base-whole_clusters-check_readiness.sh
More file actions
executable file
·67 lines (50 loc) · 2.08 KB
/
049-base-whole_clusters-check_readiness.sh
File metadata and controls
executable file
·67 lines (50 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
source utils/sm-api-call.sh
CLUSTER_DATA_DIR="data/clusters"
MIN_VERSION="1.28.0"
ONBOARDED_CLUSTER_INDEX_FILE="$CLUSTER_DATA_DIR/onboarded-clusters-name-index"
#===========================================================================#
# After onboard all the managed clusters, wait for them to be totally ready.
# Check the onboarded clusters recorded in $ONBOARDED_CLUSTER_INDEX_FILE.
#===========================================================================#
INTERVAL=30 # seconds between checks
TIMEOUT=1800 # 30 minutes in seconds
START_TIME=$(date +%s)
echo "Checking cluster readiness..."
while true; do
non_ready=0
while IFS= read -r line || [[ -n "$line" ]]; do
# Skip empty lines
[[ -z "$line" ]] && continue
IFS='.' read -r management_cluster provisioner cluster <<< "$line"
if [[ -z "$management_cluster" || -z "$provisioner" || -z "$cluster" ]]; then
echo "Invalid cluster data: $line"
continue
fi
echo "Checking cluster: $cluster (management_cluster: $management_cluster, provisioner: $provisioner)"
cluster_api="v1alpha1/clusters/$cluster?full_name.managementClusterName=$management_cluster&full_name.provisionerName=$provisioner"
output=$(curl_api_call $cluster_api 2>/dev/null || true)
#output=$(tanzu tmc cluster get "$cluster" -m "$management_cluster" -p "$provisioner" -o yaml 2>/dev/null || true)
if [[ -z "$output" ]]; then
echo "Failed to get cluster info for $cluster"
((non_ready++))
continue
fi
phase=$(echo "$output" | yq '.cluster.status.health' 2>/dev/null || echo "UNKNOWN")
echo "Cluster '$cluster' health: $phase"
if [[ "$phase" != "HEALTHY" ]]; then
((non_ready++))
fi
done < "$ONBOARDED_CLUSTER_INDEX_FILE"
if [[ "$non_ready" -eq 0 ]]; then
echo "✅ All clusters are READY."
exit 0
fi
NOW=$(date +%s)
ELAPSED=$((NOW - START_TIME))
if [[ "$ELAPSED" -ge "$TIMEOUT" ]]; then
echo "❌ Timeout reached. $non_ready clusters not READY."
exit 1
fi
echo "⏳ $non_ready clusters not READY. Retrying in ${INTERVAL}s..."
sleep "$INTERVAL"
done