forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade-cluster.sh
More file actions
executable file
·90 lines (76 loc) · 2.62 KB
/
Copy pathupgrade-cluster.sh
File metadata and controls
executable file
·90 lines (76 loc) · 2.62 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
# upgrade-cluster.sh — semi-automated Kubernetes cluster upgrade
# Usage: ./upgrade-cluster.sh --target-version 1.30 [--dry-run]
set -euo pipefail
TARGET_VERSION=""
DRY_RUN=false
CLUSTER_NAME="${CLUSTER_NAME:-gistpin-cluster}"
REGION="${AWS_REGION:-us-east-1}"
while [[ $# -gt 0 ]]; do
case "$1" in
--target-version) TARGET_VERSION="$2"; shift 2 ;;
--dry-run) DRY_RUN=true; shift ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
[[ -z "${TARGET_VERSION}" ]] && { echo "ERROR: --target-version required"; exit 1; }
RUN() {
if [[ "${DRY_RUN}" == "true" ]]; then
echo "[DRY-RUN] $*"
else
echo "[RUN] $*"
eval "$@"
fi
}
echo "=== GistPin EKS Cluster Upgrade ==="
echo "Cluster: ${CLUSTER_NAME} | Target: ${TARGET_VERSION} | Region: ${REGION}"
echo ""
# --- 1. Pre-upgrade compatibility check ---
echo "--- Step 1: Pre-upgrade compatibility check ---"
CURRENT_VERSION=$(aws eks describe-cluster \
--name "${CLUSTER_NAME}" --region "${REGION}" \
--query 'cluster.version' --output text 2>/dev/null || echo "unknown")
echo "Current version: ${CURRENT_VERSION}"
bash "$(dirname "$0")/validate-upgrade.sh" \
--current "${CURRENT_VERSION}" --target "${TARGET_VERSION}" \
${DRY_RUN:+--dry-run}
# --- 2. Upgrade control plane ---
echo ""
echo "--- Step 2: Control plane upgrade ---"
RUN aws eks update-cluster-version \
--name "${CLUSTER_NAME}" \
--kubernetes-version "${TARGET_VERSION}" \
--region "${REGION}"
if [[ "${DRY_RUN}" != "true" ]]; then
echo "Waiting for control plane upgrade to complete..."
aws eks wait cluster-active --name "${CLUSTER_NAME}" --region "${REGION}"
fi
# --- 3. Rolling node group upgrade ---
echo ""
echo "--- Step 3: Node group rolling upgrade ---"
NODE_GROUPS=$(aws eks list-nodegroups \
--cluster-name "${CLUSTER_NAME}" --region "${REGION}" \
--query 'nodegroups[*]' --output text 2>/dev/null || echo "")
for ng in ${NODE_GROUPS}; do
echo "Upgrading node group: ${ng}"
RUN aws eks update-nodegroup-version \
--cluster-name "${CLUSTER_NAME}" \
--nodegroup-name "${ng}" \
--kubernetes-version "${TARGET_VERSION}" \
--region "${REGION}"
if [[ "${DRY_RUN}" != "true" ]]; then
aws eks wait nodegroup-active \
--cluster-name "${CLUSTER_NAME}" \
--nodegroup-name "${ng}" \
--region "${REGION}"
echo "Node group ${ng} upgraded successfully."
fi
done
# --- 4. Post-upgrade validation ---
echo ""
echo "--- Step 4: Post-upgrade validation ---"
bash "$(dirname "$0")/validate-upgrade.sh" \
--current "${TARGET_VERSION}" --target "${TARGET_VERSION}" \
${DRY_RUN:+--dry-run}
echo ""
echo "=== Upgrade complete ==="