Merge pull request #42949 from wenlxie/master

Automatic merge from submit-queue

recycle pod can't get the event since channel closed

What this PR does / why we need it:
We create a   hostPath type  PV with "Recycle" persistentVolumeReclaimPolicy,  and bind a PVC to it, but after deleted the PVC, the PV cannot become to available status. This is happened after we upgrade etcd to 3.0. The reason is:
If the channel used to get the pod message and events been abnormal closed(for example, the event channel maybe closed because of "required revision has been compacted" error), the function internalRecycleVolumeByWatchingPodUntilCompletion will stuck in a loop, and the recycle pod will not been deleted, the PV can not become into available status

Special notes for your reviewer:
None
Release note:
This commit is contained in:
Kubernetes Submit Queue 2017-03-16 02:41:11 -07:00 committed by GitHub
commit 754effe332

View File

@ -96,7 +96,10 @@ func internalRecycleVolumeByWatchingPodUntilCompletion(pvName string, pod *v1.Po
// Now only the old pod or the new pod run. Watch it until it finishes
// and send all events on the pod to the PV
for {
event := <-podCh
event, ok := <-podCh
if !ok {
return fmt.Errorf("recycler pod %q watch channel had been closed", pod.Name)
}
switch event.Object.(type) {
case *v1.Pod:
// POD changed
@ -198,13 +201,14 @@ func (c *realRecyclerClient) WatchPod(name, namespace string, stopChannel chan s
return nil, err
}
eventCh := make(chan watch.Event, 0)
eventCh := make(chan watch.Event, 30)
go func() {
defer eventWatch.Stop()
defer podWatch.Stop()
defer close(eventCh)
var podWatchChannelClosed bool
var eventWatchChannelClosed bool
for {
select {
case _ = <-stopChannel:
@ -212,15 +216,19 @@ func (c *realRecyclerClient) WatchPod(name, namespace string, stopChannel chan s
case podEvent, ok := <-podWatch.ResultChan():
if !ok {
return
podWatchChannelClosed = true
} else {
eventCh <- podEvent
}
eventCh <- podEvent
case eventEvent, ok := <-eventWatch.ResultChan():
if !ok {
return
eventWatchChannelClosed = true
} else {
eventCh <- eventEvent
}
eventCh <- eventEvent
}
if podWatchChannelClosed && eventWatchChannelClosed {
break
}
}
}()