Skip to content

Commit caa71eb

Browse files
authored
fix: minor fixes (#767)
1 parent 319a76e commit caa71eb

File tree

8 files changed

+38
-55
lines changed

8 files changed

+38
-55
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ObservedGenerationAware.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

77
/**
88
* If the custom resource's status implements this interface, the observed generation will be
9-
* automatically handled. The last observed generation will be updated on status when the status is
10-
* instructed to be updated (see below). In addition to that, controller configuration will be
11-
* checked if is set to generation aware. If generation aware config is turned off, this interface
12-
* is ignored.
13-
*
14-
* In order to work the status object returned by CustomResource.getStatus() should not be null. In
15-
* addition to that from the controller that the {@link UpdateControl#updateStatus(HasMetadata)} or
16-
* {@link UpdateControl#updateResourceAndStatus(HasMetadata)} should be returned. The observed
17-
* generation is not updated in other cases.
18-
*
9+
* automatically handled. The last observed generation will be updated on status. In addition to
10+
* that, controller configuration will be checked if is set to be generation aware. If generation
11+
* aware config is turned off, this interface is ignored.
12+
* <p>
13+
* In order for this automatic handling to work the status object returned by
14+
* {@link CustomResource#getStatus()} should not be null.
15+
* <p>
16+
* The observed generation is updated even when {@link UpdateControl#noUpdate()} or
17+
* {@link UpdateControl#updateResource(HasMetadata)} is called. Although those results call normally
18+
* does not result in a status update, there will be a subsequent status update Kubernetes API call
19+
* in this case.
20+
*
1921
* @see ObservedGenerationAwareStatus
2022
*/
2123
public interface ObservedGenerationAware {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public interface ErrorStatusHandler<T extends HasMetadata> {
88

99
/**
1010
* <p>
11-
* Reconcile can implement this interface in order to update the status sub-resource in the case
12-
* when the last reconciliation retry attempt is failed on the Reconciler. In that case the
13-
* updateErrorStatus is called automatically.
11+
* Reconciler can implement this interface in order to update the status sub-resource in the case
12+
* an exception in thrown. In that case
13+
* {@link #updateErrorStatus(HasMetadata, RetryInfo, RuntimeException)} is called automatically.
1414
* <p>
1515
* The result of the method call is used to make a status update on the custom resource. This is
1616
* always a sub-resource update request, so no update on custom resource itself (like spec of

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,30 @@
55
public interface Reconciler<R extends HasMetadata> {
66

77
/**
8-
* Note that this method is used in combination of finalizers. If automatic finalizer handling is
9-
* turned off for the controller, this method is not called.
8+
* The implementation of this operation is required to be idempotent. Always use the UpdateControl
9+
* object to make updates on custom resource if possible.
10+
*
11+
* @param resource the resource that has been created or updated
12+
* @param context the context with which the operation is executed
13+
* @return UpdateControl to manage updates on the custom resource (usually the status) after
14+
* reconciliation.
15+
*/
16+
UpdateControl<R> reconcile(R resource, Context context);
17+
18+
/**
19+
* Note that this method is used in combination with finalizers. If automatic finalizer handling
20+
* is turned off for the controller, this method is not called.
1021
*
11-
* The implementation should delete the associated component(s). Note that this is method is
12-
* called when an object is marked for deletion. After it's executed the custom resource finalizer
13-
* is automatically removed by the framework; unless the return value is
22+
* The implementation should delete the associated component(s). This method is called when an
23+
* object is marked for deletion. After it's executed the custom resource finalizer is
24+
* automatically removed by the framework; unless the return value is
1425
* {@link DeleteControl#noFinalizerRemoval()}, which indicates that the controller has determined
1526
* that the resource should not be deleted yet. This is usually a corner case, when a cleanup is
1627
* tried again eventually.
1728
*
1829
* <p>
19-
* It's important that this method be idempotent, as it could be called several times, depending
20-
* on the conditions and the controller's configuration (for example, if the controller is
21-
* configured to not use a finalizer but the resource does have finalizers, it might be be
22-
* "offered" again for deletion several times until the finalizers are all removed.
30+
* It's important for implementations of this method to be idempotent, since it can be called
31+
* several times.
2332
*
2433
* @param resource the resource that is marked for deletion
2534
* @param context the context with which the operation is executed
@@ -32,20 +41,4 @@ default DeleteControl cleanup(R resource, Context context) {
3241
return DeleteControl.defaultDelete();
3342
}
3443

35-
/**
36-
* The implementation of this operation is required to be idempotent. Always use the UpdateControl
37-
* object to make updates on custom resource if possible. Also always use the custom resource
38-
* parameter (not the custom resource that might be in the events)
39-
*
40-
* @param resource the resource that has been created or updated
41-
* @param context the context with which the operation is executed
42-
* @return The resource is updated in api server if the return value is not
43-
* {@link UpdateControl#noUpdate()}. This the common use cases. However in cases, for
44-
* example the operator is restarted, and we don't want to have an update call to k8s api
45-
* to be made unnecessarily, by returning {@link UpdateControl#noUpdate()} this update can
46-
* be skipped. <b>However we will always call an update if there is no finalizer on object
47-
* and it's not marked for deletion.</b>
48-
*/
49-
UpdateControl<R> reconcile(R resource, Context context);
50-
5144
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getName;
3232
import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion;
3333

34-
/**
35-
* Event handler that makes sure that events are processed in a "single threaded" way per resource
36-
* UID, while buffering events which are received during an execution.
37-
*/
3834
class EventProcessor<R extends HasMetadata> implements EventHandler, LifecycleAware {
3935

4036
private static final Logger log = LoggerFactory.getLogger(EventProcessor.class);

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ private PostExecutionControl<R> handleDispatch(ExecutionScope<R> executionScope)
8787
private boolean shouldNotDispatchToDelete(R resource) {
8888
// we don't dispatch to delete if the controller is configured to use a finalizer but that
8989
// finalizer is not present (which means it's already been removed)
90-
return configuration().useFinalizer() && !resource.hasFinalizer(configuration().getFinalizer());
90+
return !configuration().useFinalizer() || (configuration().useFinalizer()
91+
&& !resource.hasFinalizer(configuration().getFinalizer()));
9192
}
9293

9394
private PostExecutionControl<R> handleReconcile(

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSource.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getUID;
2727
import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getVersion;
2828

29-
/**
30-
* This is a special case since is not bound to a single custom resource
31-
*/
3229
public class ControllerResourceEventSource<T extends HasMetadata> extends AbstractEventSource
3330
implements ResourceEventHandler<T> {
3431

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/RetryExecution.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
public interface RetryExecution extends RetryInfo {
88

99
/**
10-
* Calculates the delay for the next execution. This method should return 0, when called first
11-
* time;
12-
*
13-
* @return the time to wait until the next execution in millisecondsz
10+
* @return the time to wait until the next execution in milliseconds
1411
*/
1512
Optional<Long> nextDelay();
1613
}

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcherTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,14 @@ void callsDeleteIfObjectHasFinalizerAndMarkedForDelete() {
139139
verify(reconciler, times(1)).cleanup(eq(testCustomResource), any());
140140
}
141141

142-
/**
143-
* Note that there could be more finalizers. Out of our control.
144-
*/
145142
@Test
146-
void callDeleteOnControllerIfMarkedForDeletionWhenNoFinalizerIsConfigured() {
143+
void doesNotCallDeleteOnControllerIfMarkedForDeletionWhenNoFinalizerIsConfigured() {
147144
configureToNotUseFinalizer();
148145
markForDeletion(testCustomResource);
149146

150147
reconciliationDispatcher.handleExecution(executionScopeWithCREvent(testCustomResource));
151148

152-
verify(reconciler).cleanup(eq(testCustomResource), any());
149+
verify(reconciler, times(0)).cleanup(eq(testCustomResource), any());
153150
}
154151

155152
@Test

0 commit comments

Comments
 (0)