@@ -72,6 +72,7 @@ impl Log {
72
72
previous : true ,
73
73
..Default :: default ( )
74
74
} ,
75
+ true ,
75
76
) ) ;
76
77
77
78
Self {
@@ -191,15 +192,16 @@ fn log_stream<'a>(
191
192
pod : Arc < Pod > ,
192
193
tx : UnboundedSender < String > ,
193
194
params : LogParams ,
195
+ retry : bool ,
194
196
) -> BoxFuture < ' a , Result < ( ) > > {
195
197
async move {
196
- let client = Api :: < Pod > :: namespaced ( client. clone ( ) , & pod. namespace ( ) . unwrap ( ) ) ;
198
+ let pod_client = Api :: < Pod > :: namespaced ( client. clone ( ) , & pod. namespace ( ) . unwrap ( ) ) ;
197
199
198
200
let containers = try_join_all ( pod. containers ( None ) . iter ( ) . map ( |c| {
199
201
let mut params = params. clone ( ) ;
200
202
params. container = Some ( c. name_any ( ) ) ;
201
203
202
- container_stream ( & client , c, params)
204
+ container_stream ( & pod_client , c, params)
203
205
} ) )
204
206
. await ?;
205
207
@@ -211,6 +213,21 @@ fn log_stream<'a>(
211
213
212
214
tracing:: debug!( pod = pod. name_any( ) , "stream ended" ) ;
213
215
216
+ // The api server is a little finicky about streaming previous logs. It is
217
+ // possible that the request succeeds, but also that the stream finishes
218
+ // immediately. If this happens, retry without the previous flag. Because we're
219
+ // not clearing out the buffer on the widget side of things, the logs will be
220
+ // duplicated. Before the restart, we send a simple message to tell the user
221
+ // what happened.
222
+ if retry {
223
+ tx. send ( "Stream terminated, retrying without previous logs" . to_string ( ) ) ?;
224
+
225
+ let mut new_params = params. clone ( ) ;
226
+ new_params. previous = false ;
227
+
228
+ return log_stream ( client, pod, tx, new_params, false ) . await ;
229
+ }
230
+
214
231
Ok ( ( ) )
215
232
}
216
233
. boxed ( )
0 commit comments