-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Azure Clouds (#2795)
* Add support for Azure Clouds --------- Co-authored-by: narrieta <narrieta>
- Loading branch information
Showing
14 changed files
with
261 additions
and
106 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 |
---|---|---|
|
@@ -19,3 +19,4 @@ azure-core | |
azure-identity | ||
azure-mgmt-compute>=22.1.0 | ||
azure-mgmt-resource>=15.0.0 | ||
msrestazure |
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
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 |
---|---|---|
@@ -1,58 +1,59 @@ | ||
# | ||
# Pipeline for cleaning up any remaining Resource Groups generated by the Azure.WALinuxAgent pipeline. | ||
# | ||
# Deletes any resource groups that are more than a day old and contain string "lisa-WALinuxAgent-" | ||
# Deletes any resource groups that are older than 'older_than' and match the 'name_pattern' regular expression | ||
# | ||
schedules: | ||
- cron: "0 */12 * * *" # Run twice a day (every 12 hours) | ||
displayName: cleanup build | ||
branches: | ||
include: | ||
- develop | ||
always: true | ||
|
||
trigger: | ||
- develop | ||
parameters: | ||
- name: name_pattern | ||
displayName: Regular expression to match the name of the resource groups to delete | ||
type: string | ||
default: lisa-WALinuxAgent-.* | ||
|
||
pr: none | ||
- name: older_than | ||
displayName: Delete resources older than (use the syntax of the "date -d" command) | ||
type: string | ||
default: 1 day ago | ||
|
||
- name: service_connections | ||
type: object | ||
default: | ||
- azuremanagement | ||
# | ||
# TODO: Enable these services connections once we create test pipelines for all Azure clouds | ||
# | ||
# - azuremanagement.china | ||
# - azuremanagement.government | ||
|
||
pool: | ||
vmImage: ubuntu-latest | ||
|
||
variables: | ||
- name: azureConnection | ||
value: 'azuremanagement' | ||
- name: rgPrefix | ||
value: 'lisa-WALinuxAgent-' | ||
|
||
steps: | ||
- ${{ each service_connection in parameters.service_connections }}: | ||
- task: AzureCLI@2 | ||
inputs: | ||
azureSubscription: ${{ service_connection }} | ||
scriptType: 'bash' | ||
scriptLocation: 'inlineScript' | ||
inlineScript: | | ||
set -euxo pipefail | ||
- task: AzureKeyVault@2 | ||
displayName: "Fetch secrets from KV" | ||
inputs: | ||
azureSubscription: '$(azureConnection)' | ||
KeyVaultName: 'dcrV2SPs' | ||
SecretsFilter: '*' | ||
RunAsPreJob: true | ||
# | ||
# We use the REST API to list the resource groups because we need the createdTime and that | ||
# property is not available via the az-cli commands. | ||
# | ||
subscription_id=$(az account list --all --query "[?isDefault].id" -o tsv) | ||
date=$(date --utc +%Y-%m-%d'T'%H:%M:%S.%N'Z' -d "${{ parameters.older_than }}") | ||
- task: AzureCLI@2 | ||
inputs: | ||
azureSubscription: '$(azureConnection)' | ||
scriptType: 'bash' | ||
scriptLocation: 'inlineScript' | ||
inlineScript: | | ||
set -euxo pipefail | ||
date=`date --utc +%Y-%m-%d'T'%H:%M:%S.%N'Z' -d "1 day ago"` | ||
# Using the Azure REST GET resourceGroups API call as we can add the createdTime to the results. | ||
# This feature is not available via the az-cli commands directly so we have to use the Azure REST APIs | ||
|
||
az rest --method GET \ | ||
--url "https://management.azure.com/subscriptions/$(SUBSCRIPTION-ID)/resourcegroups" \ | ||
--url-parameters api-version=2021-04-01 \$expand=createdTime \ | ||
--output json \ | ||
--query value \ | ||
| jq --arg date "$date" '.[] | select (.createdTime < $date).name' \ | ||
| grep "$(rgPrefix)" \ | ||
| xargs -l -t -r az group delete --no-wait -y -n \ | ||
|| echo "No resource groups found to delete" | ||
rest_endpoint=$(az cloud show --query "endpoints.resourceManager" -o tsv) | ||
az rest --method GET \ | ||
--url "${rest_endpoint}/subscriptions/${subscription_id}/resourcegroups" \ | ||
--url-parameters api-version=2021-04-01 \$expand=createdTime \ | ||
--output json \ | ||
--query value \ | ||
| jq --arg date "$date" '.[] | select (.createdTime < $date).name' \ | ||
| grep '${{ parameters.name_pattern }}' \ | ||
| xargs -l -t -r az group delete --no-wait -y -n \ | ||
|| echo "No resource groups found to delete" |
Oops, something went wrong.