From 5b58af64ac3882c2f0e8f75432742487ded6bfae Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Sat, 21 Nov 2020 20:52:50 -0800 Subject: [PATCH] Suspend AZRebalance in on-demand autoscaling group --- manager/install.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/manager/install.sh b/manager/install.sh index d758633e6e..dd332adaaf 100755 --- a/manager/install.sh +++ b/manager/install.sh @@ -160,9 +160,7 @@ function create_eks() { eksctl create cluster --timeout=$EKSCTL_TIMEOUT --install-neuron-plugin=false -f /workspace/eks.yaml echo - if [ "${CORTEX_SPOT,,}" == "true" ]; then - suspend_spot_az_rebalance - fi + suspend_az_rebalance write_kubeconfig } @@ -325,14 +323,20 @@ function resize_nodegroup() { fi } -function suspend_spot_az_rebalance() { - asg_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\`)]") - asg_name=$(echo "$asg_info" | jq -r 'first | .AutoScalingGroupName') - if [ "$asg_name" = "" ] || [ "$asg_name" = "null" ]; then - echo -e "unable to find autoscaling group name from info:\n$asg_info" - exit 1 +function suspend_az_rebalance() { + 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\`)]") + asg_on_demand_length=$(echo "$asg_on_demand_info" | jq -r 'length') + if (( "$asg_on_demand_length" > "0" )); then + asg_on_demand_name=$(echo "$asg_on_demand_info" | jq -r 'first | .AutoScalingGroupName') + aws autoscaling suspend-processes --region $CORTEX_REGION --auto-scaling-group-name $asg_on_demand_name --scaling-processes AZRebalance + fi + + 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\`)]") + asg_spot_length=$(echo "$asg_spot_info" | jq -r 'length') + if (( "$asg_spot_length" > "0" )); then + asg_spot_name=$(echo "$asg_spot_info" | jq -r 'first | .AutoScalingGroupName') + aws autoscaling suspend-processes --region $CORTEX_REGION --auto-scaling-group-name $asg_spot_name --scaling-processes AZRebalance fi - aws autoscaling suspend-processes --region $CORTEX_REGION --auto-scaling-group-name $asg_name --scaling-processes AZRebalance } function create_vpc_link() {