Skip to content

Commit 6402a76

Browse files
committed
Suppress suprious exceptions
1 parent f8020c9 commit 6402a76

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

operator/src/main/java/oracle/kubernetes/operator/Main.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import oracle.kubernetes.operator.helpers.CRDHelper;
3535
import oracle.kubernetes.operator.helpers.CallBuilder;
3636
import oracle.kubernetes.operator.helpers.CallBuilderFactory;
37+
import oracle.kubernetes.operator.helpers.ClientPool;
3738
import oracle.kubernetes.operator.helpers.ConfigMapHelper;
3839
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
3940
import oracle.kubernetes.operator.helpers.HealthCheckHelper;
@@ -89,6 +90,8 @@ public Thread newThread(Runnable r) {
8990

9091
static {
9192
try {
93+
ClientPool.initialize(threadFactory);
94+
9295
TuningParameters.initializeInstance(wrappedExecutorService, "/operator/config");
9396
tuningAndConfig = TuningParameters.getInstance();
9497
} catch (IOException e) {

operator/src/main/java/oracle/kubernetes/operator/helpers/ClientPool.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
package oracle.kubernetes.operator.helpers;
66

7+
import com.squareup.okhttp.Dispatcher;
78
import io.kubernetes.client.ApiClient;
89
import io.kubernetes.client.Configuration;
910
import io.kubernetes.client.util.Config;
1011
import java.io.IOException;
12+
import java.util.concurrent.ExecutorService;
13+
import java.util.concurrent.SynchronousQueue;
14+
import java.util.concurrent.ThreadFactory;
15+
import java.util.concurrent.ThreadPoolExecutor;
16+
import java.util.concurrent.TimeUnit;
1117
import java.util.concurrent.atomic.AtomicBoolean;
1218
import oracle.kubernetes.operator.logging.LoggingFacade;
1319
import oracle.kubernetes.operator.logging.LoggingFactory;
@@ -18,9 +24,25 @@
1824
public class ClientPool extends Pool<ApiClient> {
1925
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
2026
private static ClientPool SINGLETON = new ClientPool();
27+
private static ThreadFactory threadFactory;
2128

2229
private static final ClientFactory FACTORY = new DefaultClientFactory();
2330

31+
public static void initialize(ThreadFactory threadFactory) {
32+
ClientPool.threadFactory =
33+
(r) -> {
34+
return threadFactory.newThread(
35+
() -> {
36+
try {
37+
r.run();
38+
} catch (Throwable t) {
39+
// These will almost always be spurious exceptions
40+
LOGGER.fine(MessageKeys.EXCEPTION, t);
41+
}
42+
});
43+
};
44+
}
45+
2446
public static ClientPool getInstance() {
2547
return SINGLETON;
2648
}
@@ -71,6 +93,19 @@ public ApiClient get() {
7193
if (first.getAndSet(false)) {
7294
Configuration.setDefaultApiClient(client);
7395
}
96+
97+
if (threadFactory != null) {
98+
ExecutorService exec =
99+
new ThreadPoolExecutor(
100+
0,
101+
Integer.MAX_VALUE,
102+
60,
103+
TimeUnit.SECONDS,
104+
new SynchronousQueue<Runnable>(),
105+
threadFactory);
106+
client.getHttpClient().setDispatcher(new Dispatcher(exec));
107+
}
108+
74109
return client;
75110
} catch (IOException e) {
76111
throw new RuntimeException(e);

0 commit comments

Comments
 (0)