Draft
Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@

public interface ControllerConfiguration<P extends HasMetadata> extends ResourceConfiguration<P> {

boolean DEFAULT_RECONCILER_RESOURCES_MARKED_FOR_DELETION = false;


@SuppressWarnings("rawtypes")
RateLimiter DEFAULT_RATE_LIMITER = LinearRateLimiter.deactivatedRateLimiter();
/**
Expand DownExpand Up@@ -140,4 +143,8 @@ default String fieldManager() {
return getName();
}

default boolean reconcileResourcesMarkedForDeletion() {
return DEFAULT_RECONCILER_RESOURCES_MARKED_FOR_DELETION;
}

}
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@
import io.javaoperatorsdk.operator.processing.retry.Retry;

import static io.javaoperatorsdk.operator.api.config.ControllerConfiguration.CONTROLLER_NAME_AS_FIELD_MANAGER;
import static io.javaoperatorsdk.operator.api.config.ControllerConfiguration.DEFAULT_RECONCILER_RESOURCES_MARKED_FOR_DELETION;
import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_LONG_VALUE_SET;

@Inherited
Expand DownExpand Up@@ -166,4 +167,11 @@ MaxReconciliationInterval maxReconciliationInterval() default @MaxReconciliation
* the informer cache.
*/
long informerListLimit() default NO_LONG_VALUE_SET;

/**
* if true and reconciler not implements {@link Cleaner} interface executes reconciliation even if
* controller is marked for deletion, thus when waiting for other finalizer removal. This allows
* to manage corner cases when not all resources will need a finalizer.
*/
boolean reconcileResourcesMarkedForDeletion() default DEFAULT_RECONCILER_RESOURCES_MARKED_FOR_DELETION;
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,7 +75,7 @@ private PostExecutionControl<P> handleDis(ExecutionScope<P> executionScope)
originalResource.getMetadata().getNamespace());

final var markedForDeletion = originalResource.isMarkedForDeletion();
if (markedForDeletion && shouldNotDisToCleanupWhenMarkedForDeletion(originalResource)) {
if (markedForDeletion && shouldNotDisWhenMarkedForDeletion(originalResource)) {
log.debug(
"Skipping cleanup of resource {} because finalizer(s) {} don't allow processing yet",
getName(originalResource),
Expand All@@ -85,21 +85,22 @@ private PostExecutionControl<P> handleDis(ExecutionScope<P> executionScope)

Context<P> context =
new DefaultContext<>(executionScope.getRetryInfo(), controller, originalResource);
if (markedForDeletion) {
if (markedForDeletion && controller.useFinalizer()) {
return handleCleanup(resourceForExecution, context);
} else {
return handleReconcile(executionScope, resourceForExecution, originalResource, context);
}
}

private boolean shouldNotDisToCleanupWhenMarkedForDeletion(P resource) {
private boolean shouldNotDisWhenMarkedForDeletion(P resource) {
var alreadyRemovedFinalizer = controller.useFinalizer()
&& !resource.hasFinalizer(configuration().getFinalizerName());
if (alreadyRemovedFinalizer) {
log.warn("This should not happen. Marked for deletion & already removed finalizer: {}",
ResourceID.fromResource(resource));
}
return !controller.useFinalizer() || alreadyRemovedFinalizer;
return !controller.getConfiguration().reconcileResourcesMarkedForDeletion() &&
(!controller.useFinalizer() || alreadyRemovedFinalizer);
}

private PostExecutionControl<P> handleReconcile(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -145,7 +145,8 @@ public ControllerConfig(String finalizer, boolean generationAware,
null,
null,
null,
null, null, null, finalizer, null, null, null, new BaseConfigurationService(), null);
null, null, null, finalizer, null, null, null, new BaseConfigurationService(), null,
false);
setEventFilter(eventFilter);
}
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -199,7 +199,7 @@ public TestConfiguration(boolean generationAware, OnAddFilter<TestCustomResource
null,
FINALIZER,
null, null, null, new BaseConfigurationService(),
null);
null, DEFAULT_RECONCILER_RESOURCES_MARKED_FOR_DELETION);
}
}
}