@@ -491,25 +491,28 @@ To register event sources, your `Reconciler` has to implement the
491491[`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)
492492interface and initialize a list of event sources to register. One way to see this in action is
493493to look at the
494- [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)
494+ [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)
495495(irrelevant details omitted):
496496
497497```java
498498
499499@ControllerConfiguration
500- public class TomcatReconciler implements Reconciler<Tomcat>, EventSourceInitializer<Tomcat> {
501-
502- @Override
503- public List<EventSource> prepareEventSources(EventSourceContext<Tomcat> context) {
504- var configMapEventSource =
505- new InformerEventSource<>(InformerConfiguration.from(Deployment.class, context)
506- .withLabelSelector(SELECTOR)
507- .withSecondaryToPrimaryMapper(
508- Mappers.fromAnnotation(ANNOTATION_NAME, ANNOTATION_NAMESPACE)
509- .build(), context));
510- return EventSourceInitializer.nameEventSources(configMapEventSource);
511- }
512- ...
500+ public class WebappReconciler
501+ implements Reconciler<Webapp>, Cleaner<Webapp>, EventSourceInitializer<Webapp> {
502+
503+ @Override
504+ public Map<String, EventSource> prepareEventSources(EventSourceContext<Webapp> context) {
505+ InformerConfiguration<Tomcat> configuration =
506+ InformerConfiguration.from(Tomcat.class, context)
507+ .withSecondaryToPrimaryMapper(webappsMatchingTomcatName)
508+ .withPrimaryToSecondaryMapper(
509+ (Webapp primary) -> Set.of(new ResourceID(primary.getSpec().getTomcat(),
510+ primary.getMetadata().getNamespace())))
511+ .build();
512+ return EventSourceInitializer
513+ .nameEventSources(new InformerEventSource<>(configuration, context));
514+ }
515+ ...
513516}
514517```
515518
0 commit comments