@@ -95,23 +95,13 @@ func (s *PodStreamer) streamLogs(ctx context.Context) (bool, error) {
9595 return false , nil
9696 }
9797
98- exit := make (chan struct {})
99- go func (ctx context.Context , currPod * corev1.Pod ) {
100- defer utilruntime .HandleCrash ()
101- defer close (exit )
102- s .streamLogsReader (ctx , currPod )
103- }(ctx , currPod )
104-
105- select {
106- case <- exit :
107- return false , nil
108- case <- ctx .Done ():
109- // wait just a moment so that the streamLogsReader doesn't write to a closed channel
110- time .Sleep (100 * time .Millisecond )
111- return false , nil
112- }
98+ s .streamLogsReader (ctx , currPod )
99+ return false , nil
113100}
114101
102+ // streamLogsReader will run and block until
103+ // 1. server closes the http connection
104+ // 2. context is closed.
115105func (s * PodStreamer ) streamLogsReader (ctx context.Context , currPod * corev1.Pod ) {
116106 caughtUpToLastLine := false
117107 if currPod .UID != s .lastUID {
@@ -131,7 +121,7 @@ func (s *PodStreamer) streamLogsReader(ctx context.Context, currPod *corev1.Pod)
131121 Container : s .containerName ,
132122 Follow : true ,
133123 Timestamps : true ,
134- }).Stream (context . Background () )
124+ }).Stream (ctx )
135125 if err != nil {
136126 s .errs <- LogError {
137127 Pod : currPod ,
@@ -140,6 +130,7 @@ func (s *PodStreamer) streamLogsReader(ctx context.Context, currPod *corev1.Pod)
140130 }
141131 return
142132 }
133+
143134 scan := bufio .NewScanner (reader )
144135 for scan .Scan () {
145136 // exit if we have been stopped.
0 commit comments