Skip to content

feat: add possibility to configure termination timeout #426

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ on [event sources](https://csviri.medium.com/java-operator-sdk-introduction-to-e
- Updated Fabric8 client to version 5.4.0
- It is now possible to configure the controllers to not automatically add finalizers to resources.
See the `Controller` annotation documentation for more details.
- Added the possibility to configure how many seconds the SDK will wait before terminating reconciliation threads when a shut down is requested

#### Overview of the 1.8.0 changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,16 @@ default int concurrentReconciliationThreads() {
default ObjectMapper getObjectMapper() {
return new ObjectMapper();
}

int DEFAULT_TERMINATION_TIMEOUT_SECONDS = 10;

/**
* Retrieves the number of seconds the SDK waits for reconciliation threads to terminate before
* shutting down.
*
* @return the number of seconds to wait before terminating reconciliation threads
*/
default int getTerminationTimeoutSeconds() {
return DEFAULT_TERMINATION_TIMEOUT_SECONDS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.javaoperatorsdk.operator.api.ResourceController;
import io.javaoperatorsdk.operator.api.RetryInfo;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager;
import io.javaoperatorsdk.operator.processing.event.Event;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class DefaultEventHandler implements EventHandler {
private final Retry retry;
private final Map<String, RetryExecution> retryState = new HashMap<>();
private final String controllerName;
private final int terminationTimeout;
private DefaultEventSourceManager eventSourceManager;

private final ReentrantLock lock = new ReentrantLock();
Expand All @@ -51,18 +53,34 @@ public DefaultEventHandler(
new EventDispatcher(controller, configuration, client),
configuration.getName(),
GenericRetry.fromConfiguration(configuration.getRetryConfiguration()),
configuration.getConfigurationService().concurrentReconciliationThreads());
configuration.getConfigurationService().concurrentReconciliationThreads(),
configuration.getConfigurationService().getTerminationTimeoutSeconds());
}

DefaultEventHandler(
EventDispatcher eventDispatcher,
String relatedControllerName,
Retry retry,
int concurrentReconciliationThreads) {
this(
eventDispatcher,
relatedControllerName,
retry,
concurrentReconciliationThreads,
ConfigurationService.DEFAULT_TERMINATION_TIMEOUT_SECONDS);
}

private DefaultEventHandler(
EventDispatcher eventDispatcher,
String relatedControllerName,
Retry retry,
int concurrentReconciliationThreads,
int terminationTimeout) {
this.eventDispatcher = eventDispatcher;
this.retry = retry;
this.controllerName = relatedControllerName;
eventBuffer = new EventBuffer();
this.terminationTimeout = terminationTimeout;
executor =
new ScheduledThreadPoolExecutor(
concurrentReconciliationThreads,
Expand All @@ -73,7 +91,7 @@ public DefaultEventHandler(
public void close() {
try {
log.debug("Closing handler for {}", controllerName);
executor.awaitTermination(10, TimeUnit.SECONDS);
executor.awaitTermination(terminationTimeout, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.debug("Exception closing handler for {}: {}", controllerName, e.getLocalizedMessage());
}
Expand Down