From 9a9a59e63b9e7d545a23670c2bba3dc33d4b7c94 Mon Sep 17 00:00:00 2001 From: csviri Date: Tue, 18 Apr 2023 11:02:15 +0200 Subject: [PATCH 1/2] docs: read only dependnet resource dilemma --- docs/documentation/dependent-resources.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/documentation/dependent-resources.md b/docs/documentation/dependent-resources.md index 85aebc66e4..9d0c39c72d 100644 --- a/docs/documentation/dependent-resources.md +++ b/docs/documentation/dependent-resources.md @@ -452,7 +452,7 @@ as a sample. `getResource()` of the dependent resource or getting the resource from the `EventSource` itself won't return the just updated resource, in the case where the associated event hasn't been received from the Kubernetes API. The `KubernetesDependentResource` implementation, - however, addresses this issue so you don't have to worry about it by making sure that it or + however, addresses this issue, so you don't have to worry about it by making sure that it or the related `InformerEventSource` always return the up-to-date resource. 2. Another feature of `KubernetesDependentResource` is to make sure that if a resource is created or @@ -468,3 +468,16 @@ as a sample. to select only the relevant events, see 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) . + +## Read-only Dependent Resources? + +It can happen that a resource is just read-only, thus it serves just as an input for the reconciliation, +like a config map to configure common characteristics for multiple custom resources in one place. +It is up to the debate if it is useful to create a dependent resource in this case. Dependent resources +helps with a reconciliation, thus making sure that a target resource in the desired state, in this case +however there is no desired state. As an alternative it might be enough just to register an event source +for such resources. + +On the other hand it might be useful to have a read-only dependent from the Workflows perspective, to add +conditions on for a reconciliation. Thus, for example to reconcile a dependent resource which depends on +a read-only dependent resource only if some reconcile pre-condition holds on the read-only resource. \ No newline at end of file From 82c493d6c16e1d60f9ee216ef516115e4303d808 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Mon, 24 Apr 2023 12:43:19 +0200 Subject: [PATCH 2/2] docs: add more details --- docs/documentation/dependent-resources.md | 34 +++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/docs/documentation/dependent-resources.md b/docs/documentation/dependent-resources.md index 9d0c39c72d..b82fc8e7e7 100644 --- a/docs/documentation/dependent-resources.md +++ b/docs/documentation/dependent-resources.md @@ -469,15 +469,25 @@ as a sample. 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) . -## Read-only Dependent Resources? - -It can happen that a resource is just read-only, thus it serves just as an input for the reconciliation, -like a config map to configure common characteristics for multiple custom resources in one place. -It is up to the debate if it is useful to create a dependent resource in this case. Dependent resources -helps with a reconciliation, thus making sure that a target resource in the desired state, in this case -however there is no desired state. As an alternative it might be enough just to register an event source -for such resources. - -On the other hand it might be useful to have a read-only dependent from the Workflows perspective, to add -conditions on for a reconciliation. Thus, for example to reconcile a dependent resource which depends on -a read-only dependent resource only if some reconcile pre-condition holds on the read-only resource. \ No newline at end of file +## "Read-only" Dependent Resources vs. Event Source + +Some secondary resources only exist as input for the reconciliation process and are never +updated *by a controller* (they might, and actually usually do, get updated by users interacting +with the resources directly, however). This might be the case, for example, of a `ConfigMap`that is +used to configure common characteristics of multiple resources in one convenient place. + +In such situations, one might wonder whether it makes sense to create a dependent resource in +this case or simply use an `EventSource` so that the primary resource gets reconciled whenever a +user changes the resource. Typical dependent resources provide a desired state that the +reconciliation process attempts to match. In the case of so-called read-only dependents, though, +there is no such desired state because the operator / controller will never update the resource +itself, just react to external changes to it. An `EventSource` would achieve the same result. + +Using a dependent resource for that purpose instead of a simple `EventSource`, however, provides +several benefits: +- dependents can be created declaratively, while an event source would need to be manually created +- if dependents are already used in a controller, it makes sense to unify the handling of all + secondary resources as dependents from a code organization perspective +- dependent resources can also interact with the workflow feature, thus allowing the read-only + resource to participate in conditions, in particular to decide whether or not the primary + resource needs/can be reconciled using reconcile pre-conditions \ No newline at end of file