You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/en/docs/documentation/working-with-es-caches.md
+34-31Lines changed: 34 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
---
2
-
title: Accessing resources in caches
2
+
title: Working with EventSource caches
3
3
weight: 48
4
4
---
5
5
6
6
As described in [Event sources and related topics](eventing.md), event sources serve as the backbone
7
7
for caching resources and triggering reconciliation for primary resources that are related
8
-
to cached resources.
8
+
to these secondary resources.
9
9
10
10
In the Kubernetes ecosystem, the component responsible for this is called an Informer. Without delving into
11
-
the details (there are plenty of excellent resources online about informers), its responsibility
12
-
is to watch resources, cache them, and emit events when resources change.
11
+
the details (there are plenty of excellent resources online about informers), informers
12
+
watch resources, cache them, and emit events when resources change.
13
13
14
-
EventSource is a generalized concept that extends the Informer pattern to non-Kubernetes resources,
14
+
`EventSource` is a generalized concept that extends the Informer pattern to non-Kubernetes resources,
15
15
allowing you to cache external resources and trigger reconciliation when those resources change.
16
16
17
17
## The InformerEventSource
18
18
19
-
The underlying informer implementation comes from the fabric8 client, specifically the[DefaultSharedIndexInformer](https://github.com/fabric8io/kubernetes-client/blob/main/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/informers/impl/DefaultSharedIndexInformer.java).
19
+
The underlying informer implementation comes from the Fabric8 client, called[DefaultSharedIndexInformer](https://github.com/fabric8io/kubernetes-client/blob/main/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/informers/impl/DefaultSharedIndexInformer.java).
in Java Operator SDK wraps the fabric8 client informers.
21
+
in Java Operator SDK wraps the Fabric8 client informers.
22
22
This wrapper adds additional capabilities specifically required for controllers
23
23
(note that informers have broader applications beyond just implementing controllers).
24
24
@@ -30,40 +30,43 @@ These additional capabilities include:
30
30
31
31
### Associating Secondary Resources to Primary Resource
32
32
33
-
The key question is: how do you trigger reconciliation of a primary resource (your custom resource)
34
-
when an Informer receives a new resource?
33
+
Event sources need to trigger the appropriate reconciler, providing the correct primary resource, whenever one of their
34
+
handled secondary resources changes. It is thus core to an event source's role to identify which primary resource (
35
+
usually, your custom resource) is potentially impacted by that change.
35
36
The framework uses [`SecondaryToPrimaryMapper`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/SecondaryToPrimaryMapper.java)
36
-
to determine which primary resource reconciliation to trigger based on the received resource.
37
-
This mapping is typically done using owner references or annotations on the secondary resource,
38
-
though other mapping strategies are possible (as we'll see later).
39
-
40
-
It's important to understand that when a resource triggers reconciliation of a primary resource,
41
-
that resource will naturally be needed during the reconciliation process, so the reconciler must be able to access it.
42
-
Therefore, InformerEventSource maintains a reverse index called [PrimaryToSecondaryIndex](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java),
43
-
which is built based on the results of the `SecondaryToPrimaryMapper`.
37
+
for this purpose. For `InformerEventSources`, which target Kubernetes resources, this mapping is typically done using
38
+
either the owner reference or an annotation on the secondary resource. For external resources, other mechanisms need to
39
+
be used and there are also cases where the default mechanisms provided by the SDK do not work, even for Kubernetes
40
+
resources.
41
+
42
+
However, once the event source has triggered a primary resource reconciliation, the associated reconciler needs to
43
+
access the secondary resources which changes caused the reconciliation. Indeed, the information from the secondary
44
+
resources might be needed during the reconciliation. For that purpose,
45
+
`InformerEventSource` maintains a reverse
46
+
index [PrimaryToSecondaryIndex](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/DefaultPrimaryToSecondaryIndex.java),
47
+
based on the result of the `SecondaryToPrimaryMapper`result.
44
48
45
49
## Unified API for Related Resources
46
50
47
-
To access all related resources for a primary resource, the framework provides a unified API:
To access all related resources for a primary resource, the framework provides an API to access the related
52
+
secondary resources using the `Set<R> getSecondaryResources(Class<R> expectedType)` method of the `Context` object
53
+
provided as part of the `reconcile` method.
52
54
53
-
This method lists all related resources of a specific type, based on the `InformerEventSource`'s`PrimaryToSecondaryIndex`.
54
-
It reads the resources from the Informer's cache using this index. Since these operations work
55
-
directly with indexes, they are very fast—typically O(1) performance.
55
+
For `InformerEventSource`, this will leverage the associated`PrimaryToSecondaryIndex`. Resources are then retrieved
56
+
from the informer's cache. Note that since all those steps work
57
+
on top of indexes, those operations are very fast, usually O(1).
56
58
57
-
While we've focused on InformerEventSource, this pattern works similarly for the broader EventSource concept.
58
-
The [`EventSource`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java#L93)
59
-
interface actually implements the `Set<R> getSecondaryResources(P primary);` method, which is called by the context.
59
+
While we've focused mostly on `InformerEventSource`, this concept can be extended to all `EventSources`, since
0 commit comments