Merge pull request #52155 from kevin-wangzefeng/fix-prober-phase-shift

Automatic merge from submit-queue (batch tested with PRs 50949, 52155, 52175, 52112, 52188)

Fix prober ticking shift for kubelet restart cases

Fixes #52154 
call sleep() before `probeTicker` starts ticking, to reduce the number of probers executed at the same time, after kubelete restarted.


**Special notes for your reviewer**:
Before:
![image](https://user-images.githubusercontent.com/6914660/30204947-d900c9ca-94b9-11e7-959d-049c5da1a80b.png)
After:
![image](https://user-images.githubusercontent.com/6914660/30204997-11db2b3c-94ba-11e7-970a-a542f46fc09d.png)


**Release note**:

```release-note
NONE
```

/cc @kubernetes/sig-node-bugs
This commit is contained in:
Kubernetes Submit Queue 2017-09-08 15:11:25 -07:00 committed by GitHub
commit e5dc995cc5

View File

@ -99,6 +99,11 @@ func newWorker(
// run periodically probes the container. // run periodically probes the container.
func (w *worker) run() { func (w *worker) run() {
probeTickerPeriod := time.Duration(w.spec.PeriodSeconds) * time.Second probeTickerPeriod := time.Duration(w.spec.PeriodSeconds) * time.Second
// If kubelet restarted the probes could be started in rapid succession.
// Let the worker wait for a random portion of tickerPeriod before probing.
time.Sleep(time.Duration(rand.Float64() * float64(probeTickerPeriod)))
probeTicker := time.NewTicker(probeTickerPeriod) probeTicker := time.NewTicker(probeTickerPeriod)
defer func() { defer func() {
@ -111,10 +116,6 @@ func (w *worker) run() {
w.probeManager.removeWorker(w.pod.UID, w.container.Name, w.probeType) w.probeManager.removeWorker(w.pod.UID, w.container.Name, w.probeType)
}() }()
// If kubelet restarted the probes could be started in rapid succession.
// Let the worker wait for a random portion of tickerPeriod before probing.
time.Sleep(time.Duration(rand.Float64() * float64(probeTickerPeriod)))
probeLoop: probeLoop:
for w.doProbe() { for w.doProbe() {
// Wait for next probe tick. // Wait for next probe tick.