Skip to content

Commit e6e69e3

Browse files
author
k8s-merge-robot
committed
Merge pull request kubernetes#13363 from mesosphere/abort-kubelet-syncloop
Auto commit by PR queue bot
2 parents 2443052 + de064f4 commit e6e69e3

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

pkg/kubelet/kubelet.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,17 +1896,19 @@ func (kl *Kubelet) syncLoop(updates <-chan PodUpdate, handler SyncHandler) {
18961896
}
18971897
housekeepingTimestamp = time.Now()
18981898
}
1899-
kl.syncLoopIteration(updates, handler)
1899+
if !kl.syncLoopIteration(updates, handler) {
1900+
break
1901+
}
19001902
}
19011903
}
19021904

1903-
func (kl *Kubelet) syncLoopIteration(updates <-chan PodUpdate, handler SyncHandler) {
1905+
func (kl *Kubelet) syncLoopIteration(updates <-chan PodUpdate, handler SyncHandler) bool {
19041906
kl.syncLoopMonitor.Store(time.Now())
19051907
select {
1906-
case u, ok := <-updates:
1907-
if !ok {
1908+
case u, open := <-updates:
1909+
if !open {
19081910
glog.Errorf("Update channel is closed. Exiting the sync loop.")
1909-
return
1911+
return false
19101912
}
19111913
switch u.Op {
19121914
case ADD:
@@ -1928,6 +1930,7 @@ func (kl *Kubelet) syncLoopIteration(updates <-chan PodUpdate, handler SyncHandl
19281930
handler.HandlePodSyncs(kl.podManager.GetPods())
19291931
}
19301932
kl.syncLoopMonitor.Store(time.Now())
1933+
return true
19311934
}
19321935

19331936
func (kl *Kubelet) dispatchWork(pod *api.Pod, syncType SyncPodType, mirrorPod *api.Pod, start time.Time) {

pkg/kubelet/kubelet_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,26 @@ func TestSyncLoopTimeUpdate(t *testing.T) {
329329
}
330330
}
331331

332+
func TestSyncLoopAbort(t *testing.T) {
333+
testKubelet := newTestKubelet(t)
334+
testKubelet.fakeCadvisor.On("MachineInfo").Return(&cadvisorApi.MachineInfo{}, nil)
335+
kubelet := testKubelet.kubelet
336+
kubelet.lastTimestampRuntimeUp = time.Now()
337+
kubelet.networkConfigured = true
338+
339+
ch := make(chan PodUpdate)
340+
close(ch)
341+
342+
// sanity check (also prevent this test from hanging in the next step)
343+
ok := kubelet.syncLoopIteration(ch, kubelet)
344+
if ok {
345+
t.Fatalf("expected syncLoopIteration to return !ok since update chan was closed")
346+
}
347+
348+
// this should terminate immediately; if it hangs then the syncLoopIteration isn't aborting properly
349+
kubelet.syncLoop(ch, kubelet)
350+
}
351+
332352
func TestSyncPodsStartPod(t *testing.T) {
333353
testKubelet := newTestKubelet(t)
334354
testKubelet.fakeCadvisor.On("MachineInfo").Return(&cadvisorApi.MachineInfo{}, nil)

0 commit comments

Comments
 (0)