Skip to content

Commit dbba885

Browse files
committed
docs: dependent resources and other improvements
1 parent 94f0b75 commit dbba885

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

docs/documentation/dependent-resources.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,39 @@ JOSDK will take the appropriate steps to wire everything together and call your
111111
This makes sense in most use cases where the logic associated with the primary resource is usually
112112
limited to status handling based on the state of the secondary resources. This behavior and
113113
automated handling is referred to as "managed" because the `DependentResource`
114-
implementations are managed by JOSDK.
114+
implementations are managed by JOSDK. See related sample:
115+
116+
```java
117+
118+
@ControllerConfiguration(
119+
labelSelector = SELECTOR,
120+
dependents = {
121+
@Dependent(type = ConfigMapDependentResource.class),
122+
@Dependent(type = DeploymentDependentResource.class),
123+
@Dependent(type = ServiceDependentResource.class)
124+
})
125+
public class WebPageManagedDependentsReconciler
126+
implements Reconciler<WebPage>, ErrorStatusHandler<WebPage> {
127+
128+
// emitted code
129+
130+
@Override
131+
public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> context)
132+
throws Exception {
133+
simulateErrorIfRequested(webPage);
134+
135+
final var name = context.getSecondaryResource(ConfigMap.class).orElseThrow()
136+
.getMetadata().getName();
137+
webPage.setStatus(createStatus(name));
138+
return UpdateControl.updateStatus(webPage);
139+
}
140+
141+
}
142+
```
143+
115144

116145
## Standalone Dependent Resources
117146

147+
148+
118149
## Other Dependent Resources features

docs/documentation/features.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ execution.
3737
[Kubernetes finalizers](https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/)
3838
make sure that a reconciliation happens when a custom resource is instructed to be deleted. Typical case when it's
3939
useful, when an operator is down (pod not running). Without a finalizer the reconciliation - thus the cleanup -
40-
i.e. [`Cleaner.cleanup(...)`](https://github.com/java-operator-sdk/java-operator-sdk/blob/b82c1f106968cb3eb18835c5e9cd1e4d5c40362e/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java#L28-L28)
40+
i.e. [`Cleaner.cleanup(...)`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java#L28)
4141
would not happen if a custom resource is deleted.
4242

43-
To use finalizers the reconciler have to implement [`Cleaner<P>`](https://github.com/java-operator-sdk/java-operator-sdk/blob/b82c1f106968cb3eb18835c5e9cd1e4d5c40362e/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java) interface.
44-
In other words, finalizer is added if the `Reconciler` implements `Cleaner` interface. If not, no
43+
To use finalizers the reconciler have to implement [`Cleaner<P>`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java) interface.
44+
In other words, finalizer is added only if the `Reconciler` implements `Cleaner` interface. If not, no
4545
finalizer is added and/or removed.
4646

4747
Finalizers are automatically added by the framework as the first step, thus after a custom resource is created, but
@@ -69,7 +69,7 @@ When automatic finalizer handling is turned off, the `Reconciler.cleanup(...)` m
6969
case when a delete event received. So it does not make sense to implement this method and turn off finalizer at the same
7070
time.
7171

72-
## The `reconcile` and [`cleanup`](https://github.com/java-operator-sdk/java-operator-sdk/blob/b82c1f106968cb3eb18835c5e9cd1e4d5c40362e/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java) Methods on a [`Reconciler`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java)
72+
## The [`reconcile`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java#L16) and [`cleanup`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java#L28)
7373

7474
The lifecycle of a custom resource can be clearly separated into two phases from the perspective of an operator. When a
7575
custom resource is created or update, or on the other hand when the custom resource is deleted - or rather marked for
@@ -160,7 +160,7 @@ In order to have this feature working:
160160
If these conditions are fulfilled and generation awareness not turned off, the observed generation is automatically set
161161
by the framework after the `reconcile` method is called. Note that the observed generation is updated also
162162
when `UpdateControl.noUpdate()` is returned from the reconciler. See this feature working in
163-
the [WebPage example](https://github.com/java-operator-sdk/java-operator-sdk/blob/b91221bb54af19761a617bf18eef381e8ceb3b4c/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStatus.java#L5)
163+
the [WebPage example](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageStatus.java#L5)
164164
.
165165

166166
```java
@@ -361,7 +361,7 @@ of requests to Kubernetes API server, and leads to faster reconciliation cycles.
361361
Note that when an operator starts and the first reconciliation is executed the caches are already populated for example
362362
for `InformerEventSource`. Currently, this is not true however for `PerResourceEventSource`, where the cache might or
363363
might not be populated. To handle this situation elegantly methods are provided which checks the object in cache, if
364-
not found tries to get it from the supplier. See related [method](https://github.com/java-operator-sdk/java-operator-sdk/blob/e7fd79968a238d7e0acc446d949b83a06cea17b5/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java#L145)
364+
not found tries to get it from the supplier. See related [method](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java#L146)
365365
.
366366

367367
### Registering Event Sources

0 commit comments

Comments
 (0)