Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recycle pod can't get the event since channel closed #42949

Merged
merged 1 commit into from
Mar 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 16 additions & 8 deletions pkg/volume/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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
Expand Down Expand Up @@ -199,29 +202,34 @@ 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:
return

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
}
}
}()
Expand Down