Skip to content

Commit 0c5d589

Browse files
committed
feat: make EventSourceRegistry available from Context
1 parent 9abb469 commit 0c5d589

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package io.javaoperatorsdk.operator.api.reconciler;
22

3+
import io.fabric8.kubernetes.api.model.HasMetadata;
4+
import io.javaoperatorsdk.operator.processing.event.source.EventSourceRegistry;
35
import java.util.Optional;
46

5-
public interface Context {
7+
public interface Context<P extends HasMetadata> {
68

79
Optional<RetryInfo> getRetryInfo();
810

11+
EventSourceRegistry<P> getEventSourceRegistry();
12+
913
}
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
package io.javaoperatorsdk.operator.api.reconciler;
22

3+
import io.fabric8.kubernetes.api.model.HasMetadata;
4+
import io.javaoperatorsdk.operator.processing.event.source.EventSourceRegistry;
35
import java.util.Optional;
46

5-
public class DefaultContext implements Context {
7+
public class DefaultContext<P extends HasMetadata> implements Context<P> {
68

79
private final RetryInfo retryInfo;
10+
private final EventSourceRegistry<P> registry;
811

9-
public DefaultContext(RetryInfo retryInfo) {
12+
public DefaultContext(RetryInfo retryInfo,
13+
EventSourceRegistry<P> registry) {
1014
this.retryInfo = retryInfo;
15+
this.registry = registry;
1116
}
1217

1318
@Override
1419
public Optional<RetryInfo> getRetryInfo() {
1520
return Optional.ofNullable(retryInfo);
1621
}
22+
23+
@Override
24+
public EventSourceRegistry<P> getEventSourceRegistry() {
25+
return registry;
26+
}
1727
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface Reconciler<R extends HasMetadata> {
2828
* finalizer to indicate that the resource should not be deleted after all, in which case
2929
* the controller should restore the resource's state appropriately.
3030
*/
31-
default DeleteControl cleanup(R resource, Context context) {
31+
default DeleteControl cleanup(R resource, Context<R> context) {
3232
return DeleteControl.defaultDelete();
3333
}
3434

@@ -46,5 +46,5 @@ default DeleteControl cleanup(R resource, Context context) {
4646
* be skipped. <b>However we will always call an update if there is no finalizer on object
4747
* and it's not marked for deletion.</b>
4848
*/
49-
UpdateControl<R> reconcile(R resource, Context context);
49+
UpdateControl<R> reconcile(R resource, Context<R> context);
5050
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,8 @@ public void stop() {
285285
eventSourceManager.stop();
286286
}
287287
}
288+
289+
public EventSourceRegistry<R> getEventSourceRegistry() {
290+
return eventSourceManager;
291+
}
288292
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ private PostExecutionControl<R> handleDispatch(ExecutionScope<R> executionScope)
6767
return PostExecutionControl.defaultDispatch();
6868
}
6969

70-
Context context =
71-
new DefaultContext(executionScope.getRetryInfo());
70+
Context<R> context =
71+
new DefaultContext<>(executionScope.getRetryInfo(), controller.getEventSourceRegistry());
7272
if (markedForDeletion) {
7373
return handleCleanup(resource, context);
7474
} else {
@@ -91,7 +91,7 @@ private boolean shouldNotDispatchToDelete(R resource) {
9191
}
9292

9393
private PostExecutionControl<R> handleReconcile(
94-
ExecutionScope<R> executionScope, R originalResource, Context context) {
94+
ExecutionScope<R> executionScope, R originalResource, Context<R> context) {
9595
if (configuration().useFinalizer()
9696
&& !originalResource.hasFinalizer(configuration().getFinalizer())) {
9797
/*
@@ -121,7 +121,7 @@ private PostExecutionControl<R> handleReconcile(
121121
* resource is changed during an execution, and it's much cleaner to have to original resource in
122122
* place for status update.
123123
*/
124-
private R cloneResourceForErrorStatusHandlerIfNeeded(R resource, Context context) {
124+
private R cloneResourceForErrorStatusHandlerIfNeeded(R resource, Context<R> context) {
125125
if (isErrorStatusHandlerPresent() ||
126126
shouldUpdateObservedGenerationAutomatically(resource)) {
127127
return configuration().getConfigurationService().getResourceCloner().clone(resource);
@@ -131,7 +131,7 @@ private R cloneResourceForErrorStatusHandlerIfNeeded(R resource, Context context
131131
}
132132

133133
private PostExecutionControl<R> reconcileExecution(ExecutionScope<R> executionScope,
134-
R resourceForExecution, R originalResource, Context context) {
134+
R resourceForExecution, R originalResource, Context<R> context) {
135135
log.debug(
136136
"Executing createOrUpdate for resource {} with version: {} with execution scope: {}",
137137
getName(resourceForExecution),
@@ -161,7 +161,7 @@ && shouldUpdateObservedGenerationAutomatically(resourceForExecution)) {
161161
return createPostExecutionControl(updatedCustomResource, updateControl);
162162
}
163163

164-
private void handleErrorStatusHandler(R resource, Context context,
164+
private void handleErrorStatusHandler(R resource, Context<R> context,
165165
RuntimeException e) {
166166
if (isErrorStatusHandlerPresent()) {
167167
try {
@@ -238,7 +238,7 @@ private void updatePostExecutionControlWithReschedule(
238238
baseControl.getScheduleDelay().ifPresent(postExecutionControl::withReSchedule);
239239
}
240240

241-
private PostExecutionControl<R> handleCleanup(R resource, Context context) {
241+
private PostExecutionControl<R> handleCleanup(R resource, Context<R> context) {
242242
log.debug(
243243
"Executing delete for resource: {} with version: {}",
244244
getName(resource),

0 commit comments

Comments
 (0)