From 211e0649b7250a51f5e1a4d3c18c7ba3f64aa57e Mon Sep 17 00:00:00 2001 From: Matt Riben Date: Thu, 22 Aug 2024 16:17:51 -0500 Subject: [PATCH] chore: update example of registering an event source Signed-off-by: Matt Riben --- docsy/content/en/docs/features/_index.md | 27 +++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/docsy/content/en/docs/features/_index.md b/docsy/content/en/docs/features/_index.md index b1f0ff166f..f78578d5d2 100644 --- a/docsy/content/en/docs/features/_index.md +++ b/docsy/content/en/docs/features/_index.md @@ -491,24 +491,27 @@ To register event sources, your `Reconciler` has to implement the [`EventSourceInitializer`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java) interface and initialize a list of event sources to register. One way to see this in action is to look at the -[tomcat example](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatReconciler.java) +[tomcat example](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java) (irrelevant details omitted): ```java @ControllerConfiguration -public class TomcatReconciler implements Reconciler, EventSourceInitializer { +public class WebappReconciler + implements Reconciler, Cleaner, EventSourceInitializer { - @Override - public List prepareEventSources(EventSourceContext context) { - var configMapEventSource = - new InformerEventSource<>(InformerConfiguration.from(Deployment.class, context) - .withLabelSelector(SELECTOR) - .withSecondaryToPrimaryMapper( - Mappers.fromAnnotation(ANNOTATION_NAME, ANNOTATION_NAMESPACE) - .build(), context)); - return EventSourceInitializer.nameEventSources(configMapEventSource); - } + @Override + public Map prepareEventSources(EventSourceContext context) { + InformerConfiguration configuration = + InformerConfiguration.from(Tomcat.class, context) + .withSecondaryToPrimaryMapper(webappsMatchingTomcatName) + .withPrimaryToSecondaryMapper( + (Webapp primary) -> Set.of(new ResourceID(primary.getSpec().getTomcat(), + primary.getMetadata().getNamespace()))) + .build(); + return EventSourceInitializer + .nameEventSources(new InformerEventSource<>(configuration, context)); + } ... } ```