Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/content/en/docs/documentation/reconciler.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ However, there are cases when controllers do not strictly follow those patterns,
and you don't want to use finalizers. For those cases, you typically want to clean up your caches when the primary
resource is deleted.

For such use cases you can set [`triggerReconcilerOnAllEvent`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java#L81)
For such use cases you can set [`triggerReconcilerOnAllEvents`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java#L107)
to `true`, as a result, the `reconcile` method will be triggered on ALL events (so also `Delete` events), making it
possible to support the above use cases.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ private <P extends HasMetadata> ResolvedControllerConfiguration<P> controllerCon
final var dependentFieldManager =
fieldManager.equals(CONTROLLER_NAME_AS_FIELD_MANAGER) ? name : fieldManager;

var triggerReconcilerOnAllEvent =
annotation != null && annotation.triggerReconcilerOnAllEvent();
var triggerReconcilerOnAllEvents =
annotation != null && annotation.triggerReconcilerOnAllEvents();

InformerConfiguration<P> informerConfig =
InformerConfiguration.builder(resourceClass)
Expand All @@ -342,7 +342,7 @@ private <P extends HasMetadata> ResolvedControllerConfiguration<P> controllerCon
dependentFieldManager,
this,
informerConfig,
triggerReconcilerOnAllEvent);
triggerReconcilerOnAllEvents);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ default String fieldManager() {

<C> C getConfigurationFor(DependentResourceSpec<?, P, C> spec);

/**
* @deprecated use {@link #triggerReconcilerOnAllEvents()} instead
*/
@Deprecated(forRemoval = true)
default boolean triggerReconcilerOnAllEvent() {
return triggerReconcilerOnAllEvents();
}

default boolean triggerReconcilerOnAllEvents() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ControllerConfigurationOverrider<R extends HasMetadata> {
private Duration reconciliationMaxInterval;
private Map<DependentResourceSpec, Object> configurations;
private final InformerConfiguration<R>.Builder config;
private boolean triggerReconcilerOnAllEvent;
private boolean triggerReconcilerOnAllEvents;

private ControllerConfigurationOverrider(ControllerConfiguration<R> original) {
this.finalizer = original.getFinalizerName();
Expand All @@ -58,7 +58,7 @@ private ControllerConfigurationOverrider(ControllerConfiguration<R> original) {
this.rateLimiter = original.getRateLimiter();
this.name = original.getName();
this.fieldManager = original.fieldManager();
this.triggerReconcilerOnAllEvent = original.triggerReconcilerOnAllEvent();
this.triggerReconcilerOnAllEvents = original.triggerReconcilerOnAllEvents();
}

public ControllerConfigurationOverrider<R> withFinalizer(String finalizer) {
Expand Down Expand Up @@ -171,9 +171,18 @@ public ControllerConfigurationOverrider<R> withFieldManager(String dependentFiel
return this;
}

/**
* @deprecated use {@link #withTriggerReconcilerOnAllEvents(boolean)} instead
*/
@Deprecated(forRemoval = true)
public ControllerConfigurationOverrider<R> withTriggerReconcilerOnAllEvent(
boolean triggerReconcilerOnAllEvent) {
this.triggerReconcilerOnAllEvent = triggerReconcilerOnAllEvent;
boolean triggerReconcilerOnAllEvents) {
return withTriggerReconcilerOnAllEvents(triggerReconcilerOnAllEvents);
}

public ControllerConfigurationOverrider<R> withTriggerReconcilerOnAllEvents(
boolean triggerReconcilerOnAllEvents) {
this.triggerReconcilerOnAllEvents = triggerReconcilerOnAllEvents;
return this;
}

Expand Down Expand Up @@ -221,7 +230,7 @@ public ControllerConfiguration<R> build() {
fieldManager,
original.getConfigurationService(),
config.buildForController(),
triggerReconcilerOnAllEvent,
triggerReconcilerOnAllEvents,
original.getWorkflowSpec().orElse(null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class ResolvedControllerConfiguration<P extends HasMetadata>
private final Map<DependentResourceSpec, Object> configurations;
private final ConfigurationService configurationService;
private final String fieldManager;
private final boolean triggerReconcilerOnAllEvent;
private final boolean triggerReconcilerOnAllEvents;
private WorkflowSpec workflowSpec;

public ResolvedControllerConfiguration(ControllerConfiguration<P> other) {
Expand All @@ -60,7 +60,7 @@ public ResolvedControllerConfiguration(ControllerConfiguration<P> other) {
other.fieldManager(),
other.getConfigurationService(),
other.getInformerConfig(),
other.triggerReconcilerOnAllEvent(),
other.triggerReconcilerOnAllEvents(),
other.getWorkflowSpec().orElse(null));
}

Expand All @@ -76,7 +76,7 @@ public ResolvedControllerConfiguration(
String fieldManager,
ConfigurationService configurationService,
InformerConfiguration<P> informerConfig,
boolean triggerReconcilerOnAllEvent,
boolean triggerReconcilerOnAllEvents,
WorkflowSpec workflowSpec) {
this(
name,
Expand All @@ -90,7 +90,7 @@ public ResolvedControllerConfiguration(
fieldManager,
configurationService,
informerConfig,
triggerReconcilerOnAllEvent);
triggerReconcilerOnAllEvents);
setWorkflowSpec(workflowSpec);
}

Expand All @@ -106,7 +106,7 @@ protected ResolvedControllerConfiguration(
String fieldManager,
ConfigurationService configurationService,
InformerConfiguration<P> informerConfig,
boolean triggerReconcilerOnAllEvent) {
boolean triggerReconcilerOnAllEvents) {
this.informerConfig = informerConfig;
this.configurationService = configurationService;
this.name = ControllerConfiguration.ensureValidName(name, associatedReconcilerClassName);
Expand All @@ -119,7 +119,7 @@ protected ResolvedControllerConfiguration(
this.finalizer =
ControllerConfiguration.ensureValidFinalizerName(finalizer, getResourceTypeName());
this.fieldManager = fieldManager;
this.triggerReconcilerOnAllEvent = triggerReconcilerOnAllEvent;
this.triggerReconcilerOnAllEvents = triggerReconcilerOnAllEvents;
}

protected ResolvedControllerConfiguration(
Expand Down Expand Up @@ -231,7 +231,7 @@ public String fieldManager() {
}

@Override
public boolean triggerReconcilerOnAllEvent() {
return triggerReconcilerOnAllEvent;
public boolean triggerReconcilerOnAllEvents() {
return triggerReconcilerOnAllEvents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ default <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType) {
/**
* To check if the primary resource is already deleted. This value can be true only if you turn on
* {@link
* io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration#triggerReconcilerOnAllEvent()}
* io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration#triggerReconcilerOnAllEvents()}
*
* @return true Delete event received for primary resource
* @since 5.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ MaxReconciliationInterval maxReconciliationInterval() default
*/
String fieldManager() default CONTROLLER_NAME_AS_FIELD_MANAGER;

/**
* @deprecated use {@link #triggerReconcilerOnAllEvents()} instead
*/
@Deprecated(forRemoval = true)
boolean triggerReconcilerOnAllEvent() default false;

/**
* By settings to true, reconcile method will be triggered on every event, thus even for Delete
* event. You cannot use {@link Cleaner} or managed dependent resources in that case. See
* documentation for further details.
*/
boolean triggerReconcilerOnAllEvent() default false;
boolean triggerReconcilerOnAllEvents() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public class Controller<P extends HasMetadata>
private static final String STATUS = "status";
private static final String BOTH = "both";
public static final String CLEANER_NOT_SUPPORTED_ON_ALL_EVENT_ERROR_MESSAGE =
"Cleaner is not supported when triggerReconcilerOnAllEvent enabled.";
"Cleaner is not supported when triggerReconcilerOnAllEvents enabled.";
public static final String
MANAGED_WORKFLOWS_NOT_SUPPORTED_TRIGGER_RECONCILER_ON_ALL_EVENT_ERROR_MESSAGE =
"Managed workflows are not supported when triggerReconcilerOnAllEvent enabled.";
"Managed workflows are not supported when triggerReconcilerOnAllEvents enabled.";

private final Reconciler<P> reconciler;
private final ControllerConfiguration<P> configuration;
Expand Down Expand Up @@ -117,7 +117,7 @@ public Controller(
explicitWorkflowInvocation =
configuration.getWorkflowSpec().map(WorkflowSpec::isExplicitInvocation).orElse(false);

if (configuration.triggerReconcilerOnAllEvent()) {
if (configuration.triggerReconcilerOnAllEvents()) {
if (isCleaner) {
throw new OperatorException(CLEANER_NOT_SUPPORTED_ON_ALL_EVENT_ERROR_MESSAGE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public synchronized void handleEvent(Event event) {
}

private void handleMarkedEventForResource(ResourceState state) {
if (state.deleteEventPresent() && !triggerOnAllEvent()) {
if (state.deleteEventPresent() && !triggerOnAllEvents()) {
cleanupForDeletedEvent(state.getId());
} else if (!state.processedMarkForDeletionPresent()) {
submitReconciliationExecution(state);
Expand Down Expand Up @@ -181,7 +181,7 @@ private void submitReconciliationExecution(ResourceState state) {
state.getRetry(),
state.deleteEventPresent(),
state.isDeleteFinalStateUnknown());
state.unMarkEventReceived(triggerOnAllEvent());
state.unMarkEventReceived(triggerOnAllEvents());
metrics.reconcileCustomResource(latest, state.getRetry(), metricsMetadata);
log.debug("Executing events for custom resource. Scope: {}", executionScope);
executor.execute(new ReconcilerExecutor(resourceID, executionScope));
Expand All @@ -208,7 +208,7 @@ private void submitReconciliationExecution(ResourceState state) {

@SuppressWarnings("unchecked")
private P getResourceFromState(ResourceState state) {
if (triggerOnAllEvent()) {
if (triggerOnAllEvents()) {
log.debug("Getting resource from state for {}", state.getId());
return (P) state.getLastKnownResource();
} else {
Expand Down Expand Up @@ -239,10 +239,10 @@ private void handleEventMarking(Event event, ResourceState state) {
// removed, but also the informers websocket is disconnected and later reconnected. So
// meanwhile the resource could be deleted and recreated. In this case we just mark a new
// event as below.
state.markEventReceived(triggerOnAllEvent());
state.markEventReceived(triggerOnAllEvents());
}
} else if (!state.deleteEventPresent() && !state.processedMarkForDeletionPresent()) {
state.markEventReceived(triggerOnAllEvent());
state.markEventReceived(triggerOnAllEvents());
} else if (isTriggerOnAllEventAndDeleteEventPresent(state)) {
state.markAdditionalEventAfterDeleteEvent();
} else if (log.isDebugEnabled()) {
Expand Down Expand Up @@ -286,15 +286,15 @@ synchronized void eventProcessingFinished(
// Either way we don't want to retry.
if (isRetryConfigured()
&& postExecutionControl.exceptionDuringExecution()
&& (!state.deleteEventPresent() || triggerOnAllEvent())) {
&& (!state.deleteEventPresent() || triggerOnAllEvents())) {
handleRetryOnException(
executionScope, postExecutionControl.getRuntimeException().orElseThrow());
return;
}
cleanupOnSuccessfulExecution(executionScope);
metrics.finishedReconciliation(executionScope.getResource(), metricsMetadata);
if ((triggerOnAllEvent() && executionScope.isDeleteEvent())
|| (!triggerOnAllEvent() && state.deleteEventPresent())) {
if ((triggerOnAllEvents() && executionScope.isDeleteEvent())
|| (!triggerOnAllEvents() && state.deleteEventPresent())) {
cleanupForDeletedEvent(executionScope.getResourceID());
} else if (postExecutionControl.isFinalizerRemoved()) {
state.markProcessedMarkForDeletion();
Expand All @@ -310,7 +310,7 @@ synchronized void eventProcessingFinished(
}

private boolean isTriggerOnAllEventAndDeleteEventPresent(ResourceState state) {
return triggerOnAllEvent() && state.deleteEventPresent();
return triggerOnAllEvents() && state.deleteEventPresent();
}

/**
Expand Down Expand Up @@ -370,8 +370,8 @@ private void handleRetryOnException(ExecutionScope<P> executionScope, Exception
var resourceID = state.getId();
boolean eventPresent =
state.eventPresent()
|| (triggerOnAllEvent() && state.isAdditionalEventPresentAfterDeleteEvent());
state.markEventReceived(triggerOnAllEvent());
|| (triggerOnAllEvents() && state.isAdditionalEventPresentAfterDeleteEvent());
state.markEventReceived(triggerOnAllEvents());

retryAwareErrorLogging(state.getRetry(), eventPresent, exception, executionScope);
if (eventPresent) {
Expand Down Expand Up @@ -517,7 +517,7 @@ public void run() {
// we try to get the most up-to-date resource from cache
var actualResource = cache.get(resourceID);
if (actualResource.isEmpty()) {
if (triggerOnAllEvent()) {
if (triggerOnAllEvents()) {
log.debug(
"Resource not found in the cache, checking for delete event resource: {}",
resourceID);
Expand Down Expand Up @@ -578,7 +578,7 @@ public synchronized boolean isRunning() {
}

// shortening
private boolean triggerOnAllEvent() {
return controllerConfiguration.triggerReconcilerOnAllEvent();
private boolean triggerOnAllEvents() {
return controllerConfiguration.triggerReconcilerOnAllEvents();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class EventSourceManager<P extends HasMetadata>
public EventSourceManager(Controller<P> controller) {
this(
controller,
new EventSources<>(controller.getConfiguration().triggerReconcilerOnAllEvent()));
new EventSources<>(controller.getConfiguration().triggerReconcilerOnAllEvents()));
}

EventSourceManager(Controller<P> controller, EventSources<P> eventSources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class EventSources<P extends HasMetadata> {
private final TimerEventSource<P> retryAndRescheduleTimerEventSource;
private ControllerEventSource<P> controllerEventSource;

public EventSources(boolean triggerReconcilerOnAllEvent) {
public EventSources(boolean triggerReconcilerOnAllEvents) {
retryAndRescheduleTimerEventSource =
new TimerEventSource<>("RetryAndRescheduleTimerEventSource", triggerReconcilerOnAllEvent);
new TimerEventSource<>("RetryAndRescheduleTimerEventSource", triggerReconcilerOnAllEvents);
}

EventSources() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private PostExecutionControl<P> handleDispatch(ExecutionScope<P> executionScope)
originalResource.getMetadata().getNamespace());

final var markedForDeletion = originalResource.isMarkedForDeletion();
if (!triggerOnAllEvent()
if (!triggerOnAllEvents()
&& markedForDeletion
&& shouldNotDispatchToCleanupWhenMarkedForDeletion(originalResource)) {
log.debug(
Expand All @@ -118,7 +118,7 @@ && shouldNotDispatchToCleanupWhenMarkedForDeletion(originalResource)) {
executionScope.isDeleteFinalStateUnknown());

// checking the cleaner for all-event-mode
if (!triggerOnAllEvent() && markedForDeletion) {
if (!triggerOnAllEvents() && markedForDeletion) {
return handleCleanup(resourceForExecution, originalResource, context, executionScope);
} else {
return handleReconcile(executionScope, resourceForExecution, originalResource, context);
Expand All @@ -137,7 +137,7 @@ private PostExecutionControl<P> handleReconcile(
P originalResource,
Context<P> context)
throws Exception {
if (!triggerOnAllEvent()
if (!triggerOnAllEvents()
&& controller.useFinalizer()
&& !originalResource.hasFinalizer(configuration().getFinalizerName())) {
/*
Expand Down Expand Up @@ -329,7 +329,7 @@ private PostExecutionControl<P> handleCleanup(
}
DeleteControl deleteControl = controller.cleanup(resourceForExecution, context);
final var useFinalizer = controller.useFinalizer();
if (useFinalizer && !triggerOnAllEvent()) {
if (useFinalizer && !triggerOnAllEvents()) {
// note that we don't reschedule here even if instructed. Removing finalizer means that
// cleanup is finished, nothing left to be done
final var finalizerName = configuration().getFinalizerName();
Expand Down Expand Up @@ -477,7 +477,7 @@ public P conflictRetryingPatch(
}

private void validateExecutionScope(ExecutionScope<P> executionScope) {
if (!triggerOnAllEvent()
if (!triggerOnAllEvents()
&& (executionScope.isDeleteEvent() || executionScope.isDeleteFinalStateUnknown())) {
throw new OperatorException(
"isDeleteEvent or isDeleteFinalStateUnknown cannot be true if not triggerOnAllEvent."
Expand Down Expand Up @@ -589,7 +589,7 @@ private Resource<R> resource(R resource) {
}
}

private boolean triggerOnAllEvent() {
return configuration().triggerReconcilerOnAllEvent();
private boolean triggerOnAllEvents() {
return configuration().triggerReconcilerOnAllEvents();
}
}
Loading