-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into r2k1/amd-gpu
- Loading branch information
Showing
5 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
pool: | ||
name: $(POOL_NAME) | ||
|
||
parameters: | ||
- name: DRY_RUN | ||
displayName: Dry Run | ||
type: boolean | ||
default: false | ||
|
||
jobs: | ||
- job: gc | ||
displayName: Garbage Collection | ||
steps: | ||
- checkout: self | ||
fetchTags: false | ||
fetchDepth: 1 | ||
|
||
- bash: | | ||
chmod +x ./vhdbuilder/scripts/gc.sh | ||
./vhdbuilder/scripts/gc.sh | ||
env: | ||
SUBSCRIPTION_ID: $(SUBSCRIPTION_ID) | ||
DRY_RUN: ${{ parameters.DRY_RUN }} | ||
displayName: Garbage collect resource groups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,8 @@ retrycmd_if_failure() { | |
|
||
set_git_config() { | ||
# git config needs to be set in the agent | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "aks-node" | ||
git config --global user.email "aks-node-assistant@microsoft.com" | ||
git config --global user.name "aks-node-assistant" | ||
git config --list | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
[ -z "${SUBSCRIPTION_ID:-}" ] && echo "SUBSCRIPTION_ID must be set" && exit 1 | ||
|
||
SKIP_TAG_NAME="gc.skip" | ||
SKIP_TAG_VALUE="true" | ||
|
||
DRY_RUN="${DRY_RUN:-}" | ||
|
||
DAY_AGO=$(( $(date +%s) - 86400 )) # 24 hours ago | ||
WEEK_AGO=$(( $(date +%s) - 604800 )) # 7 days ago | ||
|
||
function main() { | ||
az login --identity # relies on an appropriately permissioned identity being attached to the build agent | ||
az account set -s $SUBSCRIPTION_ID | ||
|
||
echo "garbage collecting ephemeral resource groups..." | ||
cleanup_rgs || exit $? | ||
|
||
# TODO(cameissner): migrate linux VHD build back-fill deletion logic to this script | ||
} | ||
|
||
function cleanup_rgs() { | ||
groups=$(az group list | jq -r --arg dl $DAY_AGO '.[] | select(.name | test("vhd-test*|vhd-scanning*|pkr-Resource-Group*")) | select(.tags.now < $dl).name' | tr -d '\"' || "") | ||
if [ -z "$groups" ]; then | ||
echo "no resource groups found for garbage collection" | ||
return 0 | ||
fi | ||
|
||
for group in $groups; do | ||
echo "resource group $group is in-scope for garbage collection" | ||
group_object=$(az group show -g $group) | ||
tag_value=$(echo "$group_object" | jq -r --arg skipTagName $SKIP_TAG_NAME '.tags."\($skipTagName)"') | ||
|
||
if [ "${tag_value,,}" == "$SKIP_TAG_VALUE" ]; then | ||
now=$(echo "$group_object" | jq -r '.tags.now') | ||
if [ "$now" != "null" ] && [ $now -lt $WEEK_AGO ]; then | ||
echo "resource group $group is tagged with $SKIP_TAG_NAME=$SKIP_TAG_VALUE but is more than 7 days old, will attempt to delete..." | ||
delete_group $group || return $? | ||
fi | ||
continue | ||
fi | ||
|
||
echo "will attempt to delete resource group $group" | ||
delete_group $group || return $? | ||
done | ||
} | ||
|
||
function delete_group() { | ||
local group=$1 | ||
|
||
if [ "${DRY_RUN,,}" == "true" ]; then | ||
echo "DRY_RUN: az group delete -g $group --yes --no-wait" | ||
return 0 | ||
fi | ||
|
||
az group delete -g $group --yes --no-wait || return $? | ||
} | ||
|
||
main "$@" |