Skip to content

Commit 8e5797e

Browse files
committed
Check EKS status before spinning up cluster (#561)
(cherry picked from commit 9118cf4)
1 parent af7e12b commit 8e5797e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

manager/install.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ set -e
1919
arg1="$1"
2020

2121
function ensure_eks() {
22-
if ! eksctl utils describe-stacks --name=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION >/dev/null 2>&1; then
22+
# Cluster statuses: https://github.com/aws/aws-sdk-go/blob/master/service/eks/api.go#L2785
23+
set +e
24+
cluster_info=$(eksctl get cluster --name=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION -o json)
25+
cluster_info_exit_code=$?
26+
set -e
27+
28+
# No cluster
29+
if [ $cluster_info_exit_code -ne 0 ]; then
2330
if [ "$arg1" = "--update" ]; then
2431
echo "error: there isn't a Cortex cluster named \"$CORTEX_CLUSTER_NAME\" in $CORTEX_REGION; please update your configuration to point to an existing Cortex cluster or create a Cortex cluster with \`cortex cluster up\`"
2532
exit 1
@@ -31,6 +38,29 @@ function ensure_eks() {
3138
return
3239
fi
3340

41+
cluster_status=$(echo "$cluster_info" | jq -r 'first | .Status')
42+
43+
if [ "$cluster_status" == "DELETING" ]; then
44+
echo "error: your Cortex cluster named \"$CORTEX_CLUSTER_NAME\" in $CORTEX_REGION is currently spinning down; please try again once it is completely deleted (may take a few minutes)"
45+
exit 1
46+
fi
47+
48+
if [ "$cluster_status" == "CREATING" ]; then
49+
echo "error: your Cortex cluster named \"$CORTEX_CLUSTER_NAME\" in $CORTEX_REGION is currently spinning up; please try again once it is ready"
50+
exit 1
51+
fi
52+
53+
if [ "$cluster_status" == "FAILED" ]; then
54+
echo "error: your Cortex cluster named \"$CORTEX_CLUSTER_NAME\" in $CORTEX_REGION is failed; delete it with \`eksctl delete cluster --name=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION\` and try again"
55+
exit 1
56+
fi
57+
58+
# Catch all
59+
if [ "$cluster_status" != "ACTIVE" ]; then
60+
echo "error: your Cortex cluster named \"$CORTEX_CLUSTER_NAME\" in $CORTEX_REGION is not active; please wait until it is active, or delete it with \`eksctl delete cluster --name=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION\` and try again"
61+
exit 1
62+
fi
63+
3464
echo "✓ Cluster is running"
3565

3666
# Check if instance type changed

0 commit comments

Comments
 (0)