Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/aks-preview/azcli_aks_live_test/scripts/clean_up.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
#!/usr/bin/env bash

# bash options
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# check var
[[ -z "${TENANT_ID}" ]] && (echo "TENANT_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_SUBSCRIPTION_ID}" ]] && (echo "AZCLI_ALT_SUBSCRIPTION_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_CLIENT_ID}" ]] && (echo "AZCLI_ALT_CLIENT_ID is empty"; exit 1)
[[ -z "${AZCLI_ALT_CLIENT_SECRET}" ]] && (echo "AZCLI_ALT_CLIENT_SECRET is empty"; exit 1)
[[ -z "${LOOKBACK}" ]] && (echo "LOOKBACK is empty"; exit 1)
[[ -z "${PREFIX}" ]] && (echo "PREFIX is empty"; exit 1)

# login
az login --service-principal -u "${AZCLI_ALT_CLIENT_ID}" -p "${AZCLI_ALT_CLIENT_SECRET}" -t "${TENANT_ID}"
az account set -s "${AZCLI_ALT_SUBSCRIPTION_ID}"
az account show

# list the details of resource groups whose names start with "clitest"
az group list --query "([].name)[?starts_with(@, 'clitest')]" -o tsv | xargs -i az group show -n {}
# get lookback date
cond_date=$(date -u -d "${LOOKBACK} hours ago" '+%Y-%m-%dT%H:%M:%SZ')

# list matched result
az group list --query "[? @.tags.date < '${cond_date}'] | [? starts_with(@.name, '${PREFIX}')]"
echo "Length:" $(az group list --query "[? @.tags.date < '${cond_date}'] | [? starts_with(@.name, '${PREFIX}')] | length(@)")

# delete all resource groups whose names start with "clitest"
# az group list --query "([].name)[?starts_with(@, 'clitest')]" -o tsv | xargs -i az group delete --no-wait -y -n {}
# delete
az group list --query "[? @.tags.date < '${cond_date}'] | [? starts_with(@.name, '${PREFIX}')].name" -o tsv | xargs -i az group delete --no-wait -y -n {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: $(Date:yyyyMMdd)$(Rev:.r-)-CleanUp

trigger: none

pool:
name: 1ES-AKS-Elastic-DevInfra-Auto-TearDown-Pool

variables:
- group: azcli-aks-tool
- name: LIVE_TEST_BASE_DIR
value: "src/aks-preview/azcli_aks_live_test"

jobs:
- job: CleanUp
timeoutInMinutes: 60
displayName: "Clean Up"
steps:
- bash: |
$(LIVE_TEST_BASE_DIR)/scripts/clean_up.sh
env:
AZCLI_ALT_CLIENT_SECRET: $(AZCLI_ALT_CLIENT_SECRET)
displayName: "Clean up outdated resource groups"