diff --git a/docs/content/en/docs/documentation/reconciler.md b/docs/content/en/docs/documentation/reconciler.md index b9ede8aa95..362de38a03 100644 --- a/docs/content/en/docs/documentation/reconciler.md +++ b/docs/content/en/docs/documentation/reconciler.md @@ -201,7 +201,7 @@ public UpdateControl reconcile( var freshCopy = createFreshCopy(primary); freshCopy.getStatus().setValue(statusWithState()); - var updatedResource = PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatus(resource, freshCopy, context); + var updatedResource = PrimaryUpdateAndCacheUtils.ssaPatchStatusAndCacheResource(resource, freshCopy, context); return UpdateControl.noUpdate(); } @@ -247,7 +247,7 @@ needs to be set to `false` you can use an explicit caching approach: freshCopy.getStatus().setValue(statusWithState()); var updated = - PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatus(primary, freshCopy, context, cache); + PrimaryUpdateAndCacheUtils.ssaPatchStatusAndCacheResource(primary, freshCopy, context, cache); return UpdateControl.noUpdate(); } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java index 174f7667f6..d1c210dd1a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java @@ -25,53 +25,56 @@ private PrimaryUpdateAndCacheUtils() {} private static final Logger log = LoggerFactory.getLogger(PrimaryUpdateAndCacheUtils.class); /** - * Makes sure that the up-to-date primary resource will be present during the next reconciliation. - * Using update (PUT) method. + * Updates status and makes sure that the up-to-date primary resource will be present during the + * next reconciliation. Using update (PUT) method. * * @param primary resource * @param context of reconciliation * @return updated resource * @param

primary resource type */ - public static

P updateAndCacheStatus(P primary, Context

context) { + public static

P updateStatusAndCacheResource( + P primary, Context

context) { logWarnIfResourceVersionPresent(primary); - return patchAndCacheStatus( + return patchStatusAndCacheResource( primary, context, () -> context.getClient().resource(primary).updateStatus()); } /** - * Makes sure that the up-to-date primary resource will be present during the next reconciliation. - * Using JSON Merge patch. + * Patches status with and makes sure that the up-to-date primary resource will be present during + * the next reconciliation. Using JSON Merge patch. * * @param primary resource * @param context of reconciliation * @return updated resource * @param

primary resource type */ - public static

P patchAndCacheStatus(P primary, Context

context) { + public static

P patchStatusAndCacheResource( + P primary, Context

context) { logWarnIfResourceVersionPresent(primary); - return patchAndCacheStatus( + return patchStatusAndCacheResource( primary, context, () -> context.getClient().resource(primary).patchStatus()); } /** - * Makes sure that the up-to-date primary resource will be present during the next reconciliation. - * Using JSON Patch. + * Patches status and makes sure that the up-to-date primary resource will be present during the + * next reconciliation. Using JSON Patch. * * @param primary resource * @param context of reconciliation * @return updated resource * @param

primary resource type */ - public static

P editAndCacheStatus( + public static

P editStatusAndCacheResource( P primary, Context

context, UnaryOperator

operation) { logWarnIfResourceVersionPresent(primary); - return patchAndCacheStatus( + return patchStatusAndCacheResource( primary, context, () -> context.getClient().resource(primary).editStatus(operation)); } /** - * Makes sure that the up-to-date primary resource will be present during the next reconciliation. + * Patches the resource with supplied method and makes sure that the up-to-date primary resource + * will be present during the next reconciliation. * * @param primary resource * @param context of reconciliation @@ -79,7 +82,7 @@ public static

P editAndCacheStatus( * @return the updated resource. * @param

primary resource type */ - public static

P patchAndCacheStatus( + public static

P patchStatusAndCacheResource( P primary, Context

context, Supplier

patch) { var updatedResource = patch.get(); context @@ -90,8 +93,8 @@ public static

P patchAndCacheStatus( } /** - * Makes sure that the up-to-date primary resource will be present during the next reconciliation. - * Using Server Side Apply. + * Patches status and makes sure that the up-to-date primary resource will be present during the + * next reconciliation. Using Server Side Apply. * * @param primary resource * @param freshResourceWithStatus - fresh resource with target state @@ -99,7 +102,7 @@ public static

P patchAndCacheStatus( * @return the updated resource. * @param

primary resource type */ - public static

P ssaPatchAndCacheStatus( + public static

P ssaPatchStatusAndCacheResource( P primary, P freshResourceWithStatus, Context

context) { logWarnIfResourceVersionPresent(freshResourceWithStatus); var res = @@ -122,7 +125,8 @@ public static

P ssaPatchAndCacheStatus( } /** - * Patches the resource and adds it to the {@link PrimaryResourceCache}. + * Patches the resource status and caches the response in provided {@link PrimaryResourceCache}. + * Uses Server Side Apply. * * @param primary resource * @param freshResourceWithStatus - fresh resource with target state @@ -131,10 +135,10 @@ public static

P ssaPatchAndCacheStatus( * @return the updated resource. * @param

primary resource type */ - public static

P ssaPatchAndCacheStatus( + public static

P ssaPatchStatusAndCacheResource( P primary, P freshResourceWithStatus, Context

context, PrimaryResourceCache

cache) { logWarnIfResourceVersionPresent(freshResourceWithStatus); - return patchAndCacheStatus( + return patchStatusAndCacheResource( primary, cache, () -> @@ -151,7 +155,8 @@ public static

P ssaPatchAndCacheStatus( } /** - * Patches the resource with JSON Patch and adds it to the {@link PrimaryResourceCache}. + * Patches the resource with JSON Patch and caches the response in provided {@link + * PrimaryResourceCache}. * * @param primary resource * @param context of reconciliation @@ -159,16 +164,16 @@ public static

P ssaPatchAndCacheStatus( * @return the updated resource. * @param

primary resource type */ - public static

P editAndCacheStatus( + public static

P editStatusAndCacheResource( P primary, Context

context, PrimaryResourceCache

cache, UnaryOperator

operation) { logWarnIfResourceVersionPresent(primary); - return patchAndCacheStatus( + return patchStatusAndCacheResource( primary, cache, () -> context.getClient().resource(primary).editStatus(operation)); } /** - * Patches the resource with JSON Merge patch and adds it to the {@link PrimaryResourceCache} - * provided. + * Patches the resource status with JSON Merge patch and caches the response in provided {@link + * PrimaryResourceCache} * * @param primary resource * @param context of reconciliation @@ -176,15 +181,15 @@ public static

P editAndCacheStatus( * @return the updated resource. * @param

primary resource type */ - public static

P patchAndCacheStatus( + public static

P patchStatusAndCacheResource( P primary, Context

context, PrimaryResourceCache

cache) { logWarnIfResourceVersionPresent(primary); - return patchAndCacheStatus( + return patchStatusAndCacheResource( primary, cache, () -> context.getClient().resource(primary).patchStatus()); } /** - * Updates the resource and adds it to the {@link PrimaryResourceCache}. + * Updates the resource status and caches the response in provided {@link PrimaryResourceCache}. * * @param primary resource * @param context of reconciliation @@ -192,15 +197,16 @@ public static

P patchAndCacheStatus( * @return the updated resource. * @param

primary resource type */ - public static

P updateAndCacheStatus( + public static

P updateStatusAndCacheResource( P primary, Context

context, PrimaryResourceCache

cache) { logWarnIfResourceVersionPresent(primary); - return patchAndCacheStatus( + return patchStatusAndCacheResource( primary, cache, () -> context.getClient().resource(primary).updateStatus()); } /** - * Updates the resource using the user provided implementation anc caches the result. + * Updates the resource using the user provided implementation and caches the response in provided + * {@link PrimaryResourceCache}. * * @param primary resource * @param cache resource cache managed by user @@ -208,7 +214,7 @@ public static

P updateAndCacheStatus( * @return the updated resource. * @param

primary resource type */ - public static

P patchAndCacheStatus( + public static

P patchStatusAndCacheResource( P primary, PrimaryResourceCache

cache, Supplier

patch) { var updatedResource = patch.get(); cache.cacheResource(primary, updatedResource); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheReconciler.java index 8a3a72a901..a62d0c5b18 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheReconciler.java @@ -37,7 +37,8 @@ public UpdateControl reconcile( .getStatus() .setValue(resource.getStatus() == null ? 1 : resource.getStatus().getValue() + 1); - var updated = PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatus(resource, freshCopy, context); + var updated = + PrimaryUpdateAndCacheUtils.ssaPatchStatusAndCacheResource(resource, freshCopy, context); latestValue = updated.getStatus().getValue(); return UpdateControl.noUpdate(); diff --git a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/primarycache/StatusPatchPrimaryCacheReconciler.java b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/primarycache/StatusPatchPrimaryCacheReconciler.java index c25fcddfec..b03424441f 100644 --- a/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/primarycache/StatusPatchPrimaryCacheReconciler.java +++ b/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/primarycache/StatusPatchPrimaryCacheReconciler.java @@ -52,7 +52,8 @@ public UpdateControl reconcile( .setValue(primary.getStatus() == null ? 1 : primary.getStatus().getValue() + 1); var updated = - PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatus(primary, freshCopy, context, cache); + PrimaryUpdateAndCacheUtils.ssaPatchStatusAndCacheResource( + primary, freshCopy, context, cache); latestValue = updated.getStatus().getValue(); return UpdateControl.noUpdate();