mirror of https://github.com/k3s-io/k3s
Remove unnecessary random re-seeding
Package k8s.io/apimachinery/pkg/util/rand seeds the random based on time during the package initialization, so no need to re-seed it.pull/58/head
parent
3a243090a5
commit
f5e9c0473c
|
@ -18,7 +18,6 @@ package flocker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/rand"
|
"k8s.io/apimachinery/pkg/util/rand"
|
||||||
|
@ -68,7 +67,6 @@ func (util *FlockerUtil) CreateVolume(c *flockerVolumeProvisioner) (datasetUUID
|
||||||
}
|
}
|
||||||
|
|
||||||
// select random node
|
// select random node
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
node := nodes[rand.Intn(len(nodes))]
|
node := nodes[rand.Intn(len(nodes))]
|
||||||
glog.V(2).Infof("selected flocker node with UUID '%s' to provision dataset", node.UUID)
|
glog.V(2).Infof("selected flocker node with UUID '%s' to provision dataset", node.UUID)
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,13 @@ var rng = struct {
|
||||||
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Int returns a non-negative pseudo-random int.
|
||||||
|
func Int() int {
|
||||||
|
rng.Lock()
|
||||||
|
defer rng.Unlock()
|
||||||
|
return rng.rand.Int()
|
||||||
|
}
|
||||||
|
|
||||||
// Intn generates an integer in range [0,max).
|
// Intn generates an integer in range [0,max).
|
||||||
// By design this should panic if input is invalid, <= 0.
|
// By design this should panic if input is invalid, <= 0.
|
||||||
func Intn(max int) int {
|
func Intn(max int) int {
|
||||||
|
|
|
@ -46,6 +46,7 @@ go_library(
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||||
|
|
|
@ -19,7 +19,6 @@ package vsphere
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -37,6 +36,7 @@ import (
|
||||||
storage "k8s.io/api/storage/v1"
|
storage "k8s.io/api/storage/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/rand"
|
||||||
"k8s.io/apimachinery/pkg/util/uuid"
|
"k8s.io/apimachinery/pkg/util/uuid"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
|
@ -747,7 +747,6 @@ func GetReadySchedulableNodeInfos() []*NodeInfo {
|
||||||
// and it's associated NodeInfo object is returned.
|
// and it's associated NodeInfo object is returned.
|
||||||
func GetReadySchedulableRandomNodeInfo() *NodeInfo {
|
func GetReadySchedulableRandomNodeInfo() *NodeInfo {
|
||||||
nodesInfo := GetReadySchedulableNodeInfos()
|
nodesInfo := GetReadySchedulableNodeInfos()
|
||||||
rand.Seed(time.Now().Unix())
|
|
||||||
Expect(nodesInfo).NotTo(BeEmpty())
|
Expect(nodesInfo).NotTo(BeEmpty())
|
||||||
return nodesInfo[rand.Int()%len(nodesInfo)]
|
return nodesInfo[rand.Int()%len(nodesInfo)]
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,6 @@ func main() {
|
||||||
// Outputs linesTotal lines of logs to stdout uniformly for duration
|
// Outputs linesTotal lines of logs to stdout uniformly for duration
|
||||||
func generateLogs(linesTotal int, duration time.Duration) {
|
func generateLogs(linesTotal int, duration time.Duration) {
|
||||||
delay := duration / time.Duration(linesTotal)
|
delay := duration / time.Duration(linesTotal)
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
|
|
||||||
ticker := time.NewTicker(delay)
|
ticker := time.NewTicker(delay)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
Loading…
Reference in New Issue