Skip to content

Commit f523d24

Browse files
csvirimetacosm
authored andcommitted
docs
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 9aee25b commit f523d24

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Diff for: docs/documentation/dependent-resources.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,30 @@ resource which matches the desired state associated with the primary resource. T
400400
state computation already needs to be able to discriminate among multiple related secondary resources to tell JOSDK how
401401
they should be reconciled.
402402

403-
However, it is also possible to be more explicit about how JOSDK should identify the proper secondary resource by using
403+
Note that the mechanism of selecting the target resource can be further tuned by overriding the whole mechanism.
404+
405+
Typically, if some reason it would be a problem to call the `desired` method on when reading the secondary resource
406+
for dependent resources that extends the `KubernetesDependentResource` is enough to override the following method:
407+
408+
```java
409+
protected ResourceID managedSecondaryResourceID(P primary, Context<P> context) {
410+
return ResourceID.fromResource(desired(primary, context)); // can be replaced by a static ResourceID
411+
}
412+
```
413+
414+
and just return the `name` and `namespace` of the target resource.
415+
416+
In general however the whole mechanism can be overridden and optimized. See the related base implementation
417+
in [`AbstractDependetResource`](https://github.com/operator-framework/java-operator-sdk/blob/6cd0f884a7c9b60c81bd2d52da54adbd64d6e118/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java#L126-L136)
418+
419+
See also example of selection for external resource [here](https://github.com/operator-framework/java-operator-sdk/blob/6cd0f884a7c9b60c81bd2d52da54adbd64d6e118/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalWithStateDependentResource.java#L43-L49).
420+
421+
### Resource Discriminators
422+
423+
It is also possible to be more explicit about how JOSDK should identify the proper secondary resource by using
404424
a
405425
[resource discriminator](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceDiscriminator.java)
426+
This is a former approach, that was the default before v5. It is NOT the preferred way anymore.
406427
Resource discriminators uniquely identify the target resource of a dependent resource.
407428
In the managed Kubernetes dependent resources case, the discriminator can be declaratively set
408429
using the `@KubernetesDependent` annotation:

0 commit comments

Comments
 (0)