Skip to content

Commit

Permalink
Merge branch 'master' into renovate/actions-checkout-4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanHoey96 authored Oct 24, 2023
2 parents d832c06 + e6030e5 commit c9878e0
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 296 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aks-manual-shutdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
tenant-id: 531ff96d-0ae9-462a-8d2d-bec7c0b42082 # HMCTS.NET
allow-no-subscriptions: true
- name: AKS Manual Stop
run: ./scripts/aks/manual-shutdown.sh
run: ./scripts/aks/manual-start-stop.sh stop
2 changes: 1 addition & 1 deletion .github/workflows/aks-manual-start.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
tenant-id: 531ff96d-0ae9-462a-8d2d-bec7c0b42082 # HMCTS.NET
allow-no-subscriptions: true
- name: AKS Manual Start
run: ./scripts/aks/manual-start.sh ${{ secrets.REGISTRYSLACKWEBHOOK }}
run: ./scripts/aks/manual-start-stop.sh start
2 changes: 1 addition & 1 deletion .github/workflows/manual-start.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
tenant-id: 531ff96d-0ae9-462a-8d2d-bec7c0b42082 # HMCTS.NET
allow-no-subscriptions: true
- name: AKS Manual Start in ${{ inputs.PROJECT }} ${{ inputs.SELECTED_ENV }} Environment
run: ./scripts/aks/manual-start.sh
run: ./scripts/aks/manual-start-stop.sh start
appgateway:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/parsegithubissue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
if: ${{ github.event.issue.user.login != 'renovate[bot]' }}
steps:
- name: Add eyes reaction
uses: aidan-mundy/[email protected].1
uses: aidan-mundy/[email protected].2
with:
issue-number: ${{ github.event.issue.number }}
reactions: eyes
Expand Down
28 changes: 11 additions & 17 deletions issues_list.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
[
{
"skip_start_date": "02-10-2023",
"skip_end_date": "06-10-2023",
"environment": "Preview / Dev",
"business_area": "cft",
"change_jira_id": "Requested by Robin to be kept on Monday-Friday until we have Preview postgresl change",
"issue_link": "https://github.com/hmcts/auto-shutdown/issues/155"
"skip_end_date": "03-11-2023",
"environment": "Test / Perftest",
"business_area": "cross-cutting",
"change_jira_id": "DTSPO-15384",
"issue_link": "https://github.com/hmcts/auto-shutdown/issues/168"
},
{
"skip_start_date": "11-10-2023",
"skip_end_date": "11-10-2023",
"skip_start_date": "24-10-2023",
"skip_end_date": "25-10-2023",
"environment": [
"AAT / Staging",
"Preview / Dev",
"Demo",
"PTL"
],
"business_area": "cft",
"change_jira_id": "RR-3278 - CCD 31.1.0 (Cache move to Caffeine) Release",
"issue_link": "https://github.com/hmcts/auto-shutdown/issues/159"
},
{
"skip_start_date": "02-10-2023",
"skip_end_date": "03-11-2023",
"environment": "Test / Perftest",
"business_area": "cross-cutting",
"change_jira_id": "DTSPO-15384",
"issue_link": "https://github.com/hmcts/auto-shutdown/issues/168"
"change_jira_id": "CHG5013849",
"issue_link": "https://github.com/hmcts/auto-shutdown/issues/184"
}
]
154 changes: 72 additions & 82 deletions scripts/aks/auto-start.sh
Original file line number Diff line number Diff line change
@@ -1,104 +1,94 @@
#!/usr/bin/env bash

registrySlackWebhook=$1

function subscription () {

SUBSCRIPTION_ID=$(jq -r '.id' <<< $subscription)
az account set -s $SUBSCRIPTION_ID
CLUSTERS=$(az resource list \
--resource-type Microsoft.ContainerService/managedClusters \
--query "[?tags.autoShutdown == 'true']" -o json)
function subscription() {
SUBSCRIPTION_ID=$(jq -r '.id' <<< $subscription)
az account set -s $SUBSCRIPTION_ID
CLUSTERS=$(az resource list --resource-type Microsoft.ContainerService/managedClusters --query "[?tags.autoShutdown == 'true']" -o json)
}

function cluster () {
RESOURCE_GROUP=$(jq -r '.resourceGroup' <<< $cluster)
NAME=$(jq -r '.name' <<< $cluster)
function cluster() {
RESOURCE_GROUP=$(jq -r '.resourceGroup' <<< $cluster)
NAME=$(jq -r '.name' <<< $cluster)
}

function ts_echo() {
date +"%H:%M:%S $(printf "%s " "$@")"
}

function notification() {
ts_echo "$APP works in $ENVIRONMENT after $NAME start-up"
curl -X POST --data-urlencode "payload={\"channel\": \"#aks-monitor-$ENV\", \"username\": \"AKS Auto-Start\", \"text\": \"$APP works in $ENVIRONMENT after $NAME start-up.\", \"icon_emoji\": \":tim-webster:\"}" \
${registrySlackWebhook}
local channel="$1"
local message="$2"
curl -X POST --data-urlencode "payload={\"channel\": \"$channel\", \"username\": \"AKS Auto-Start\", \"text\": \"$message\", \"icon_emoji\": \":tim-webster:\"}" \
${registrySlackWebhook}
}

SUBSCRIPTIONS=$(az account list -o json)
jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
subscription
jq -c '.[]' <<< $CLUSTERS | while read cluster; do
cluster
ts_echo "About to start cluster $NAME (rg:$RESOURCE_GROUP)"
az aks start --resource-group $RESOURCE_GROUP --name $NAME --no-wait || ts_echo Ignoring any errors starting cluster $NAME
done
done

echo "Waiting 10 mins to give clusters time to start before testing pods"
sleep 600

# Tests
jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
subscription
jq -c '.[]' <<< $CLUSTERS | while read cluster; do
cluster

BUSINESS_AREA=$(jq -r '.tags.businessArea' <<< $cluster)
if [[ "$BUSINESS_AREA" == "Cross-Cutting" ]]; then
APP="toffee"
elif [[ "$BUSINESS_AREA" == "CFT" ]]; then
APP="plum"
fi
function check_cluster_status() {
BUSINESS_AREA=$(jq -r '.tags.businessArea' <<< $cluster)
if [[ "$BUSINESS_AREA" == "Cross-Cutting" ]]; then
APP="toffee"
elif [[ "$BUSINESS_AREA" == "CFT" ]]; then
APP="plum"
fi

ENVIRONMENT=$(jq -r '.tags.environment' <<< $cluster)
ENVIRONMENT=$(jq -r '.tags.environment' <<< $cluster)

if [[ "$ENVIRONMENT" == "sandbox" || "$ENVIRONMENT" == "Sandbox" ]]; then
ENV="sbox"
elif [[ "$ENVIRONMENT" == "testing" ]]; then
ENV="perftest"
elif [[ "$ENVIRONMENT" == "staging" ]]; then
ENV="aat"
else
ENV="$ENVIRONMENT"
fi
local env_variants=(
"sandbox/Sandbox:sbox"
"testing/toffee:toffee.test"
"testing/plum:plum.perftest"
"staging/toffee:toffee.staging"
"staging/plum:plum.aat"
)

ts_echo "Test that $APP works in $ENVIRONMENT after $NAME start-up"
if [[ "$ENVIRONMENT" == "testing" && "$APP" == "toffee" ]]; then
APPLICATION="$APP.test"
elif [[ "$ENVIRONMENT" == "testing" && "$APP" == "plum" ]]; then
APPLICATION="$APP.perftest"
elif [[ "$ENVIRONMENT" == "staging" && "$APP" == "toffee" ]]; then
APPLICATION="$APP.staging"
elif [[ "$ENVIRONMENT" == "staging" && "$APP" == "plum" ]]; then
APPLICATION="$APP.aat"
else
for variant in "${env_variants[@]}"; do
parts=(${variant//:/ })
if [[ "$ENVIRONMENT/$APP" == "${parts[0]}" ]]; then
APPLICATION="${parts[1]}"
break
else
APPLICATION="$APP.$ENVIRONMENT"
fi
done

statuscode=$(curl --max-time 30 --retry 20 --retry-delay 15 -s -o /dev/null -w "%{http_code}" https://$APPLICATION.platform.hmcts.net)
ts_echo "Test that $APP works in $ENVIRONMENT after $NAME start-up"

if [[ "$ENVIRONMENT" == "demo" && $statuscode -eq 302 ]]; then
notification
elif [[ $statuscode -eq 200 ]]; then
notification
else
ts_echo "$APP does not work in $ENVIRONMENT after $NAME start-up"
curl -X POST --data-urlencode "payload={\"channel\": \"#green-daily-checks\", \"username\": \"AKS Auto-Start\", \"text\": \"$APP does not work in $ENVIRONMENT after $NAME start-up. Please check cluster.\", \"icon_emoji\": \":tim-webster:\"}" \
${registrySlackWebhook}
curl -X POST --data-urlencode "payload={\"channel\": \"#aks-monitor-$ENV\", \"username\": \"AKS Auto-Start\", \"text\": \"$APP does not work in $ENVIRONMENT after $NAME start-up. Please check cluster.\", \"icon_emoji\": \":tim-webster:\"}" \
${registrySlackWebhook}
fi
done
done

#Summary
jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
subscription
jq -c '.[]' <<< $CLUSTERS | while read cluster; do
cluster
ts_echo $NAME
RESULT=$(az aks show --name $NAME -g $RESOURCE_GROUP | jq -r .powerState.code)
ts_echo "${RESULT}"
statuscode=$(curl --max-time 30 --retry 20 --retry-delay 15 -s -o /dev/null -w "%{http_code}" https://$APPLICATION.platform.hmcts.net)

if [[ ("$ENVIRONMENT" == "demo" || $statuscode -eq 200) ]]; then
notification "#aks-monitor-$ENV" "$APP works in $ENVIRONMENT after $NAME start-up"
else
message="$APP does not work in $ENVIRONMENT after $NAME start-up. Please check cluster."
ts_echo "$message"
notification "#green-daily-checks" "$message"
notification "#aks-monitor-$ENV" "$message"
fi
}

function process_clusters() {
jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
subscription
jq -c '.[]' <<< $CLUSTERS | while read cluster; do
cluster
ts_echo "About to start cluster $NAME (rg:$RESOURCE_GROUP)"
az aks start --resource-group $RESOURCE_GROUP --name $NAME --no-wait || ts_echo Ignoring any errors starting cluster $NAME
done
done
done

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 $NAME -g $RESOURCE_GROUP | jq -r .powerState.code)
ts_echo "cluster: $NAME, Power State : ${RESULT}"
done
done
}

SUBSCRIPTIONS=$(az account list -o json)
process_clusters
76 changes: 0 additions & 76 deletions scripts/aks/manual-shutdown.sh

This file was deleted.

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

source scripts/aks/set-subscription.sh

function cluster() {
RESOURCE_GROUP=$(jq -r '.resourceGroup' <<<$cluster)
NAME=$(jq -r '.name' <<<$cluster)
}

MODE=${1:-start}

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


if [[ $INSTANCES == 'All' ]]; then
INSTANCES=(00 01)
fi

subscription # Call the subscription function from the included script
for INSTANCE in ${INSTANCES[@]}; do
CLUSTERS=$(az resource list \
--name $CLUSTER_PREFIX"-"$INSTANCE"-aks" \
--query "[?tags.autoShutdown == 'true']" -o json)
jq -c '.[]' <<<$CLUSTERS | while read cluster; do
cluster

ts_echo "About to $MODE cluster $NAME (rg:$RESOURCE_GROUP)"
az aks $MODE --resource-group $RESOURCE_GROUP --name $NAME --no-wait || ts_echo Ignoring any errors while doing $MODE operation on cluster $NAME

ts_echo "Waiting 2 mins to give clusters time to $MODE before testing pods"
sleep 120
ts_echo $NAME
RESULT=$(az aks show --name $NAME -g $RESOURCE_GROUP | jq -r .powerState.code)
ts_echo "${RESULT}"
done
done
Loading

0 comments on commit c9878e0

Please sign in to comment.