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() {
|
go func() {
|
||||||
defer runtime.HandleCrash()
|
defer runtime.HandleCrash()
|
||||||
|
|
||||||
for {
|
for size := range resize {
|
||||||
size, ok := <-resize
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if size.Height < 1 || size.Width < 1 {
|
if size.Height < 1 || size.Width < 1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1099,35 +1099,28 @@ func (kl *Kubelet) podKiller() {
|
|||||||
killing := sets.NewString()
|
killing := sets.NewString()
|
||||||
// guard for the killing set
|
// guard for the killing set
|
||||||
lock := sync.Mutex{}
|
lock := sync.Mutex{}
|
||||||
for {
|
for podPair := range kl.podKillingCh {
|
||||||
select {
|
runningPod := podPair.RunningPod
|
||||||
case podPair, ok := <-kl.podKillingCh:
|
apiPod := podPair.APIPod
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
runningPod := podPair.RunningPod
|
lock.Lock()
|
||||||
apiPod := podPair.APIPod
|
exists := killing.Has(string(runningPod.ID))
|
||||||
|
if !exists {
|
||||||
|
killing.Insert(string(runningPod.ID))
|
||||||
|
}
|
||||||
|
lock.Unlock()
|
||||||
|
|
||||||
lock.Lock()
|
if !exists {
|
||||||
exists := killing.Has(string(runningPod.ID))
|
go func(apiPod *v1.Pod, runningPod *kubecontainer.Pod) {
|
||||||
if !exists {
|
glog.V(2).Infof("Killing unwanted pod %q", runningPod.Name)
|
||||||
killing.Insert(string(runningPod.ID))
|
err := kl.killPod(apiPod, runningPod, nil, nil)
|
||||||
}
|
if err != nil {
|
||||||
lock.Unlock()
|
glog.Errorf("Failed killing the pod %q: %v", runningPod.Name, err)
|
||||||
|
}
|
||||||
if !exists {
|
lock.Lock()
|
||||||
go func(apiPod *v1.Pod, runningPod *kubecontainer.Pod) {
|
killing.Delete(string(runningPod.ID))
|
||||||
glog.V(2).Infof("Killing unwanted pod %q", runningPod.Name)
|
lock.Unlock()
|
||||||
err := kl.killPod(apiPod, runningPod, nil, nil)
|
}(apiPod, runningPod)
|
||||||
if err != nil {
|
|
||||||
glog.Errorf("Failed killing the pod %q: %v", runningPod.Name, err)
|
|
||||||
}
|
|
||||||
lock.Lock()
|
|
||||||
killing.Delete(string(runningPod.ID))
|
|
||||||
lock.Unlock()
|
|
||||||
}(apiPod, runningPod)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,10 +45,8 @@ func newPodContainerDeletor(runtime kubecontainer.Runtime, containersToKeep int)
|
|||||||
buffer := make(chan kubecontainer.ContainerID, containerDeletorBufferLimit)
|
buffer := make(chan kubecontainer.ContainerID, containerDeletorBufferLimit)
|
||||||
go wait.Until(func() {
|
go wait.Until(func() {
|
||||||
for {
|
for {
|
||||||
select {
|
id := <-buffer
|
||||||
case id := <-buffer:
|
runtime.DeleteContainer(id)
|
||||||
runtime.DeleteContainer(id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 0, wait.NeverStop)
|
}, 0, wait.NeverStop)
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ func (c *realRecyclerClient) WatchPod(name, namespace string, stopChannel chan s
|
|||||||
var eventWatchChannelClosed bool
|
var eventWatchChannelClosed bool
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case _ = <-stopChannel:
|
case <-stopChannel:
|
||||||
return
|
return
|
||||||
|
|
||||||
case podEvent, ok := <-podWatch.ResultChan():
|
case podEvent, ok := <-podWatch.ResultChan():
|
||||||
|
@ -62,11 +62,7 @@ func (fw *filteredWatch) Stop() {
|
|||||||
// loop waits for new values, filters them, and resends them.
|
// loop waits for new values, filters them, and resends them.
|
||||||
func (fw *filteredWatch) loop() {
|
func (fw *filteredWatch) loop() {
|
||||||
defer close(fw.result)
|
defer close(fw.result)
|
||||||
for {
|
for event := range fw.incoming.ResultChan() {
|
||||||
event, ok := <-fw.incoming.ResultChan()
|
|
||||||
if !ok {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
filtered, keep := fw.f(event)
|
filtered, keep := fw.f(event)
|
||||||
if keep {
|
if keep {
|
||||||
fw.result <- filtered
|
fw.result <- filtered
|
||||||
|
@ -204,11 +204,7 @@ func (m *Broadcaster) Shutdown() {
|
|||||||
func (m *Broadcaster) loop() {
|
func (m *Broadcaster) loop() {
|
||||||
// Deliberately not catching crashes here. Yes, bring down the process if there's a
|
// Deliberately not catching crashes here. Yes, bring down the process if there's a
|
||||||
// bug in watch.Broadcaster.
|
// bug in watch.Broadcaster.
|
||||||
for {
|
for event := range m.incoming {
|
||||||
event, ok := <-m.incoming
|
|
||||||
if !ok {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if event.Type == internalRunFunctionMarker {
|
if event.Type == internalRunFunctionMarker {
|
||||||
event.Object.(functionFakeRuntimeObject)()
|
event.Object.(functionFakeRuntimeObject)()
|
||||||
continue
|
continue
|
||||||
|
@ -445,6 +445,7 @@ func (e *Store) WaitForInitialized(ctx genericapirequest.Context, obj runtime.Ob
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
return nil, ctx.Err()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1070,11 +1071,7 @@ func (e *Store) DeleteCollection(ctx genericapirequest.Context, options *metav1.
|
|||||||
})
|
})
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
for {
|
for index := range toProcess {
|
||||||
index, ok := <-toProcess
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
accessor, err := meta.Accessor(items[index])
|
accessor, err := meta.Accessor(items[index])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs <- err
|
errs <- err
|
||||||
|
@ -225,11 +225,7 @@ func (eventBroadcaster *eventBroadcasterImpl) StartEventWatcher(eventHandler fun
|
|||||||
watcher := eventBroadcaster.Watch()
|
watcher := eventBroadcaster.Watch()
|
||||||
go func() {
|
go func() {
|
||||||
defer utilruntime.HandleCrash()
|
defer utilruntime.HandleCrash()
|
||||||
for {
|
for watchEvent := range watcher.ResultChan() {
|
||||||
watchEvent, open := <-watcher.ResultChan()
|
|
||||||
if !open {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
event, ok := watchEvent.Object.(*v1.Event)
|
event, ok := watchEvent.Object.(*v1.Event)
|
||||||
if !ok {
|
if !ok {
|
||||||
// This is all local, so there's no reason this should
|
// 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) {
|
func waitForEvent(w watch.Interface, expectType watch.EventType, expectObject runtime.Object) (watch.Event, bool) {
|
||||||
stopTimer := time.NewTimer(1 * time.Minute)
|
stopTimer := time.NewTimer(1 * time.Minute)
|
||||||
|
defer stopTimer.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case actual := <-w.ResultChan():
|
case actual := <-w.ResultChan():
|
||||||
|
Loading…
Reference in New Issue
Block a user