Skip to content

Commit fd6e493

Browse files
authored
fix: minor improvements (#799)
1 parent 3061d2b commit fd6e493

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public class EventSourceManager<R extends HasMetadata> implements LifecycleAware
4040
EventSourceManager(EventProcessor<R> eventProcessor) {
4141
this.eventProcessor = eventProcessor;
4242
controller = null;
43-
registerEventSource(eventSources.initRetryEventSource());
43+
registerEventSource(eventSources.retryEventSource());
4444
}
4545

4646
public EventSourceManager(Controller<R> controller) {
4747
this.controller = controller;
4848
// controller event source needs to be available before we create the event processor
4949
final var controllerEventSource = eventSources.initControllerEventSource(controller);
5050
this.eventProcessor = new EventProcessor<>(this);
51-
registerEventSource(eventSources.initRetryEventSource());
51+
registerEventSource(eventSources.retryEventSource());
5252
registerEventSource(controllerEventSource);
5353
}
5454

@@ -184,7 +184,7 @@ ControllerResourceEventSource<R> initControllerEventSource(Controller<R> control
184184
return controllerResourceEventSource;
185185
}
186186

187-
TimerEventSource<R> initRetryEventSource() {
187+
TimerEventSource<R> retryEventSource() {
188188
return retryAndRescheduleTimerEventSource;
189189
}
190190

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ResourceEventFilters.java

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public final class ResourceEventFilters {
2525
private static final ResourceEventFilter<HasMetadata> GENERATION_AWARE =
2626
(configuration, oldResource, newResource) -> {
2727
final var generationAware = configuration.isGenerationAware();
28-
// todo: change this to check for HasStatus (or similar) when
29-
// https://github.com/fabric8io/kubernetes-client/issues/3586 is fixed
3028
if (newResource instanceof CustomResource<?, ?>) {
3129
var newCustomResource = (CustomResource<?, ?>) newResource;
3230
final var status = newCustomResource.getStatus();

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public void onResourceDeleted(R resource) {
9797
cache.remove(resourceID);
9898
}
9999

100+
// This method is always called from the same Thread for the same resource,
101+
// since events from ResourceEventAware are propagated from the thread of the informer. This is
102+
// important
103+
// because otherwise there will be a race condition related to the timerTasks.
100104
private void checkAndRegisterTask(R resource) {
101105
var resourceID = ResourceID.fromResource(resource);
102106
if (timerTasks.get(resourceID) == null && (registerPredicate == null

sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaOperator.java

+2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public static void main(String[] args) throws IOException {
2727
KubernetesClient client = new DefaultKubernetesClient(config);
2828
Operator operator = new Operator(client, DefaultConfigurationService.instance());
2929
operator.register(new MySQLSchemaReconciler(client, MySQLDbConfig.loadFromEnvironmentVars()));
30+
operator.installShutdownHook();
3031
operator.start();
3132

33+
3234
new FtBasic(new TkFork(new FkRegex("/health", "ALL GOOD!")), 8080).start(Exit.NEVER);
3335
}
3436
}

sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatOperator.java

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static void main(String[] args) throws IOException {
2727
Operator operator = new Operator(client, DefaultConfigurationService.instance());
2828
operator.register(new TomcatReconciler(client));
2929
operator.register(new WebappReconciler(client));
30+
operator.installShutdownHook();
3031
operator.start();
3132

3233
new FtBasic(new TkFork(new FkRegex("/health", "ALL GOOD.")), 8080).start(Exit.NEVER);

sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static void main(String[] args) throws IOException {
2727
KubernetesClient client = new DefaultKubernetesClient(config);
2828
Operator operator = new Operator(client, DefaultConfigurationService.instance());
2929
operator.register(new WebPageReconciler(client));
30+
operator.installShutdownHook();
3031
operator.start();
3132

3233
new FtBasic(new TkFork(new FkRegex("/health", "ALL GOOD!")), 8080).start(Exit.NEVER);

0 commit comments

Comments
 (0)