Skip to content

Commit 2707b58

Browse files
authored
Merge pull request #662 from adohe/adjust_read_timeout
manually set OKHttpClient read timeout zero ensure client doesnot tim…
2 parents 7e6fc7b + db342a6 commit 2707b58

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

util/src/main/java/io/kubernetes/client/informer/SharedInformerFactory.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.concurrent.ExecutorService;
1515
import java.util.concurrent.Executors;
1616
import java.util.concurrent.Future;
17+
import java.util.concurrent.TimeUnit;
1718

1819
/** SharedInformerFactory class constructs and caches informers for api types. */
1920
public class SharedInformerFactory {
@@ -24,9 +25,16 @@ public class SharedInformerFactory {
2425

2526
private ExecutorService informerExecutor;
2627

28+
private ApiClient apiClient;
29+
2730
/** Constructor w/ default thread pool. */
2831
public SharedInformerFactory() {
29-
this(Executors.newCachedThreadPool());
32+
this(Configuration.getDefaultApiClient(), Executors.newCachedThreadPool());
33+
}
34+
35+
/** Constructor w/ api client specified and default thread pool. */
36+
public SharedInformerFactory(ApiClient apiClient) {
37+
this(apiClient, Executors.newCachedThreadPool());
3038
}
3139

3240
/**
@@ -35,6 +43,17 @@ public SharedInformerFactory() {
3543
* @param threadPool specified thread pool
3644
*/
3745
public SharedInformerFactory(ExecutorService threadPool) {
46+
this(Configuration.getDefaultApiClient(), threadPool);
47+
}
48+
49+
/**
50+
* Constructor w/ api client and thread pool specified.
51+
*
52+
* @param client specific api client
53+
* @param threadPool specified thread pool
54+
*/
55+
public SharedInformerFactory(ApiClient client, ExecutorService threadPool) {
56+
apiClient = client;
3857
informerExecutor = threadPool;
3958
informers = new HashMap<>();
4059
startedInformers = new HashMap<>();
@@ -87,7 +106,8 @@ private <ApiType, ApiListType> ListerWatcher<ApiType, ApiListType> listerWatcher
87106
CallGenerator callGenerator,
88107
Class<ApiType> apiTypeClass,
89108
Class<ApiListType> apiListTypeClass) {
90-
ApiClient apiClient = Configuration.getDefaultApiClient();
109+
// set read timeout zero to ensure client doesn't time out
110+
apiClient.getHttpClient().setReadTimeout(0, TimeUnit.MILLISECONDS);
91111
return new ListerWatcher<ApiType, ApiListType>() {
92112
@Override
93113
public ApiListType list(CallGeneratorParams params) throws ApiException {

0 commit comments

Comments
 (0)