Skip to content

Commit 48620b9

Browse files
committed
Seed math/rand on start
1 parent ec0d94c commit 48620b9

File tree

7 files changed

+19
-1
lines changed

7 files changed

+19
-1
lines changed

cmd/dockerregistry/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"math/rand"
67
"net/http"
78
_ "net/http/pprof"
89
"os"
910
"runtime"
11+
"time"
1012

1113
log "github.com/Sirupsen/logrus"
1214
"k8s.io/kubernetes/pkg/util/logs"
@@ -28,6 +30,7 @@ func main() {
2830
defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop()
2931
startProfiler()
3032

33+
rand.Seed(time.Now().UTC().UnixNano())
3134
runtime.GOMAXPROCS(runtime.NumCPU())
3235
flag.Parse()
3336

cmd/gitserver/gitserver.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package main
22

33
import (
4+
"math/rand"
45
"os"
56
"path/filepath"
67
"runtime"
8+
"time"
79

810
"k8s.io/kubernetes/pkg/util/logs"
911

@@ -22,6 +24,7 @@ func main() {
2224
defer serviceability.BehaviorOnPanic(os.Getenv("OPENSHIFT_ON_PANIC"))()
2325
defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop()
2426

27+
rand.Seed(time.Now().UTC().UnixNano())
2528
if len(os.Getenv("GOMAXPROCS")) == 0 {
2629
runtime.GOMAXPROCS(runtime.NumCPU())
2730
}

cmd/oc/oc.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package main
22

33
import (
4+
"math/rand"
45
"os"
56
"path/filepath"
67
"runtime"
8+
"time"
79

810
"k8s.io/kubernetes/pkg/util/logs"
911

@@ -24,6 +26,7 @@ func main() {
2426
defer serviceability.BehaviorOnPanic(os.Getenv("OPENSHIFT_ON_PANIC"))()
2527
defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop()
2628

29+
rand.Seed(time.Now().UTC().UnixNano())
2730
if len(os.Getenv("GOMAXPROCS")) == 0 {
2831
runtime.GOMAXPROCS(runtime.NumCPU())
2932
}

cmd/openshift/openshift.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package main
22

33
import (
4+
"math/rand"
45
"os"
56
"path/filepath"
67
"runtime"
8+
"time"
79

810
"k8s.io/kubernetes/pkg/util/logs"
911

@@ -24,6 +26,7 @@ func main() {
2426
defer serviceability.BehaviorOnPanic(os.Getenv("OPENSHIFT_ON_PANIC"))()
2527
defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop()
2628

29+
rand.Seed(time.Now().UTC().UnixNano())
2730
if len(os.Getenv("GOMAXPROCS")) == 0 {
2831
runtime.GOMAXPROCS(runtime.NumCPU())
2932
}

pkg/cmd/admin/router/router.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path"
99
"strconv"
1010
"strings"
11+
"time"
1112

1213
"github.com/golang/glog"
1314
"github.com/spf13/cobra"
@@ -846,6 +847,7 @@ func generateRoleBindingName(name string) string {
846847

847848
// generateStatsPassword creates a random password.
848849
func generateStatsPassword() string {
850+
rand := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
849851
allowableChars := []rune("abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
850852
allowableCharLength := len(allowableChars)
851853
password := []string{}

pkg/cmd/server/crypto/crypto.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ type RandomSerialGenerator struct {
256256
}
257257

258258
func (s *RandomSerialGenerator) Next(template *x509.Certificate) (int64, error) {
259-
return mathrand.Int63(), nil
259+
r := mathrand.New(mathrand.NewSource(time.Now().UTC().UnixNano()))
260+
return r.Int63(), nil
260261
}
261262

262263
// EnsureCA returns a CA, whether it was created (as opposed to pre-existing), and any error

pkg/sdn/plugin/sdn-cni-plugin/openshift-sdn.go

+3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
"encoding/json"
88
"fmt"
99
"io/ioutil"
10+
"math/rand"
1011
"net"
1112
"net/http"
1213
"os"
1314
"strings"
15+
"time"
1416

1517
"github.com/openshift/origin/pkg/sdn/plugin/cniserver"
1618

@@ -111,6 +113,7 @@ func (p *cniPlugin) CmdDel(args *skel.CmdArgs) error {
111113
}
112114

113115
func main() {
116+
rand.Seed(time.Now().UTC().UnixNano())
114117
p := NewCNIPlugin(cniserver.CNIServerSocketPath)
115118
skel.PluginMain(p.skelCmdAdd, p.CmdDel, version.Legacy)
116119
}

0 commit comments

Comments
 (0)