Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add automatic closure of operator on shut down #102

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ ConfigurationServiceBuildItem createConfigurationServiceAndOperator(

additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(OperatorProducer.class));

// if the app doesn't provide a main class, add the StartupListener
// if the app doesn't provide a main class, add the AppEventListener
if (index.getAllKnownImplementors(DotName.createSimple(QuarkusApplication.class.getName())).isEmpty()) {
additionalBeans.produce(AdditionalBeanBuildItem.builder()
.addBeanClass(StartupListener.class).setDefaultScope(DotName.createSimple(Singleton.class.getName()))
.addBeanClass(AppEventListener.class).setDefaultScope(DotName.createSimple(Singleton.class.getName()))
.setUnremovable()
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.slf4j.LoggerFactory;

import io.javaoperatorsdk.operator.Operator;
import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;

public class StartupListener {
private static final Logger log = LoggerFactory.getLogger(StartupListener.class);
public class AppEventListener {
private static final Logger log = LoggerFactory.getLogger(AppEventListener.class);
private final Operator operator;
private final QuarkusConfigurationService configurationService;

public StartupListener(Operator operator, QuarkusConfigurationService configurationService) {
public AppEventListener(Operator operator, QuarkusConfigurationService configurationService) {
this.operator = operator;
this.configurationService = configurationService;
}
Expand All @@ -29,4 +30,9 @@ public void onStartup(@Observes StartupEvent event) {
}
operator.start();
}

public void onShutdown(@Observes ShutdownEvent event) {
log.info("Quarkus Java Operator SDK extension is shutting down");
operator.close();
}
}