Skip to content

Commit c382943

Browse files
author
k8s-merge-robot
committed
Merge pull request kubernetes#20726 from ingvagabund/jitter-sync-loops-in-kubelet
Auto commit by PR queue bot
2 parents 2fbd44c + 392fc66 commit c382943

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pkg/kubelet/pod_workers.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/kubernetes/pkg/kubelet/util/queue"
2929
"k8s.io/kubernetes/pkg/types"
3030
"k8s.io/kubernetes/pkg/util/runtime"
31+
"k8s.io/kubernetes/pkg/util/wait"
3132
)
3233

3334
// PodWorkers is an abstract interface for testability.
@@ -39,6 +40,14 @@ type PodWorkers interface {
3940

4041
type syncPodFnType func(*api.Pod, *api.Pod, *kubecontainer.PodStatus, kubetypes.SyncPodType) error
4142

43+
const (
44+
// jitter factor for resyncInterval
45+
workerResyncIntervalJitterFactor = 0.5
46+
47+
// jitter factor for backOffPeriod
48+
workerBackOffPeriodJitterFactor = 0.5
49+
)
50+
4251
type podWorkers struct {
4352
// Protects all per worker fields.
4453
podLock sync.Mutex
@@ -209,10 +218,10 @@ func (p *podWorkers) wrapUp(uid types.UID, syncErr error) {
209218
switch {
210219
case syncErr == nil:
211220
// No error; requeue at the regular resync interval.
212-
p.workQueue.Enqueue(uid, p.resyncInterval)
221+
p.workQueue.Enqueue(uid, wait.Jitter(p.resyncInterval, workerResyncIntervalJitterFactor))
213222
default:
214223
// Error occurred during the sync; back off and then retry.
215-
p.workQueue.Enqueue(uid, p.backOffPeriod)
224+
p.workQueue.Enqueue(uid, wait.Jitter(p.backOffPeriod, workerBackOffPeriodJitterFactor))
216225
}
217226
p.checkForUpdates(uid)
218227
}

pkg/kubelet/prober/worker.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package prober
1818

1919
import (
20+
"math/rand"
2021
"time"
2122

2223
"github.com/golang/glog"
@@ -93,7 +94,8 @@ func newWorker(
9394

9495
// run periodically probes the container.
9596
func (w *worker) run() {
96-
probeTicker := time.NewTicker(time.Duration(w.spec.PeriodSeconds) * time.Second)
97+
probeTickerPeriod := time.Duration(w.spec.PeriodSeconds) * time.Second
98+
probeTicker := time.NewTicker(probeTickerPeriod)
9799

98100
defer func() {
99101
// Clean up.
@@ -105,6 +107,10 @@ func (w *worker) run() {
105107
w.probeManager.removeWorker(w.pod.UID, w.container.Name, w.probeType)
106108
}()
107109

110+
// If kubelet restarted the probes could be started in rapid succession.
111+
// Let the worker wait for a random portion of tickerPeriod before probing.
112+
time.Sleep(time.Duration(rand.Float64() * float64(probeTickerPeriod)))
113+
108114
probeLoop:
109115
for w.doProbe() {
110116
// Wait for next probe tick.

0 commit comments

Comments
 (0)