Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eace828

Browse files
csvirimetacosm
andauthoredApr 4, 2023
docs: improved docs on primary to secondary mapper (#1846)
Co-authored-by: Chris Laprun <[email protected]>
1 parent a14ab99 commit eace828

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed
 

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public <P extends HasMetadata> PrimaryToSecondaryMapper<P> getPrimaryToSecondary
8181
*/
8282
boolean followControllerNamespaceChanges();
8383

84+
/**
85+
* Returns the configured {@link SecondaryToPrimaryMapper} which will allow JOSDK to identify
86+
* which secondary resources are associated with a given primary resource in cases where there is
87+
* no explicit reference to the primary resource (e.g. using owner references) in the associated
88+
* secondary resources.
89+
*
90+
* @return the configured {@link SecondaryToPrimaryMapper}
91+
* @see SecondaryToPrimaryMapper for more explanations on when using such a mapper is useful /
92+
* needed
93+
*/
8494
SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper();
8595

8696
Optional<OnAddFilter<R>> onAddFilter();

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/PrimaryToSecondaryMapper.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,28 @@
66
import io.javaoperatorsdk.operator.processing.event.ResourceID;
77

88
/**
9-
* Primary to Secondary mapper only needed in some cases, typically when there is many-to-one or
10-
* many-to-many relation between primary and secondary resources. If there is owner reference (or
11-
* reference with annotations) from secondary to primary this is not needed. See
12-
* PrimaryToSecondaryIT integration tests that handles many-to-many relationship.
9+
* Identifies the set of secondary resources associated with a given primary resource. This is
10+
* typically needed when multiple secondary resources can be associated with one or several multiple
11+
* primary resources *without* a standard way (e.g. owner reference or annotations) to materialize
12+
* that relations. When owner references are present, a {@code PrimaryToSecondaryMapper} instance
13+
* should not be needed. In other words, associating such a mapper with your
14+
* {@link io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration} is usually needed
15+
* when your secondary resources are referenced in some way by your primary resource but that this
16+
* link does not exist in the secondary resource information. The mapper implementation instructs
17+
* the SDK on how to find all the secondary resources associated with a given primary resource so
18+
* that this primary resource can properly be reconciled when changes impact the associated
19+
* secondary resources, even though these don't contain any information allowing to make such an
20+
* inference.
21+
* <p/>
22+
* This helps particularly in cases where several secondary resources, listed in some way in the
23+
* primary resource, need to or can be created before the primary resource exists. In that
24+
* situation, attempting to retrieve the associated secondary resources by calling
25+
* {@link io.javaoperatorsdk.operator.api.reconciler.Context#getSecondaryResource(Class)} would fail
26+
* without providing a mapper to tell JOSDK how to retrieve the secondary resources.
27+
* <p/>
28+
* You can see an example of this in action in the <a href=
29+
* "https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primarytosecondary/JobReconciler.java">Reconciler
30+
* for the PrimaryToSecondaryIT</a> integration tests that handles many-to-many relationship.
1331
*
1432
* @param <P> primary resource type
1533
*/

0 commit comments

Comments
 (0)
Please sign in to comment.