diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 0945c769b02..2dc2997ca95 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -1812,9 +1812,12 @@ func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHand time.Sleep(5 * time.Second) continue } + + kl.syncLoopMonitor.Store(kl.clock.Now()) if !kl.syncLoopIteration(updates, handler, syncTicker.C, housekeepingTicker.C, plegCh) { break } + kl.syncLoopMonitor.Store(kl.clock.Now()) } } @@ -1852,7 +1855,6 @@ func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHand // containers have failed liveness checks func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handler SyncHandler, syncCh <-chan time.Time, housekeepingCh <-chan time.Time, plegCh <-chan *pleg.PodLifecycleEvent) bool { - kl.syncLoopMonitor.Store(kl.clock.Now()) select { case u, open := <-configCh: // Update from a config source; dispatch it to the right handler @@ -1946,7 +1948,6 @@ func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handle } } } - kl.syncLoopMonitor.Store(kl.clock.Now()) return true } diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index 943243c1c49..59000904a34 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -326,32 +326,6 @@ func newTestPods(count int) []*v1.Pod { var emptyPodUIDs map[types.UID]kubetypes.SyncPodType -func TestSyncLoopTimeUpdate(t *testing.T) { - testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */) - defer testKubelet.Cleanup() - testKubelet.fakeCadvisor.On("MachineInfo").Return(&cadvisorapi.MachineInfo{}, nil) - kubelet := testKubelet.kubelet - - loopTime1 := kubelet.LatestLoopEntryTime() - require.True(t, loopTime1.IsZero(), "Expect sync loop time to be zero") - - // Start sync ticker. - syncCh := make(chan time.Time, 1) - housekeepingCh := make(chan time.Time, 1) - plegCh := make(chan *pleg.PodLifecycleEvent) - syncCh <- time.Now() - kubelet.syncLoopIteration(make(chan kubetypes.PodUpdate), kubelet, syncCh, housekeepingCh, plegCh) - loopTime2 := kubelet.LatestLoopEntryTime() - require.False(t, loopTime2.IsZero(), "Expect sync loop time to be non-zero") - - syncCh <- time.Now() - kubelet.syncLoopIteration(make(chan kubetypes.PodUpdate), kubelet, syncCh, housekeepingCh, plegCh) - loopTime3 := kubelet.LatestLoopEntryTime() - require.True(t, loopTime3.After(loopTime1), - "Sync Loop Time was not updated correctly. Second update timestamp %v should be greater than first update timestamp %v", - loopTime3, loopTime1) -} - func TestSyncLoopAbort(t *testing.T) { testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */) defer testKubelet.Cleanup()