forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaledownagentpool.go
44 lines (40 loc) · 1.29 KB
/
scaledownagentpool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package operations
import (
"container/list"
"github.com/Azure/acs-engine/pkg/armhelpers"
log "github.com/sirupsen/logrus"
)
//VMScalingErrorDetails give the index in the agent pool that failed and the accompanying error
type VMScalingErrorDetails struct {
Name string
Error error
}
// ScaleDownVMs removes the vms in the provided list. Returns a list with details on each failure.
// all items in the list will always be of type *VMScalingErrorDetails
func ScaleDownVMs(az armhelpers.ACSEngineClient, logger *log.Entry, resourceGroup string, vmNames ...string) *list.List {
numVmsToDelete := len(vmNames)
errChan := make(chan *VMScalingErrorDetails, numVmsToDelete)
defer close(errChan)
for _, vmName := range vmNames {
go func(vmName string) {
err := CleanDeleteVirtualMachine(az, logger, resourceGroup, vmName)
if err != nil {
errChan <- &VMScalingErrorDetails{Name: vmName, Error: err}
return
}
errChan <- nil
}(vmName)
}
failedVMDeletions := &list.List{}
for i := 0; i < numVmsToDelete; i++ {
errDetails := <-errChan
if errDetails != nil {
failedVMDeletions.PushBack(errDetails)
logger.Errorf("Vm '%s' failed to delete with error: '%s'", errDetails.Name, errDetails.Error.Error())
}
}
if failedVMDeletions.Len() > 0 {
return failedVMDeletions
}
return nil
}