@@ -80,10 +80,18 @@ function ensure_eks() {
80
80
81
81
# Check for change in min/max instances
82
82
asg_on_demand_info=$( aws autoscaling describe-auto-scaling-groups --region $CORTEX_REGION --query " AutoScalingGroups[?contains(Tags[?Key==\` alpha.eksctl.io/cluster-name\` ].Value, \` $CORTEX_CLUSTER_NAME \` )]|[?contains(Tags[?Key==\` alpha.eksctl.io/nodegroup-name\` ].Value, \` ng-cortex-worker-on-demand\` )]" )
83
- asg_on_demand_name=$( echo " $asg_on_demand_info " | jq -r ' first | .AutoScalingGroupName' )
83
+ asg_on_demand_length=$( echo " $asg_on_demand_info " | jq -r ' length' )
84
+ asg_on_demand_name=" "
85
+ if (( "$asg_on_demand_length " > "0 " )) ; then
86
+ asg_on_demand_name=$( echo " $asg_on_demand_info " | jq -r ' first | .AutoScalingGroupName' )
87
+ fi
84
88
85
89
asg_spot_info=$( aws autoscaling describe-auto-scaling-groups --region $CORTEX_REGION --query " AutoScalingGroups[?contains(Tags[?Key==\` alpha.eksctl.io/cluster-name\` ].Value, \` $CORTEX_CLUSTER_NAME \` )]|[?contains(Tags[?Key==\` alpha.eksctl.io/nodegroup-name\` ].Value, \` ng-cortex-worker-spot\` )]" )
86
- asg_spot_name=$( echo " $asg_spot_info " | jq -r ' first | .AutoScalingGroupName' )
90
+ asg_spot_length=$( echo " $asg_spot_info " | jq -r ' length' )
91
+ asg_spot_name=" "
92
+ if (( "$asg_spot_length " > "0 " )) ; then
93
+ asg_spot_name=$( echo " $asg_spot_info " | jq -r ' first | .AutoScalingGroupName' )
94
+ fi
87
95
88
96
if [[ -z $asg_spot_name ]]; then
89
97
asg_min_size=$( echo " $asg_on_demand_info " | jq -r ' first | .MinSize' )
@@ -93,9 +101,14 @@ function ensure_eks() {
93
101
asg_max_size=$( echo " $asg_spot_info " | jq -r ' first | .MaxSize' )
94
102
fi
95
103
104
+ if [[ -z " $asg_spot_name " ]] && [[ -z " $asg_on_demand_name " ]]; then
105
+ echo " error: unable to find valid autoscaling groups"
106
+ exit 1
107
+ fi
108
+
96
109
if [ " $asg_min_size " != " $CORTEX_MIN_INSTANCES " ]; then
97
110
echo -n " ○ updating min instances to $CORTEX_MIN_INSTANCES "
98
-
111
+ # only update min if on demand nodegroup exists and on demand nodegroup is not a backup
99
112
if [[ -n $asg_on_demand_name ]] && [[ " $CORTEX_SPOT_CONFIG_ON_DEMAND_BACKUP " != " True" ]]; then
100
113
aws autoscaling update-auto-scaling-group --region $CORTEX_REGION --auto-scaling-group-name $asg_on_demand_name --min-size=$CORTEX_MIN_INSTANCES
101
114
fi
0 commit comments