mirror of https://github.com/docker/docs.git
Merge pull request #960 from ahmetalpbalkan/random
scheduler/random: Use private instance of rand
This commit is contained in:
commit
077489a948
|
@ -10,11 +10,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// RandomPlacementStrategy randomly places the container into the cluster.
|
// RandomPlacementStrategy randomly places the container into the cluster.
|
||||||
type RandomPlacementStrategy struct{}
|
type RandomPlacementStrategy struct {
|
||||||
|
r *rand.Rand
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize is exported
|
// Initialize is exported
|
||||||
func (p *RandomPlacementStrategy) Initialize() error {
|
func (p *RandomPlacementStrategy) Initialize() error {
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
p.r = rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +28,7 @@ func (p *RandomPlacementStrategy) Name() string {
|
||||||
// PlaceContainer is exported
|
// PlaceContainer is exported
|
||||||
func (p *RandomPlacementStrategy) PlaceContainer(config *cluster.ContainerConfig, nodes []*node.Node) (*node.Node, error) {
|
func (p *RandomPlacementStrategy) PlaceContainer(config *cluster.ContainerConfig, nodes []*node.Node) (*node.Node, error) {
|
||||||
if size := len(nodes); size > 0 {
|
if size := len(nodes); size > 0 {
|
||||||
return nodes[rand.Intn(size)], nil
|
return nodes[p.r.Intn(size)], 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