Use range in loops; misc fixes
This commit is contained in:
parent
4685df26dd
commit
c23a8a85cc
@ -32,11 +32,7 @@ func HandleResizing(resize <-chan remotecommand.TerminalSize, resizeFunc func(si
|
||||
go func() {
|
||||
defer runtime.HandleCrash()
|
||||
|
||||
for {
|
||||
size, ok := <-resize
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
for size := range resize {
|
||||
if size.Height < 1 || size.Width < 1 {
|
||||
continue
|
||||
}
|
||||
|
@ -1099,13 +1099,7 @@ func (kl *Kubelet) podKiller() {
|
||||
killing := sets.NewString()
|
||||
// guard for the killing set
|
||||
lock := sync.Mutex{}
|
||||
for {
|
||||
select {
|
||||
case podPair, ok := <-kl.podKillingCh:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
for podPair := range kl.podKillingCh {
|
||||
runningPod := podPair.RunningPod
|
||||
apiPod := podPair.APIPod
|
||||
|
||||
@ -1130,7 +1124,6 @@ func (kl *Kubelet) podKiller() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// validateContainerLogStatus returns the container ID for the desired container to retrieve logs for, based on the state
|
||||
// of the container. The previous flag will only return the logs for the last terminated container, otherwise, the current
|
||||
|
@ -45,11 +45,9 @@ func newPodContainerDeletor(runtime kubecontainer.Runtime, containersToKeep int)
|
||||
buffer := make(chan kubecontainer.ContainerID, containerDeletorBufferLimit)
|
||||
go wait.Until(func() {
|
||||
for {
|
||||
select {
|
||||
case id := <-buffer:
|
||||
id := <-buffer
|
||||
runtime.DeleteContainer(id)
|
||||
}
|
||||
}
|
||||
}, 0, wait.NeverStop)
|
||||
|
||||
return &podContainerDeletor{
|
||||
|
@ -226,7 +226,7 @@ func (c *realRecyclerClient) WatchPod(name, namespace string, stopChannel chan s
|
||||
var eventWatchChannelClosed bool
|
||||
for {
|
||||
select {
|
||||
case _ = <-stopChannel:
|
||||
case <-stopChannel:
|
||||
return
|
||||
|
||||
case podEvent, ok := <-podWatch.ResultChan():
|
||||
|
@ -62,11 +62,7 @@ func (fw *filteredWatch) Stop() {
|
||||
// loop waits for new values, filters them, and resends them.
|
||||
func (fw *filteredWatch) loop() {
|
||||
defer close(fw.result)
|
||||
for {
|
||||
event, ok := <-fw.incoming.ResultChan()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
for event := range fw.incoming.ResultChan() {
|
||||
filtered, keep := fw.f(event)
|
||||
if keep {
|
||||
fw.result <- filtered
|
||||
|
@ -204,11 +204,7 @@ func (m *Broadcaster) Shutdown() {
|
||||
func (m *Broadcaster) loop() {
|
||||
// Deliberately not catching crashes here. Yes, bring down the process if there's a
|
||||
// bug in watch.Broadcaster.
|
||||
for {
|
||||
event, ok := <-m.incoming
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
for event := range m.incoming {
|
||||
if event.Type == internalRunFunctionMarker {
|
||||
event.Object.(functionFakeRuntimeObject)()
|
||||
continue
|
||||
|
@ -445,6 +445,7 @@ func (e *Store) WaitForInitialized(ctx genericapirequest.Context, obj runtime.Ob
|
||||
}
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1070,11 +1071,7 @@ func (e *Store) DeleteCollection(ctx genericapirequest.Context, options *metav1.
|
||||
})
|
||||
defer wg.Done()
|
||||
|
||||
for {
|
||||
index, ok := <-toProcess
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
for index := range toProcess {
|
||||
accessor, err := meta.Accessor(items[index])
|
||||
if err != nil {
|
||||
errs <- err
|
||||
|
@ -225,11 +225,7 @@ func (eventBroadcaster *eventBroadcasterImpl) StartEventWatcher(eventHandler fun
|
||||
watcher := eventBroadcaster.Watch()
|
||||
go func() {
|
||||
defer utilruntime.HandleCrash()
|
||||
for {
|
||||
watchEvent, open := <-watcher.ResultChan()
|
||||
if !open {
|
||||
return
|
||||
}
|
||||
for watchEvent := range watcher.ResultChan() {
|
||||
event, ok := watchEvent.Object.(*v1.Event)
|
||||
if !ok {
|
||||
// This is all local, so there's no reason this should
|
||||
|
@ -192,6 +192,7 @@ func expectNoEvent(w watch.Interface, eventType watch.EventType, object runtime.
|
||||
|
||||
func waitForEvent(w watch.Interface, expectType watch.EventType, expectObject runtime.Object) (watch.Event, bool) {
|
||||
stopTimer := time.NewTimer(1 * time.Minute)
|
||||
defer stopTimer.Stop()
|
||||
for {
|
||||
select {
|
||||
case actual := <-w.ResultChan():
|
||||
|
Loading…
Reference in New Issue
Block a user