ci/tests: scheduled cloud-cleaner for Azure
This introduces a script to run cloud-cleaner with a schedule. It's currently working with Azure only and therefore needed a change to cloud-cleaner code as well. Using azure-cli it gets a list of resources from $AZURE_RESOURCE_GROUP and then sorts out only resources that are older than $HOURS_BACK and are not storage accounts. Then it processes the list further leaving only list with unique TEST_ID to supply to the cloud-cleaner.
This commit is contained in:
parent
d927bfbd30
commit
a3ac31a483
3 changed files with 97 additions and 19 deletions
|
|
@ -156,17 +156,26 @@ func cleanupAzure(testID string, wg *sync.WaitGroup) {
|
|||
|
||||
func main() {
|
||||
log.Println("Running a cloud cleanup")
|
||||
|
||||
// Get test ID
|
||||
testID, err := test.GenerateCIArtifactName("")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get testID: %v", err)
|
||||
}
|
||||
log.Printf("TEST_ID=%s", testID)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go cleanupAzure(testID, &wg)
|
||||
go cleanupGCP(testID, &wg)
|
||||
wg.Wait()
|
||||
|
||||
// Currently scheduled cloud-cleaner supports Azure only.
|
||||
// In case of scheduled cleanup get testID from env and run Azure cleanup.
|
||||
// If it's empty generate it and cleanup both GCP and Azure.
|
||||
testID := os.Getenv("TEST_ID")
|
||||
if testID == "" {
|
||||
testID, err := test.GenerateCIArtifactName("")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get testID: %v", err)
|
||||
}
|
||||
log.Printf("TEST_ID=%s", testID)
|
||||
wg.Add(2)
|
||||
go cleanupAzure(testID, &wg)
|
||||
go cleanupGCP(testID, &wg)
|
||||
wg.Wait()
|
||||
} else {
|
||||
wg.Add(1)
|
||||
go cleanupAzure(testID, &wg)
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue