diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java index 12f392901d..7eb7d2ae84 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java @@ -8,17 +8,17 @@ public class UpdateControl

extends BaseControl custom resource type * @param customResource customResource to use for update * @return initialized update control @@ -73,6 +76,9 @@ public static UpdateControl updateStatus(T customReso * As a results of this there will be two call to K8S API. First the custom resource will be * updates then the status sub-resource. * + * Using this update makes sure that the resource in the next reconciliation is the updated one - + * this is not guaranteed by default if you do an update on a resource by the Kubernetes client. + * * @param resource type * @param customResource - custom resource to use in both API calls * @return UpdateControl instance @@ -82,11 +88,36 @@ public static UpdateControl updateResourceAndStatus( return new UpdateControl<>(customResource, true, true, false); } - public static UpdateControl patchResourceAndStatus( + /** + * Updates the resource - with optimistic locking - and patches the status without optimistic + * locking in place. + * + * Note that using this method, it is not guaranteed that the most recent updated resource will be + * in case for next reconciliation. + * + * @param customResource to update + * @return UpdateControl instance + * @param resource type + */ + public static UpdateControl updateResourceAndPatchStatus( T customResource) { return new UpdateControl<>(customResource, true, true, true); } + /** + * Marked for removal, because of confusing name. It does not patch the resource but rather + * updates it. + * + * @deprecated use {@link UpdateControl#updateResourceAndPatchStatus(HasMetadata)} + * + * @param customResource to update + * @return UpdateControl instance + * @param resource type + */ + @Deprecated(forRemoval = true) + public static UpdateControl patchResourceAndStatus(T customResource) { + return updateResourceAndStatus(customResource); + } public static UpdateControl noUpdate() { return new UpdateControl<>(null, false, false, false); @@ -104,8 +135,8 @@ public boolean isUpdateResource() { return updateResource; } - public boolean isPatch() { - return patch; + public boolean isPatchStatus() { + return patchStatus; } public boolean isNoUpdate() { @@ -115,4 +146,5 @@ public boolean isNoUpdate() { public boolean isUpdateResourceAndStatus() { return updateResource && updateStatus; } + } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java index 3018ed30f1..6c7e7bc9e7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java @@ -84,7 +84,7 @@ private PostExecutionControl

handleDispatch(ExecutionScope

executionScope) Context

context = new DefaultContext<>(executionScope.getRetryInfo(), controller, originalResource); if (markedForDeletion) { - return handleCleanup(originalResource, resourceForExecution, context); + return handleCleanup(resourceForExecution, context); } else { return handleReconcile(executionScope, resourceForExecution, originalResource, context); } @@ -147,23 +147,24 @@ private PostExecutionControl

reconcileExecution(ExecutionScope

executionSc .setResourceVersion(updatedCustomResource.getMetadata().getResourceVersion()); updatedCustomResource = updateStatusGenerationAware(updateControl.getResource(), originalResource, - updateControl.isPatch()); + updateControl.isPatchStatus()); } else if (updateControl.isUpdateStatus()) { updatedCustomResource = updateStatusGenerationAware(updateControl.getResource(), originalResource, - updateControl.isPatch()); + updateControl.isPatchStatus()); } else if (updateControl.isUpdateResource()) { updatedCustomResource = updateCustomResource(updateControl.getResource()); if (shouldUpdateObservedGenerationAutomatically(updatedCustomResource)) { updatedCustomResource = updateStatusGenerationAware(updateControl.getResource(), originalResource, - updateControl.isPatch()); + updateControl.isPatchStatus()); } } else if (updateControl.isNoUpdate() && shouldUpdateObservedGenerationAutomatically(resourceForExecution)) { updatedCustomResource = - updateStatusGenerationAware(originalResource, originalResource, updateControl.isPatch()); + updateStatusGenerationAware(originalResource, originalResource, + updateControl.isPatchStatus()); } return createPostExecutionControl(updatedCustomResource, updateControl); } @@ -259,7 +260,7 @@ private PostExecutionControl

createPostExecutionControl(P updatedCustomResour UpdateControl

updateControl) { PostExecutionControl

postExecutionControl; if (updatedCustomResource != null) { - if (updateControl.isUpdateStatus() && updateControl.isPatch()) { + if (updateControl.isUpdateStatus() && updateControl.isPatchStatus()) { postExecutionControl = PostExecutionControl.customResourceStatusPatched(updatedCustomResource); } else { @@ -279,7 +280,7 @@ private void updatePostExecutionControlWithReschedule( } - private PostExecutionControl

handleCleanup(P originalResource, P resource, + private PostExecutionControl

handleCleanup(P resource, Context

context) { log.debug( "Executing delete for resource: {} with version: {}", @@ -317,8 +318,10 @@ private P updateCustomResourceWithFinalizer(P resourceForExecution, P originalRe } private P updateCustomResource(P resource) { - log.debug("Updating resource: {} with version: {}", getUID(resource), getVersion(resource)); + log.debug("Updating resource: {} with version: {}", getUID(resource), + getVersion(resource)); log.trace("Resource before update: {}", resource); + return customResourceFacade.updateResource(resource); }