GCE: Allow nodes to exceed target pool maximums

If we would exceeded the TargetPool API maximums, instead just
randomly select some subsection of the nodes to include in the TP
instead.
This commit is contained in:
Zach Loafman
2016-05-04 15:11:16 -07:00
parent e973b5d27a
commit faf0c44429
4 changed files with 211 additions and 26 deletions

View File

@@ -65,3 +65,19 @@ func String(length int) string {
}
return string(b)
}
// A type that satisfies the rand.Shufflable interface can be shuffled
// by Shuffle. Any sort.Interface will satisfy this interface.
type Shufflable interface {
Len() int
Swap(i, j int)
}
func Shuffle(data Shufflable) {
rng.Lock()
defer rng.Unlock()
for i := 0; i < data.Len(); i++ {
j := rng.rand.Intn(i + 1)
data.Swap(i, j)
}
}