mirror of https://github.com/docker/docs.git
prevent panic in random strategy if no node
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
21ee7e1a13
commit
ebe77641c7
|
@ -18,11 +18,13 @@ type RandomPlacementStrategy struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *RandomPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []*cluster.Node) (*cluster.Node, error) {
|
func (p *RandomPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []*cluster.Node) (*cluster.Node, error) {
|
||||||
|
if size := len(nodes); size > 0 {
|
||||||
n := rand.Intn(len(nodes))
|
n := rand.Intn(len(nodes))
|
||||||
for i, node := range nodes {
|
for i, node := range nodes {
|
||||||
if i == n {
|
if i == n {
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil, errors.New("No nodes running in the cluster")
|
return nil, errors.New("No nodes running in the cluster")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue