Skip to content

Commit

Permalink
Merge pull request #170 from hmcts/DTSPO-14754
Browse files Browse the repository at this point in the history
DTSPO-14754 - Env selector change
  • Loading branch information
JordanHoey96 authored Oct 5, 2023
2 parents dbaf002 + 73d138b commit cdb1316
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 115 deletions.
47 changes: 24 additions & 23 deletions .github/workflows/aks-manual-shutdown.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
name: AKS Manual Shutdown
on:
workflow_dispatch:
inputs:
PROJECT:
type: choice
description: "Business area"
options:
inputs:
PROJECT:
type: choice
description: "Business area"
options:
- SDS
- CFT
SELECTED_ENV:
type: choice
description: "Environment"
options:
- sbox
- test/perftest
- ithc
- demo
- ptlsbox
- preview
- aat
INSTANCES:
type: choice
description: "Cluster"
options:
SELECTED_ENV:
type: choice
description: "Environment"
options:
- Sandbox
- AAT / Staging
- Preview / Dev
- Test / Perftest
- Demo
- ITHC
- PTL
- PTLSBOX
INSTANCES:
type: choice
description: "Cluster"
options:
- All
- '00'
- '01'
- "00"
- "01"
env:
PROJECT: ${{ inputs.PROJECT }}
SELECTED_ENV: ${{ inputs.SELECTED_ENV }}
Expand All @@ -38,7 +39,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: 'Az CLI login'
- name: "Az CLI login"
uses: azure/login@v1
with:
client-id: 2b6fa9d7-7dba-4600-a58a-5e25554997aa # DTS AKS Auto-Shutdown
Expand Down
47 changes: 24 additions & 23 deletions .github/workflows/aks-manual-start.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
name: AKS Manual Start
on:
workflow_dispatch:
inputs:
PROJECT:
type: choice
description: "Business area"
options:
inputs:
PROJECT:
type: choice
description: "Business area"
options:
- SDS
- CFT
SELECTED_ENV:
type: choice
description: "Environment"
options:
- sbox
- test/perftest
- ithc
- demo
- ptlsbox
- preview
- aat
INSTANCES:
type: choice
description: "Cluster"
options:
SELECTED_ENV:
type: choice
description: "Environment"
options:
- Sandbox
- AAT / Staging
- Preview / Dev
- Test / Perftest
- Demo
- ITHC
- PTL
- PTLSBOX
INSTANCES:
type: choice
description: "Cluster"
options:
- All
- '00'
- '01'
- "00"
- "01"
env:
PROJECT: ${{ inputs.PROJECT }}
SELECTED_ENV: ${{ inputs.SELECTED_ENV }}
Expand All @@ -38,7 +39,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: 'Az CLI login'
- name: "Az CLI login"
uses: azure/login@v1
with:
client-id: 2b6fa9d7-7dba-4600-a58a-5e25554997aa # DTS AKS Auto-Shutdown
Expand Down
109 changes: 64 additions & 45 deletions scripts/aks/manual-shutdown.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,76 @@
#!/usr/bin/env bash

function subscription () {
if [[ $SELECTED_ENV == "test/perftest" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SELECTED_ENV="test"
SUBSCRIPTION='DTS-SHAREDSERVICES-'$SELECTED_ENV
elif [[ $SELECTED_ENV == "test/perftest" && $PROJECT == "CFT" ]]; then
SELECTED_ENV="perftest"
SUBSCRIPTION='DCD-CFTAPPS-TEST'
elif [[ $SELECTED_ENV == "ptlsbox" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SUBSCRIPTION='DTS-SHAREDSERVICESPTL-SBOX'
elif [[ $SELECTED_ENV == "ptlsbox" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION='DTS-CFTSBOX-INTSVC'
elif [[ $SELECTED_ENV != "test/perftest" && $SELECTED_ENV != "ptlsbox" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SUBSCRIPTION='DTS-SHAREDSERVICES-'$SELECTED_ENV
elif [[ $SELECTED_ENV != "test/perftest" && $SELECTED_ENV != "ptlsbox" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION='DCD-CFTAPPS-'$SELECTED_ENV
fi

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

az account set -n $SUBSCRIPTION
ts_echo $SUBSCRIPTION selected
function subscription() {
if [[ $SELECTED_ENV =~ "Test / Perftest" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SELECTED_ENV="test"
SUBSCRIPTION="DTS-SHAREDSERVICES-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "Test / Perftest" && $PROJECT == "CFT" ]]; then
SELECTED_ENV="perftest"
SUBSCRIPTION="DCD-CFTAPPS-TEST"
elif [[ $SELECTED_ENV =~ "Preview / Dev" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SELECTED_ENV="DEV"
SUBSCRIPTION="DTS-SHAREDSERVICES-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "Preview / Dev" && $PROJECT == "CFT" ]]; then
SELECTED_ENV="DEV"
SUBSCRIPTION="DCD-CFTAPPS-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "AAT / Staging" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SELECTED_ENV="stg"
SUBSCRIPTION="DTS-SHAREDSERVICES-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "AAT / Staging" && $PROJECT == "CFT" ]]; then
SELECTED_ENV="stg"
SUBSCRIPTION="DCD-CFTAPPS-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "PTLSBOX" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SUBSCRIPTION="DTS-SHAREDSERVICESPTL-SBOX"
elif [[ $SELECTED_ENV =~ "PLTSBOX" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DTS-CFTSBOX-INTSVC"
elif [[ $SELECTED_ENV =~ "PTL" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DTS-CFTPTL-INTSVC"
elif [[ $SELECTED_ENV == "PTL" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SUBSCRIPTION="DTS-SHAREDSERVICESPTL"
elif [[ $SELECTED_ENV != "Test / Perftest" && $SELECTED_ENV != "Preview / Dev" && $SELECTED_ENV != "AAT / Staging" && $SELECTED_ENV != "PTL" && $SELECTED_ENV != "PLTSBOX" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SUBSCRIPTION="DTS-SHAREDSERVICES-$SELECTED_ENV"
elif [[ $SELECTED_ENV != "Test / Perftest" && $SELECTED_ENV != "Preview / Dev" && $SELECTED_ENV != "AAT / Staging" && $SELECTED_ENV != "PTL" && $SELECTED_ENV != "PLTSBOX" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DCD-CFTAPPS-$SELECTED_ENV"
fi

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

az account set -n $SUBSCRIPTION
ts_echo $SUBSCRIPTION selected
}

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 " "$@")"
date +"%H:%M:%S $(printf "%s " "$@")"
}

subscription
for INSTANCE in ${INSTANCES[@]}; do
CLUSTERS=$(az resource list \
--name $PROJECT"-"$SELECTED_ENV"-"$INSTANCE"-aks" \
--query "[?tags.autoShutdown == 'true']" -o json)
jq -c '.[]' <<< $CLUSTERS | while read cluster; do
cluster
ts_echo "About to stop cluster $NAME (rg:$RESOURCE_GROUP)"
az aks stop --resource-group $RESOURCE_GROUP --name $NAME --no-wait || ts_echo Ignoring any errors starting cluster $NAME
ts_echo "Waiting 2 mins to give clusters time to stop 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
CLUSTERS=$(az resource list \
--name $PROJECT"-"$SELECTED_ENV"-"$INSTANCE"-aks" \
--query "[?tags.autoShutdown == 'true']" -o json)
jq -c '.[]' <<<$CLUSTERS | while read cluster; do
cluster

ts_echo "About to stop cluster $NAME (rg:$RESOURCE_GROUP)"
az aks stop --resource-group $RESOURCE_GROUP --name $NAME --no-wait || ts_echo Ignoring any errors starting cluster $NAME

ts_echo "Waiting 2 mins to give clusters time to stop 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
48 changes: 24 additions & 24 deletions scripts/aks/manual-start.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
#!/usr/bin/env bash

function subscription() {
if [[ $SELECTED_ENV == "test/perftest" && $PROJECT == "SDS" ]]; then
if [[ $SELECTED_ENV =~ "Test / Perftest" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SELECTED_ENV="test"
SUBSCRIPTION='DTS-SHAREDSERVICES-'$SELECTED_ENV
elif [[ $SELECTED_ENV == "test/perftest" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DTS-SHAREDSERVICES-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "Test / Perftest" && $PROJECT == "CFT" ]]; then
SELECTED_ENV="perftest"
SUBSCRIPTION='DCD-CFTAPPS-TEST'
elif [[ $SELECTED_ENV == "preview/dev" && $PROJECT == "SDS" ]]; then
SUBSCRIPTION="DCD-CFTAPPS-TEST"
elif [[ $SELECTED_ENV =~ "Preview / Dev" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SELECTED_ENV="DEV"
SUBSCRIPTION='DTS-SHAREDSERVICES-'$SELECTED_ENV
elif [[ $SELECTED_ENV == "preview/dev" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DTS-SHAREDSERVICES-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "Preview / Dev" && $PROJECT == "CFT" ]]; then
SELECTED_ENV="DEV"
SUBSCRIPTION='DCD-CFTAPPS-'$SELECTED_ENV
elif [[ $SELECTED_ENV == "aat/staging" && $PROJECT == "SDS" ]]; then
SUBSCRIPTION="DCD-CFTAPPS-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "AAT / Staging" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SELECTED_ENV="stg"
SUBSCRIPTION='DTS-SHAREDSERVICES-'$SELECTED_ENV
elif [[ $SELECTED_ENV == "aat/staging" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DTS-SHAREDSERVICES-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "AAT / Staging" && $PROJECT == "CFT" ]]; then
SELECTED_ENV="stg"
SUBSCRIPTION='DCD-CFTAPPS-'$SELECTED_ENV
elif [[ $SELECTED_ENV == "ptlsbox" && $PROJECT == "SDS" ]]; then
SUBSCRIPTION="DCD-CFTAPPS-$SELECTED_ENV"
elif [[ $SELECTED_ENV =~ "PTLSBOX" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SUBSCRIPTION='DTS-SHAREDSERVICESPTL-SBOX'
elif [[ $SELECTED_ENV == "ptlsbox" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION='DTS-CFTSBOX-INTSVC'
elif [[ $SELECTED_ENV == "ptl" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION='DTS-CFTPTL-INTSVC'
elif [[ $SELECTED_ENV == "ptl" && $PROJECT == "SDS" ]]; then
SUBSCRIPTION="DTS-SHAREDSERVICESPTL-SBOX"
elif [[ $SELECTED_ENV =~ "PLTSBOX" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DTS-CFTSBOX-INTSVC"
elif [[ $SELECTED_ENV =~ "PTL" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DTS-CFTPTL-INTSVC"
elif [[ $SELECTED_ENV == "PTL" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SUBSCRIPTION='DTS-SHAREDSERVICESPTL'
elif [[ $SELECTED_ENV != "test/perftest" && $SELECTED_ENV != "preview/dev" && $SELECTED_ENV != "aat/staging" && $SELECTED_ENV != "ptl" && $SELECTED_ENV != "ptlsbox" && $PROJECT == "SDS" ]]; then
SUBSCRIPTION="DTS-SHAREDSERVICESPTL"
elif [[ $SELECTED_ENV != "Test / Perftest" && $SELECTED_ENV != "Preview / Dev" && $SELECTED_ENV != "AAT / Staging" && $SELECTED_ENV != "PTL" && $SELECTED_ENV != "PLTSBOX" && $PROJECT == "SDS" ]]; then
PROJECT="ss"
SUBSCRIPTION='DTS-SHAREDSERVICES-'$SELECTED_ENV
elif [[ $SELECTED_ENV != "test/perftest" && $SELECTED_ENV != "preview/dev" && $SELECTED_ENV != "aat/staging" && $SELECTED_ENV != "ptl" && $SELECTED_ENV != "ptlsbox" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION='DCD-CFTAPPS-'$SELECTED_ENV
SUBSCRIPTION="DTS-SHAREDSERVICES-$SELECTED_ENV"
elif [[ $SELECTED_ENV != "Test / Perftest" && $SELECTED_ENV != "Preview / Dev" && $SELECTED_ENV != "AAT / Staging" && $SELECTED_ENV != "PTL" && $SELECTED_ENV != "PLTSBOX" && $PROJECT == "CFT" ]]; then
SUBSCRIPTION="DCD-CFTAPPS-$SELECTED_ENV"
fi

if [[ $INSTANCES == 'All' ]]; then
Expand Down

0 comments on commit cdb1316

Please sign in to comment.