Skip to content

Commit d0d6874

Browse files
committed
docs
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 6cd0f88 commit d0d6874

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
@@ -394,9 +394,30 @@ resource which matches the desired state associated with the primary resource. T
394394
state computation already needs to be able to discriminate among multiple related secondary resources to tell JOSDK how
395395
they should be reconciled.
396396

397-
However, it is also possible to be more explicit about how JOSDK should identify the proper secondary resource by using
397+
Note that the mechanism of selecting the target resource can be further tuned by overriding the whole mechanism.
398+
399+
Typically, if some reason it would be a problem to call the `desired` method on when reading the secondary resource
400+
for dependent resources that extends the `KubernetesDependentResource` is enough to override the following method:
401+
402+
```java
403+
protected ResourceID managedSecondaryResourceID(P primary, Context<P> context) {
404+
return ResourceID.fromResource(desired(primary, context)); // can be replaced by a static ResourceID
405+
}
406+
```
407+
408+
and just return the `name` and `namespace` of the target resource.
409+
410+
In general however the whole mechanism can be overridden and optimized. See the related base implementation
411+
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)
412+
413+
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).
414+
415+
### Resource Discriminators
416+
417+
It is also possible to be more explicit about how JOSDK should identify the proper secondary resource by using
398418
a
399419
[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)
420+
This is a former approach, that was the default before v5. It is NOT the preferred way anymore.
400421
Resource discriminators uniquely identify the target resource of a dependent resource.
401422
In the managed Kubernetes dependent resources case, the discriminator can be declaratively set
402423
using the `@KubernetesDependent` annotation:

0 commit comments

Comments
 (0)