Merge pull request #16340 from timstclair/flaky-prober

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2015-10-27 12:10:22 -07:00
commit 0a7a9f3535
2 changed files with 10 additions and 4 deletions

View File

@ -473,6 +473,7 @@ type Kubelet struct {
rootDirectory string
podWorkers PodWorkers
resyncInterval time.Duration
resyncTicker *time.Ticker
sourcesReady SourcesReadyFn
// sourcesSeen records the sources seen by kubelet. This set is not thread
// safe and should only be access by the main kubelet syncloop goroutine.
@ -2008,6 +2009,7 @@ func (kl *Kubelet) canAdmitPod(pods []*api.Pod, pod *api.Pod) (bool, string, str
// state every sync-frequency seconds. Never returns.
func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHandler) {
glog.Info("Starting kubelet main sync loop.")
kl.resyncTicker = time.NewTicker(kl.resyncInterval)
var housekeepingTimestamp time.Time
for {
if !kl.containerRuntimeUp() {
@ -2071,7 +2073,7 @@ func (kl *Kubelet) syncLoopIteration(updates <-chan kubetypes.PodUpdate, handler
// TODO: Do we want to support this?
glog.Errorf("Kubelet does not support snapshot update")
}
case <-time.After(kl.resyncInterval):
case <-kl.resyncTicker.C:
// Periodically syncs all the pods and performs cleanup tasks.
glog.V(4).Infof("SyncLoop (periodic sync)")
handler.HandlePodSyncs(kl.podManager.GetPods())

View File

@ -144,6 +144,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
kubelet.backOff = util.NewBackOff(time.Second, time.Minute)
kubelet.backOff.Clock = fakeClock
kubelet.podKillingCh = make(chan *kubecontainer.Pod, 20)
kubelet.resyncInterval = 10 * time.Second
return &TestKubelet{kubelet, fakeRuntime, mockCadvisor, fakeKubeClient, fakeMirrorClient}
}
@ -331,6 +332,9 @@ func TestSyncLoopTimeUpdate(t *testing.T) {
t.Errorf("Unexpected sync loop time: %s, expected 0", loopTime1)
}
// Start sync ticker.
kubelet.resyncTicker = time.NewTicker(time.Millisecond)
kubelet.syncLoopIteration(make(chan kubetypes.PodUpdate), kubelet)
loopTime2 := kubelet.LatestLoopEntryTime()
if loopTime2.IsZero() {
@ -349,9 +353,9 @@ func TestSyncLoopAbort(t *testing.T) {
kubelet := testKubelet.kubelet
kubelet.lastTimestampRuntimeUp = time.Now()
kubelet.networkConfigured = true
// The syncLoop waits on time.After(resyncInterval), set it really big so that we don't race for
// the channel close
kubelet.resyncInterval = time.Second * 30
// The syncLoop waits on the resyncTicker, so we stop it immediately to avoid a race.
kubelet.resyncTicker = time.NewTicker(time.Second)
kubelet.resyncTicker.Stop()
ch := make(chan kubetypes.PodUpdate)
close(ch)