Skip to content

Commit 44b1245

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 66cad0a commit 44b1245

File tree

1 file changed

+32
-15
lines changed
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event

1 file changed

+32
-15
lines changed

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class EventProcessor<P extends HasMetadata> implements EventHandler, Life
4747
private final Map<String, Object> metricsMetadata;
4848
private ExecutorService executor;
4949

50+
// todo handle/test case when there is finalizer but not ours
5051
public EventProcessor(
5152
EventSourceManager<P> eventSourceManager, ConfigurationService configurationService) {
5253
this(
@@ -122,15 +123,15 @@ public synchronized void handleEvent(Event event) {
122123
}
123124

124125
private void handleMarkedEventForResource(ResourceState<P> state) {
125-
if (skipDeleteEventProcessing(state)) {
126+
if (doCleanupForDeleteEvent(state)) {
126127
cleanupForDeletedEvent(state.getId());
127128
} else if (!state.processedMarkForDeletionPresent()
128129
&& !state.deleteEventReconciliationSubmitted()) {
129130
submitReconciliationExecution(state);
130131
}
131132
}
132133

133-
private boolean skipDeleteEventProcessing(ResourceState<P> state) {
134+
private boolean doCleanupForDeleteEvent(ResourceState<P> state) {
134135
return state.deleteEventPresent() && !controllerConfiguration.reconcileOnPrimaryDelete();
135136
}
136137

@@ -146,6 +147,7 @@ private void submitReconciliationExecution(ResourceState<P> state) {
146147
rateLimit = rateLimiter.initState();
147148
state.setRateLimit(rateLimit);
148149
}
150+
// todo rate limit handling
149151
var rateLimiterPermission = rateLimiter.isLimited(rateLimit);
150152
if (rateLimiterPermission.isPresent()) {
151153
handleRateLimitedSubmission(resourceID, rateLimiterPermission.get());
@@ -158,13 +160,16 @@ private void submitReconciliationExecution(ResourceState<P> state) {
158160

159161
if (state.deleteEventPresent()) {
160162
state.markDeleteEventReconciliationSubmitted();
161-
} else {
163+
} else if (!state.deleteEventReconciliationSubmitted()) { // if there is a retry
162164
state.unMarkEventReceived();
163165
}
164-
165166
metrics.reconcileCustomResource(latest, state.getRetry(), metricsMetadata);
166167
log.debug("Executing events for custom resource. Scope: {}", executionScope);
167-
executor.execute(new ReconcilerExecutor(resourceID, executionScope));
168+
executor.execute(
169+
new ReconcilerExecutor(
170+
resourceID,
171+
executionScope,
172+
state.deleteEventReconciliationSubmitted() ? latest : null));
168173
} else {
169174
log.debug(
170175
"Skipping executing controller for resource id: {}. Controller in execution: {}. Latest"
@@ -191,7 +196,8 @@ private Optional<P> getCachedResource(ResourceID resourceID, ResourceState<P> st
191196
if (resource.isPresent()) {
192197
return resource;
193198
}
194-
if (controllerConfiguration.reconcileOnPrimaryDelete() && state.deleteEventPresent()) {
199+
if (controllerConfiguration.reconcileOnPrimaryDelete()
200+
&& (state.deleteEventPresent() || state.deleteEventReconciliationSubmitted())) {
195201
return Optional.of(state.getDeletedResource());
196202
}
197203
return Optional.empty();
@@ -206,10 +212,14 @@ private void handleEventMarking(Event event, ResourceState<P> state) {
206212
// todo check can there be delete event without resource?
207213
state.markDeleteEventReceived((P) resourceEvent.getResource().orElseThrow());
208214
} else {
209-
if (state.processedMarkForDeletionPresent() && isResourceMarkedForDeletion(resourceEvent)) {
215+
if (state.deleteEventReconciliationSubmitted()
216+
|| (state.processedMarkForDeletionPresent()
217+
&& isResourceMarkedForDeletion(resourceEvent))) {
210218
log.debug(
211-
"Skipping mark of event received, since already processed mark for deletion and"
212-
+ " resource marked for deletion: {}",
219+
"Skipping mark of event received, delete event reconciliation submitted ({}), or"
220+
+ " marked for deletion but already processed mark. resource marked for deletion:"
221+
+ " {}",
222+
state.deleteEventReconciliationSubmitted(),
213223
relatedCustomResourceID);
214224
return;
215225
}
@@ -221,15 +231,17 @@ private void handleEventMarking(Event event, ResourceState<P> state) {
221231
// event as below.
222232
markEventReceived(state);
223233
}
224-
// todo this if is weird
225-
} else if (!state.deleteEventPresent() || !state.processedMarkForDeletionPresent()) {
234+
} else if (!state.deleteEventPresent()
235+
&& !state.processedMarkForDeletionPresent()
236+
&& !state.deleteEventReconciliationSubmitted()) {
226237
markEventReceived(state);
227238
} else if (log.isDebugEnabled()) {
228239
log.debug(
229240
"Skipped marking event as received. Delete event present: {}, processed mark for"
230-
+ " deletion: {}",
241+
+ " deletion: {}, delete event reconciliation submitted: {}",
231242
state.deleteEventPresent(),
232-
state.processedMarkForDeletionPresent());
243+
state.processedMarkForDeletionPresent(),
244+
state.deleteEventReconciliationSubmitted());
233245
}
234246
}
235247

@@ -469,10 +481,13 @@ private void handleAlreadyMarkedEvents() {
469481
private class ReconcilerExecutor implements Runnable {
470482
private final ExecutionScope<P> executionScope;
471483
private final ResourceID resourceID;
484+
private final P deleteEventResource;
472485

473-
private ReconcilerExecutor(ResourceID resourceID, ExecutionScope<P> executionScope) {
486+
private ReconcilerExecutor(
487+
ResourceID resourceID, ExecutionScope<P> executionScope, P deleteEventResource) {
474488
this.executionScope = executionScope;
475489
this.resourceID = resourceID;
490+
this.deleteEventResource = deleteEventResource;
476491
}
477492

478493
@Override
@@ -488,7 +503,9 @@ public void run() {
488503
final var thread = Thread.currentThread();
489504
final var name = thread.getName();
490505
try {
491-
var actualResource = cache.get(resourceID);
506+
507+
var actualResource =
508+
deleteEventResource != null ? Optional.of(deleteEventResource) : cache.get(resourceID);
492509
if (actualResource.isEmpty()) {
493510
log.debug("Skipping execution; primary resource missing from cache: {}", resourceID);
494511
return;

0 commit comments

Comments
 (0)