Skip to content

Commit b6b4575

Browse files
authored
docs: read only dependent resource dilemma (#1860)
1 parent c90cfd0 commit b6b4575

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

docs/documentation/dependent-resources.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ as a sample.
452452
`getResource()` of the dependent resource or getting the resource from the `EventSource`
453453
itself won't return the just updated resource, in the case where the associated event hasn't
454454
been received from the Kubernetes API. The `KubernetesDependentResource` implementation,
455-
however, addresses this issue so you don't have to worry about it by making sure that it or
455+
however, addresses this issue, so you don't have to worry about it by making sure that it or
456456
the related `InformerEventSource` always return the up-to-date resource.
457457

458458
2. Another feature of `KubernetesDependentResource` is to make sure that if a resource is created or
@@ -468,3 +468,26 @@ as a sample.
468468
to select only the relevant events, see
469469
in [related integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java)
470470
.
471+
472+
## "Read-only" Dependent Resources vs. Event Source
473+
474+
Some secondary resources only exist as input for the reconciliation process and are never
475+
updated *by a controller* (they might, and actually usually do, get updated by users interacting
476+
with the resources directly, however). This might be the case, for example, of a `ConfigMap`that is
477+
used to configure common characteristics of multiple resources in one convenient place.
478+
479+
In such situations, one might wonder whether it makes sense to create a dependent resource in
480+
this case or simply use an `EventSource` so that the primary resource gets reconciled whenever a
481+
user changes the resource. Typical dependent resources provide a desired state that the
482+
reconciliation process attempts to match. In the case of so-called read-only dependents, though,
483+
there is no such desired state because the operator / controller will never update the resource
484+
itself, just react to external changes to it. An `EventSource` would achieve the same result.
485+
486+
Using a dependent resource for that purpose instead of a simple `EventSource`, however, provides
487+
several benefits:
488+
- dependents can be created declaratively, while an event source would need to be manually created
489+
- if dependents are already used in a controller, it makes sense to unify the handling of all
490+
secondary resources as dependents from a code organization perspective
491+
- dependent resources can also interact with the workflow feature, thus allowing the read-only
492+
resource to participate in conditions, in particular to decide whether or not the primary
493+
resource needs/can be reconciled using reconcile pre-conditions

0 commit comments

Comments
 (0)