Skip to content

Commit 78c7843

Browse files
committed
feat: make reconciliation thread number configurable
Fixes #399.
1 parent 112a826 commit 78c7843

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ public <R extends CustomResource> void register(
141141

142142
CustomResourceCache customResourceCache = new CustomResourceCache(objectMapper);
143143
DefaultEventHandler defaultEventHandler =
144-
new DefaultEventHandler(customResourceCache, dispatcher, controllerName, retry);
144+
new DefaultEventHandler(
145+
customResourceCache,
146+
dispatcher,
147+
controllerName,
148+
retry,
149+
configurationService.concurrentReconciliationThreads());
145150
DefaultEventSourceManager eventSourceManager =
146151
new DefaultEventSourceManager(defaultEventHandler, retry != null);
147152
defaultEventHandler.setEventSourceManager(eventSourceManager);

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,15 @@ default Config getClientConfiguration() {
5555
default boolean checkCRDAndValidateLocalModel() {
5656
return true;
5757
}
58+
59+
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 5;
60+
/**
61+
* Retrieves the maximum number of threads the operator can spin out to dispatch reconciliation
62+
* requests to controllers
63+
*
64+
* @return the maximum number of concurrent reconciliation threads
65+
*/
66+
default int concurrentReconciliationThreads() {
67+
return DEFAULT_RECONCILIATION_THREADS_NUMBER;
68+
}
5869
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import io.fabric8.kubernetes.client.CustomResource;
88
import io.javaoperatorsdk.operator.api.RetryInfo;
9+
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
910
import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager;
1011
import io.javaoperatorsdk.operator.processing.event.Event;
1112
import io.javaoperatorsdk.operator.processing.event.EventHandler;
@@ -44,14 +45,29 @@ public DefaultEventHandler(
4445
CustomResourceCache customResourceCache,
4546
EventDispatcher eventDispatcher,
4647
String relatedControllerName,
47-
Retry retry) {
48+
Retry retry,
49+
int concurrentReconciliationThreads) {
4850
this.customResourceCache = customResourceCache;
4951
this.eventDispatcher = eventDispatcher;
5052
this.retry = retry;
5153
eventBuffer = new EventBuffer();
5254
executor =
5355
new ScheduledThreadPoolExecutor(
54-
5, runnable -> new Thread(runnable, "EventHandler-" + relatedControllerName));
56+
concurrentReconciliationThreads,
57+
runnable -> new Thread(runnable, "EventHandler-" + relatedControllerName));
58+
}
59+
60+
public DefaultEventHandler(
61+
CustomResourceCache customResourceCache,
62+
EventDispatcher eventDispatcher,
63+
String relatedControllerName,
64+
Retry retry) {
65+
this(
66+
customResourceCache,
67+
eventDispatcher,
68+
relatedControllerName,
69+
retry,
70+
ConfigurationService.DEFAULT_RECONCILIATION_THREADS_NUMBER);
5571
}
5672

5773
public void setEventSourceManager(DefaultEventSourceManager eventSourceManager) {

operator-framework-spring-boot-starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,9 @@ public RetryConfiguration getRetryConfiguration() {
134134
.orElse(RetryConfiguration.DEFAULT);
135135
}
136136
}
137+
138+
@Override
139+
public int concurrentReconciliationThreads() {
140+
return configuration.getConcurrentReconciliationThreads();
141+
}
137142
}

operator-framework-spring-boot-starter/src/main/java/io/javaoperatorsdk/operator/springboot/starter/OperatorConfigurationProperties.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.javaoperatorsdk.operator.springboot.starter;
22

3+
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
34
import java.util.Collections;
45
import java.util.Map;
56
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -10,6 +11,7 @@ public class OperatorConfigurationProperties {
1011
private KubernetesClientProperties client = new KubernetesClientProperties();
1112
private Map<String, ControllerProperties> controllers = Collections.emptyMap();
1213
private boolean checkCrdAndValidateLocalModel = true;
14+
private int concurrentReconciliationThreads = ConfigurationService.DEFAULT_RECONCILIATION_THREADS_NUMBER;
1315

1416
public KubernetesClientProperties getClient() {
1517
return client;
@@ -34,4 +36,12 @@ public boolean getCheckCrdAndValidateLocalModel() {
3436
public void setCheckCrdAndValidateLocalModel(boolean checkCrdAndValidateLocalModel) {
3537
this.checkCrdAndValidateLocalModel = checkCrdAndValidateLocalModel;
3638
}
39+
40+
public int getConcurrentReconciliationThreads() {
41+
return concurrentReconciliationThreads;
42+
}
43+
44+
public void setConcurrentReconciliationThreads(int concurrentReconciliationThreads) {
45+
this.concurrentReconciliationThreads = concurrentReconciliationThreads;
46+
}
3747
}

0 commit comments

Comments
 (0)