Skip to content

Commit b793702

Browse files
authored
docs: fixes on event source page (#2739)
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent cc3d0cc commit b793702

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

docs/content/en/docs/documentation/eventing.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ controller implementations because reconciliations are then only triggered when
2323
on resources affecting our primary resources thus doing away with the need to periodically
2424
reschedule reconciliations.
2525

26-
![Event Sources architecture diagram](../assets/images/event-sources.png)
26+
![Event Sources architecture diagram](/images/event-sources.png)
2727

2828
There are few interesting points here:
2929

@@ -60,29 +60,26 @@ related [method](https://github.com/java-operator-sdk/java-operator-sdk/blob/mai
6060
To register event sources, your `Reconciler` has to override the `prepareEventSources` and return
6161
list of event sources to register. One way to see this in action is
6262
to look at the
63-
[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)
63+
[WebPage example](https://github.com/operator-framework/java-operator-sdk/blob/main/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java)
6464
(irrelevant details omitted):
6565

6666
```java
6767

68+
import java.util.List;
69+
6870
@ControllerConfiguration
6971
public class WebappReconciler
7072
implements Reconciler<Webapp>, Cleaner<Webapp>, EventSourceInitializer<Webapp> {
71-
// ommitted code
72-
73-
@Override
74-
public Map<String, EventSource> prepareEventSources(EventSourceContext<Webapp> context) {
75-
InformerEventSourceConfiguration<Tomcat> configuration =
76-
InformerEventSourceConfiguration.from(Tomcat.class, Tomcat.class)
77-
.withSecondaryToPrimaryMapper(webappsMatchingTomcatName)
78-
.withPrimaryToSecondaryMapper(
79-
(Webapp primary) -> Set.of(new ResourceID(primary.getSpec().getTomcat(),
80-
primary.getMetadata().getNamespace())))
73+
// ommitted code
74+
75+
@Override
76+
public List<EventSource<?, Webapp>> prepareEventSources(EventSourceContext<Webapp> context) {
77+
InformerEventSourceConfiguration<Webapp> configuration =
78+
InformerEventSourceConfiguration.from(Deployment.class, Webapp.class)
79+
.withLabelSelector(SELECTOR)
8180
.build();
82-
return EventSourceInitializer
83-
.nameEventSources(new InformerEventSource<>(configuration, context));
81+
return List.of(new InformerEventSource<>(configuration, context));
8482
}
85-
8683
}
8784
```
8885

@@ -95,8 +92,8 @@ cover common use cases.
9592
Event sources let your operator know when a secondary resource has changed and that your
9693
operator might need to reconcile this new information. However, in order to do so, the SDK needs
9794
to somehow retrieve the primary resource associated with which ever secondary resource triggered
98-
the event. In the `Tomcat` example above, when an event occurs on a tracked `Deployment`, the
99-
SDK needs to be able to identify which `Tomcat` resource is impacted by that change.
95+
the event. In the `Webapp` example above, when an event occurs on a tracked `Deployment`, the
96+
SDK needs to be able to identify which `Webapp` resource is impacted by that change.
10097

10198
Seasoned Kubernetes users already know one way to track this parent-child kind of relationship:
10299
using owner references. Indeed, that's how the SDK deals with this situation by default as well,
@@ -198,7 +195,7 @@ simply set a client that connects to a remote cluster:
198195

199196
```java
200197

201-
InformerEventSourceConfiguration<Tomcat> configuration =
198+
InformerEventSourceConfiguration<WebPage> configuration =
202199
InformerEventSourceConfiguration.from(SecondaryResource.class, PrimaryResource.class)
203200
.withKubernetesClient(remoteClusterClient)
204201
.withSecondaryToPrimaryMapper(Mappers.fromDefaultAnnotations());
@@ -323,8 +320,8 @@ evict cold resources than try to limit cache sizes.
323320

324321
See usage of the related implementation using [Caffeine](https://github.com/ben-manes/caffeine) cache in integration
325322
tests
326-
for [primary resources](https://github.com/java-operator-sdk/java-operator-sdk/blob/902c8a562dfd7f8993a52e03473a7ad4b00f378b/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java#L29-L29).
323+
for [primary resources](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java).
327324

328325
See
329-
also [CaffeineBoundedItemStores](https://github.com/java-operator-sdk/java-operator-sdk/blob/902c8a562dfd7f8993a52e03473a7ad4b00f378b/caffeine-bounded-cache-support/src/main/java/io/javaoperatorsdk/operator/processing/event/source/cache/CaffeineBoundedItemStores.java)
326+
also [CaffeineBoundedItemStores](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/caffeine-bounded-cache-support/src/main/java/io/javaoperatorsdk/operator/processing/event/source/cache/CaffeineBoundedItemStores.java)
330327
for more details.

docs/static/images/event-sources.png

93.6 KB
Loading

0 commit comments

Comments
 (0)