File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Linq ;
3
+ using System . Threading ;
3
4
using k8s ;
4
5
using k8s . Informers ;
5
6
using k8s . Informers . Cache ;
@@ -28,9 +29,13 @@ public static IServiceCollection AddKubernetes(this IServiceCollection services)
28
29
services . AddSingleton < RetryDelegatingHandler > ( ) ;
29
30
services . AddHttpClient ( "DefaultName" )
30
31
. AddTypedClient < IKubernetes > ( ( httpClient , serviceProvider ) =>
31
- new Kubernetes (
32
+ {
33
+ httpClient . Timeout = Timeout . InfiniteTimeSpan ;
34
+ return new Kubernetes (
32
35
serviceProvider . GetRequiredService < KubernetesClientConfiguration > ( ) ,
33
- httpClient ) )
36
+ httpClient ) ;
37
+ } )
38
+ . AddHttpMessageHandler ( ( ) => new TimeoutHandler ( TimeSpan . FromSeconds ( 5 ) ) )
34
39
. AddHttpMessageHandler ( ( ) => new RetryDelegatingHandler ( )
35
40
{
36
41
RetryPolicy = new RetryPolicy < HttpStatusCodeErrorDetectionStrategy > ( new ExponentialBackoffRetryStrategy ( ) )
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Linq ;
3
+ using System . Net . Http ;
4
+ using System . Threading ;
5
+ using System . Threading . Tasks ;
6
+ using Microsoft . AspNetCore . WebUtilities ;
7
+
8
+ namespace informers
9
+ {
10
+ internal class TimeoutHandler : DelegatingHandler
11
+ {
12
+ private readonly TimeSpan _timeout ;
13
+
14
+ public TimeoutHandler ( TimeSpan timeout )
15
+ {
16
+ _timeout = timeout ;
17
+ }
18
+
19
+ protected override async Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken cancellationToken )
20
+ {
21
+ var query = QueryHelpers . ParseQuery ( request . RequestUri . Query ) ;
22
+
23
+ if ( ! ( query . TryGetValue ( "watch" , out var values ) && values . Any ( v => v == "true" ) ) )
24
+ {
25
+ var cts = new CancellationTokenSource ( _timeout ) ;
26
+ cancellationToken = CancellationTokenSource . CreateLinkedTokenSource ( cancellationToken , cts . Token ) . Token ;
27
+ }
28
+ var originResponse = await base . SendAsync ( request , cancellationToken ) . ConfigureAwait ( false ) ;
29
+
30
+ return originResponse ;
31
+ }
32
+
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments