Skip to content

Commit 15287e3

Browse files
committed
docs: new dependent resource features (#1580)
1 parent 317712d commit 15287e3

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

docs/documentation/dependent-resources.md

+71
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,77 @@ See sample in one of the integration
342342
tests [here](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/DependentPrimaryIndexerTestReconciler.java#L25-L25)
343343
.
344344

345+
## Multiple Dependent Resources of Same Type
346+
347+
In case there are multiple dependent resource of same type, the dependent resource implementation needs to know which
348+
resource is it related to, since there will be multiple instances also in caches.
349+
For that it should have a [resource discriminator](https://github.com/java-operator-sdk/java-operator-sdk/blob/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceDiscriminator.java)
350+
. Where resource discriminator uniquely identifies the target resource of a dependent resource. For managed
351+
Kubernetes dependent resource the annotation can be used to set a discriminator:
352+
353+
```
354+
@KubernetesDependent(resourceDiscriminator = ConfigMap1Discriminator.class)
355+
public class MultipleManagedDependentResourceConfigMap1 {
356+
//...
357+
}
358+
```
359+
360+
Dependent resources has the capability to provide event sources. In case there are multiple dependent of the same type
361+
either the provided event sources should track different resources (in other words the tracked resources by different
362+
event sources should be distinct) or should share a common dependent resource.
363+
364+
To use a dedicated event source defined in a `EventSourceInitializer` use its name to set it for a dependent resource
365+
to be used:
366+
```
367+
@Dependent(type = MultipleManagedDependentResourceConfigMap1.class,
368+
useEventSourceWithName = CONFIG_MAP_EVENT_SOURCE),
369+
```
370+
371+
A sample is provided as an integration test both for [managed](/home/csviri/Workspace/java-operator-sdk/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleManagedDependentSameTypeIT.java)
372+
and for [standalone mode](https://github.com/java-operator-sdk/java-operator-sdk/blob/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework/src/test/java/io/javaoperatorsdk/operator/MultipleDependentResourceIT.java)
373+
374+
## Bulk Dependent Resources
375+
376+
There are cases when the number of certain resource type changes dynamically for example based on spec of
377+
the custom resource. These cases are covered by bulk custom resources. To have a resource in "bulk mode" it should
378+
extend the same base classes as other resources, thus `AbstractDependentResource` and it's subclasses and in addition
379+
to that implement the [`BulkDependetResource`](https://github.com/java-operator-sdk/java-operator-sdk/blob/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java)
380+
interface.
381+
382+
Various examples are provided as [integration tests](https://github.com/java-operator-sdk/java-operator-sdk/tree/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework/src/test/java/io/javaoperatorsdk/operator/bulkdependent)
383+
.
384+
385+
## Dependent Resources with Explicit State
386+
387+
For cases when an external (non-Kubernetes) resource generates an ID during creation and from that point
388+
this resource is addressed using this ID special support is provided. A typical example would a GitHub Pull request,
389+
when created, a new ID is generated for it, and from that time in the URL that ID is used to access the PR.
390+
For these cases those IDs are usually stored in a ConfigMap, Secret or a dedicated CustomResource, and accessed
391+
either during reconciliation or by the event source.
392+
393+
To create a dependent resource that covers such case the [`AbstractExternalDependentResource`](https://github.com/java-operator-sdk/java-operator-sdk/blob/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractExternalDependentResource.java)
394+
needs to be extended and the [`DependentResourceWithExplicitState`](https://github.com/java-operator-sdk/java-operator-sdk/blob/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/DependentResourceWithExplicitState.java)
395+
interface implemented. Note that most of the out-of-the-box dependent resources for external resources, like the
396+
`PollingDependentResource` or the `PerResourcePollingDependentResource` already extends
397+
`AbstractExternalDependentResource`.
398+
399+
See [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateDependentIT.java#L8-L8)
400+
as a sample.
401+
402+
For a better understanding it might be worth to study a [sample implementation](https://github.com/java-operator-sdk/java-operator-sdk/blob/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/externalstate/ExternalStateReconciler.java)
403+
without dependent resources.
404+
405+
See also [docs for managing](/docs/patterns-best-practices#managing-state) state in general.
406+
407+
## Combining Bulk and Explicit State Dependent Resources
408+
409+
The bulk and the and explicit state dependent resource features can be combined. In that case for each external resource
410+
that is created a separate resource with the state will be created too. For example if there are three external resources created
411+
there will be three related config maps (assuming config maps are used), one for each external resource.
412+
413+
See [integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/f5ffcfb6f546d79b4bab04ea503c8bad9d6acce6/operator-framework/src/test/java/io/javaoperatorsdk/operator/ExternalStateBulkIT.java)
414+
as a sample.
415+
345416
## Other Dependent Resource Features
346417

347418
### Caching and Event Handling in [KubernetesDependentResource](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java)

docs/documentation/patterns-best-practices.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ when another reconciliation occurs. While such state could be put in the primary
100100
status sub-resource, this could become quickly difficult to manage if a lot of state needs to be
101101
tracked. It also goes against the best practice that a resource's status should represent the
102102
actual resource state, when its spec represents the desired state. Putting state that doesn't
103-
striclty represent the resource's actual state is therefore discouraged. Instead, it's
103+
strictly represent the resource's actual state is therefore discouraged. Instead, it's
104104
advised to put such state into a separate resource meant for this purpose such as a
105105
Kubernetes Secret or ConfigMap or even a dedicated Custom Resource, which structure can be more
106106
easily validated.

0 commit comments

Comments
 (0)