diff --git a/.github/workflows/aks-manual-shutdown.yaml b/.github/workflows/aks-manual-shutdown.yaml index 06bf8940..62bac047 100644 --- a/.github/workflows/aks-manual-shutdown.yaml +++ b/.github/workflows/aks-manual-shutdown.yaml @@ -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 diff --git a/.github/workflows/aks-manual-start.yaml b/.github/workflows/aks-manual-start.yaml index 94d916e1..89cebe39 100644 --- a/.github/workflows/aks-manual-start.yaml +++ b/.github/workflows/aks-manual-start.yaml @@ -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 diff --git a/.github/workflows/manual-start.yaml b/.github/workflows/manual-start.yaml index 648e9828..362c7341 100644 --- a/.github/workflows/manual-start.yaml +++ b/.github/workflows/manual-start.yaml @@ -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: diff --git a/.github/workflows/parsegithubissue.yaml b/.github/workflows/parsegithubissue.yaml index b65df974..222fe8d9 100644 --- a/.github/workflows/parsegithubissue.yaml +++ b/.github/workflows/parsegithubissue.yaml @@ -17,7 +17,7 @@ jobs: if: ${{ github.event.issue.user.login != 'renovate[bot]' }} steps: - name: Add eyes reaction - uses: aidan-mundy/react-to-issue@v1.1.1 + uses: aidan-mundy/react-to-issue@v1.1.2 with: issue-number: ${{ github.event.issue.number }} reactions: eyes diff --git a/issues_list.json b/issues_list.json index 12ca9774..b936ebe3 100644 --- a/issues_list.json +++ b/issues_list.json @@ -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" } ] \ No newline at end of file diff --git a/scripts/aks/auto-start.sh b/scripts/aks/auto-start.sh index 3063f012..994a115b 100755 --- a/scripts/aks/auto-start.sh +++ b/scripts/aks/auto-start.sh @@ -1,18 +1,16 @@ #!/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() { @@ -20,85 +18,77 @@ function ts_echo() { } 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 diff --git a/scripts/aks/manual-shutdown.sh b/scripts/aks/manual-shutdown.sh deleted file mode 100755 index 4c06909a..00000000 --- a/scripts/aks/manual-shutdown.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/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 =~ "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 ts_echo() { - 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 -done diff --git a/scripts/aks/manual-start-stop.sh b/scripts/aks/manual-start-stop.sh new file mode 100755 index 00000000..7c7d792f --- /dev/null +++ b/scripts/aks/manual-start-stop.sh @@ -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 \ No newline at end of file diff --git a/scripts/aks/manual-start.sh b/scripts/aks/manual-start.sh deleted file mode 100755 index 91652bb4..00000000 --- a/scripts/aks/manual-start.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/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 =~ "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 ts_echo() { - 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 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 - - ts_echo "Waiting 2 mins to give clusters time to start 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 diff --git a/scripts/aks/resource-details.sh b/scripts/aks/resource-details.sh index 7de78097..b5088867 100755 --- a/scripts/aks/resource-details.sh +++ b/scripts/aks/resource-details.sh @@ -9,6 +9,7 @@ business_area_entry=$(jq -r '. | last | .business_area' issues_list.json) #declare associative array declare -A sku_sizes +source scripts/aks/set-subscription.sh #Function to add SKU and node count to array. #Create new entry if SKU does not already exist. Update entry if SKU already exists in array. function countSku() { @@ -66,49 +67,13 @@ function get_costs() { #Set subscription based on user entry. #If statements used to deal with subscription naming convention and enviornment dropdown values. Eg "AAT / Staging" while read i; do + PROJECT="CFT" if [[ $business_area_entry =~ "Cross-Cutting" ]]; then - echo "processing $i in $business_area_entry" - if [[ $i =~ "Staging" ]]; then - az account set --name DTS-SHAREDSERVICES-STG - get_costs - elif [[ $i =~ "dev" ]]; then - az account set --name DTS-SHAREDSERVICES-DEV - get_costs - elif [[ $i =~ "test" ]]; then - az account set --name DTS-SHAREDSERVICES-TEST - get_costs - elif [[ $i =~ "sandbox" ]]; then - az account set --name DTS-SHAREDSERVICES-SBOX - get_costs - elif [[ $i == "ptl" ]]; then - az account set --name DTS-SHAREDSERVICESPTL - get_costs - else - az account set --name DTS-SHAREDSERVICES-$i - get_costs - fi - elif [[ $business_area_entry =~ "CFT" ]]; then - echo "processing $i" - if [[ $i =~ "AAT" ]]; then - az account set --name DCD-CFTAPPS-STG - get_costs - elif [[ $i =~ "Preview" ]]; then - az account set --name DCD-CFTAPPS-DEV - get_costs - elif [[ $i =~ "Perftest" ]]; then - az account set --name DCD-CFTAPPS-TEST - get_costs - elif [[ $i =~ "Sandbox" ]]; then - az account set --name DCD-CFTAPPS-SBOX - get_costs - elif [[ $i == "ptl" ]]; then - az account set --name DTS-CFTPTL-INTSVC - get_costs - else - az account set --name DCD-CFTAPPS-$i - get_costs - fi + PROJECT="SDS" fi + SELECTED_ENV=$i + subscription + get_costs done < <(jq -r 'last | .environment[]' issues_list.json || jq -r 'last | .environment' issues_list.json) #Add GitHub env vars diff --git a/scripts/aks/set-subscription.sh b/scripts/aks/set-subscription.sh new file mode 100644 index 00000000..1489ea1a --- /dev/null +++ b/scripts/aks/set-subscription.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Define an associative array for subscription names, cluster name prefixes +declare -A SUBSCRIPTION_CLUSTERMAP + +SUBSCRIPTION_CLUSTERMAP["CFT,Sandbox"]="DCD-CFTAPPS-SBOX,CFT-SBOX" +SUBSCRIPTION_CLUSTERMAP["CFT,AAT / Staging"]="DCD-CFTAPPS-STG,CFT-AAT" +SUBSCRIPTION_CLUSTERMAP["CFT,Test / Perftest"]="DCD-CFTAPPS-TEST,CFT-PERFTEST" +SUBSCRIPTION_CLUSTERMAP["CFT,Preview / Dev"]="DCD-CFTAPPS-DEV,CFT-PREVIEW" +SUBSCRIPTION_CLUSTERMAP["CFT,Demo"]="DCD-CFTAPPS-DEMO,CFT-DEMO" +SUBSCRIPTION_CLUSTERMAP["CFT,ITHC"]="DCD-CFTAPPS-ITHC,CFT-ITHC" +SUBSCRIPTION_CLUSTERMAP["CFT,PTL"]="DTS-CFTPTL-INTSVC,CFT-PTL" +SUBSCRIPTION_CLUSTERMAP["CFT,PTLSBOX"]="DTS-CFTSBOX-INTSVC,CFT-PTLSBOX" + +SUBSCRIPTION_CLUSTERMAP["SDS,Sandbox"]="DTS-SHAREDSERVICES-SBOX,SS-SBOX" +SUBSCRIPTION_CLUSTERMAP["SDS,AAT / Staging"]="DTS-SHAREDSERVICES-STG,SS-STG" +SUBSCRIPTION_CLUSTERMAP["SDS,Test / Perftest"]="DTS-SHAREDSERVICES-TEST,SS-TEST" +SUBSCRIPTION_CLUSTERMAP["SDS,Preview / Dev"]="DTS-SHAREDSERVICES-DEV,SS-DEV" +SUBSCRIPTION_CLUSTERMAP["SDS,Demo"]="DTS-SHAREDSERVICES-DEMO,SS-DEMO" +SUBSCRIPTION_CLUSTERMAP["SDS,ITHC"]="DTS-SHAREDSERVICES-ITHC,SS-ITHC" +SUBSCRIPTION_CLUSTERMAP["SDS,PTL"]="DTS-SHAREDSERVICESPTL,SS-PTL" +SUBSCRIPTION_CLUSTERMAP["SDS,PTLSBOX"]="DTS-SHAREDSERVICESPTL-SBOX,SS-PTLSBOX" + +function subscription() { + key="${PROJECT},${SELECTED_ENV}" + SUBSCRIPTION=$(echo ${SUBSCRIPTION_CLUSTERMAP[$key]} | cut -d ',' -f 1) + CLUSTER_PREFIX=$(echo ${SUBSCRIPTION_CLUSTERMAP[$key]} | cut -d ',' -f 2) + + az account set -n $SUBSCRIPTION + ts_echo $SUBSCRIPTION selected +} + +function ts_echo() { + date +"%H:%M:%S $(printf "%s " "$@")" +} \ No newline at end of file