From 567442680b81ac4a3cf9f856ec0d37c1215c884b Mon Sep 17 00:00:00 2001 From: Praveen Adusumilli <47391951+adusumillipraveen@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:25:46 +0100 Subject: [PATCH] Make AKS start script more readable (#176) --- scripts/aks/manual-start.sh | 63 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/scripts/aks/manual-start.sh b/scripts/aks/manual-start.sh index 91652bb4..e8fc6040 100755 --- a/scripts/aks/manual-start.sh +++ b/scripts/aks/manual-start.sh @@ -1,43 +1,30 @@ #!/usr/bin/env 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() { - 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 + key="${PROJECT},${SELECTED_ENV}" + SUBSCRIPTION=$(echo ${SUBSCRIPTION_CLUSTERMAP[$key]} | cut -d ',' -f 1) + CLUSTER_PREFIX=$(echo ${SUBSCRIPTION_CLUSTERMAP[$key]} | cut -d ',' -f 2) if [[ $INSTANCES == 'All' ]]; then INSTANCES=(00 01) @@ -59,7 +46,7 @@ function ts_echo() { subscription for INSTANCE in ${INSTANCES[@]}; do CLUSTERS=$(az resource list \ - --name $PROJECT"-"$SELECTED_ENV"-"$INSTANCE"-aks" \ + --name $CLUSTER_PREFIX"-"$INSTANCE"-aks" \ --query "[?tags.autoShutdown == 'true']" -o json) jq -c '.[]' <<<$CLUSTERS | while read cluster; do cluster