mirror of
https://github.com/docker/docs.git
synced 2026-04-12 06:19:22 +07:00
Make the random placement strategy truly random.
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -2,18 +2,27 @@ package strategy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/docker/libcluster"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
}
|
||||
|
||||
// Randomly place the container into the cluster.
|
||||
type RandomPlacementStrategy struct {
|
||||
}
|
||||
|
||||
func (p *RandomPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []*libcluster.Node) (*libcluster.Node, error) {
|
||||
for _, node := range nodes {
|
||||
return node, nil
|
||||
n := rand.Intn(len(nodes))
|
||||
for i, node := range nodes {
|
||||
if i == n {
|
||||
return node, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("No nodes running in the cluster")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user