Skip to content

Commit

Permalink
re-use same script for auto-start and stop of aks clusters (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktoriyabogdanova authored Oct 31, 2023
1 parent 070987b commit d0f7525
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aks-auto-shutdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
tenant-id: 531ff96d-0ae9-462a-8d2d-bec7c0b42082 # HMCTS.NET
allow-no-subscriptions: true
- name: AKS Auto Shutdown
run: ./scripts/aks/auto-shutdown.sh
run: ./scripts/aks/auto-start-stop.sh stop
- name: AKS Auto Shutdown status check
run: ./scripts/aks/auto-shutdown-status.sh
2 changes: 1 addition & 1 deletion .github/workflows/aks-auto-start.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
tenant-id: 531ff96d-0ae9-462a-8d2d-bec7c0b42082 # HMCTS.NET
allow-no-subscriptions: true
- name: AKS Auto Start
run: ./scripts/aks/auto-start.sh ${{ secrets.REGISTRYSLACKWEBHOOK }}
run: ./scripts/aks/auto-start-stop.sh start ${{ secrets.REGISTRYSLACKWEBHOOK }}
28 changes: 0 additions & 28 deletions scripts/aks/auto-shutdown.sh

This file was deleted.

53 changes: 53 additions & 0 deletions scripts/aks/auto-start-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

shopt -s nocasematch
AMBER='\033[1;33m'
GREEN='\033[0;32m'
source scripts/aks/common-functions.sh

MODE=${1:-start}
registrySlackWebhook=$2
SKIP="false"

if [[ "$MODE" != "start" && "$MODE" != "stop" ]]; then
echo "Invalid MODE. Please use 'start' or 'stop'."
exit 1
fi

SUBSCRIPTIONS=$(az account list -o json)
jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
subscription
jq -c '.[]' <<< $CLUSTERS | while read cluster; do
cluster
cluster_env=$(echo $CLUSTER_NAME | cut -d'-' -f2)
cluster_env=${cluster_env/#sbox/Sandbox}
cluster_env=${cluster_env/stg/Staging}
cluster_business_area=$(echo $CLUSTER_NAME | cut -d'-' -f1)
cluster_business_area=${cluster_business_area/ss/cross-cutting}
if [[ $MODE == "stop" ]]; then
SKIP=$(should_skip_shutdown $cluster_env $cluster_business_area)
fi
if [[ $SKIP == "false" ]]; then
echo -e "${GREEN}About to run $MODE operation on cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP)"
echo az aks $MODE --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --no-wait || echo Ignoring any errors while $MODE operation on cluster
az aks $MODE --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --no-wait || echo Ignoring any errors while $MODE operation on cluster
else
echo -e "${AMBER}cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP) has been skipped from today's $MODE operation schedule"
fi
done
done

if [[ $MODE == "start" ]]; then
echo "Waiting 10 mins to give clusters time to start before testing pods"
sleep 600

jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
subscription
jq -c '.[]' <<< $CLUSTERS | while read cluster; do
cluster
check_cluster_status
POWER_STATE=$(az aks show --name $CLUSTER_NAME -g $RESOURCE_GROUP | jq -r .powerState.code)
ts_echo "cluster: $CLUSTER_NAME, Power State : ${POWER_STATE}"
done
done
fi
32 changes: 0 additions & 32 deletions scripts/aks/auto-start.sh

This file was deleted.

0 comments on commit d0f7525

Please sign in to comment.