You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
+
345
416
## Other Dependent Resource Features
346
417
347
418
### 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)
0 commit comments