Skip to content

Commit d0ed7fa

Browse files
committed
add meatcosm changes
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 31a590c commit d0ed7fa

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

docs/content/en/docs/documentation/access-resources.md renamed to docs/content/en/docs/documentation/working-with-es-caches.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
---
2-
title: Accessing resources in caches
2+
title: Working with EventSource caches
33
weight: 48
44
---
55

66
As described in [Event sources and related topics](eventing.md), event sources serve as the backbone
77
for caching resources and triggering reconciliation for primary resources that are related
8-
to cached resources.
8+
to these secondary resources.
99

1010
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.
1313

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,
1515
allowing you to cache external resources and trigger reconciliation when those resources change.
1616

1717
## The InformerEventSource
1818

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).
2020
[InformerEventSource](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java)
21-
in Java Operator SDK wraps the fabric8 client informers.
21+
in Java Operator SDK wraps the Fabric8 client informers.
2222
This wrapper adds additional capabilities specifically required for controllers
2323
(note that informers have broader applications beyond just implementing controllers).
2424

@@ -30,40 +30,43 @@ These additional capabilities include:
3030

3131
### Associating Secondary Resources to Primary Resource
3232

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.
3536
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.
4448

4549
## Unified API for Related Resources
4650

47-
To access all related resources for a primary resource, the framework provides a unified API:
48-
49-
```java
50-
Context.getSecondaryResources(Class<R> expectedType);
51-
```
51+
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.
5254

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).
5658

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
60+
[`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)
61+
actually implements the `Set<R> getSecondaryResources(P primary)` method that can be called from the `Context`.
6062

61-
The implementation is slightly more complex when multiple event sources exist for the same resource type—
62-
in such cases, the union of all results is returned.
63+
As there can be multiple event sources for the same resource types, things are a little more complex: the union of each
64+
event source results is returned.
6365

6466
## Getting Resources Directly from Event Sources
6567

66-
You can also directly access resources in the cache (not just through `getSecondaryResources(...)`):
68+
Note that nothing prevents you from directly accessing resources in the cache without going through
69+
`getSecondaryResources(...)`:
6770

6871
```java
6972
public class WebPageReconciler implements Reconciler<WebPage> {

0 commit comments

Comments
 (0)