From d4f431ddf7f808a4dfcc66c7701820d375b0b128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 17 Sep 2025 13:26:51 +0200 Subject: [PATCH 1/2] feat: experimental utility methods to add finalizer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../PrimaryUpdateAndCacheUtils.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) 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 c61cc837c1..e8eed3535e 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 @@ -229,4 +229,62 @@ private static

P pollLocalCache( throw new OperatorException(e); } } + + /** + * Experimental. Patches finalizer. For retry uses informer cache to get the fresh resources, + * therefore makes less Kubernetes API Calls. + */ + @Experimental( + "Not used internally for now. Therefor we don't consider it well tested. But the intention is" + + " to have it as default in the future.") + public static

P addFinalizer( + P resource, String finalizer, Context

context) { + + if (resource.hasFinalizer(finalizer)) { + log.debug("Skipping adding finalizer, since already present."); + return resource; + } + + return updateAndCacheResource( + resource, + context, + r -> r, + r -> + context + .getClient() + .resource(r) + .edit( + res -> { + res.addFinalizer(finalizer); + return res; + })); + } + + /** + * Experimental. Removes finalizer, for retry uses informer cache to get the fresh resources, + * therefore makes less Kubernetes API Calls. + */ + @Experimental( + "Not used internally for now. Therefor we don't consider it well tested. But the intention is" + + " to have it as default in the future.") + public static

P removeFinalizer( + P resource, String finalizer, Context

context) { + if (!resource.hasFinalizer(finalizer)) { + log.debug("Skipping removing finalizer, since not present."); + return resource; + } + return updateAndCacheResource( + resource, + context, + r -> r, + r -> + context + .getClient() + .resource(r) + .edit( + res -> { + res.removeFinalizer(finalizer); + return res; + })); + } } From 11492820a06e62bf5e548980c311b3056f12a727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 17 Sep 2025 13:34:21 +0200 Subject: [PATCH 2/2] format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../PrimaryUpdateAndCacheUtils.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) 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 e8eed3535e..bb58ece265 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 @@ -235,10 +235,10 @@ private static

P pollLocalCache( * therefore makes less Kubernetes API Calls. */ @Experimental( - "Not used internally for now. Therefor we don't consider it well tested. But the intention is" - + " to have it as default in the future.") + "Not used internally for now. Therefor we don't consider it well tested. But the intention is" + + " to have it as default in the future.") public static

P addFinalizer( - P resource, String finalizer, Context

context) { + P resource, String finalizer, Context

context) { if (resource.hasFinalizer(finalizer)) { log.debug("Skipping adding finalizer, since already present."); @@ -246,18 +246,18 @@ public static

P addFinalizer( } return updateAndCacheResource( - resource, - context, - r -> r, - r -> - context - .getClient() - .resource(r) - .edit( - res -> { - res.addFinalizer(finalizer); - return res; - })); + resource, + context, + r -> r, + r -> + context + .getClient() + .resource(r) + .edit( + res -> { + res.addFinalizer(finalizer); + return res; + })); } /** @@ -265,26 +265,26 @@ public static

P addFinalizer( * therefore makes less Kubernetes API Calls. */ @Experimental( - "Not used internally for now. Therefor we don't consider it well tested. But the intention is" - + " to have it as default in the future.") + "Not used internally for now. Therefor we don't consider it well tested. But the intention is" + + " to have it as default in the future.") public static

P removeFinalizer( - P resource, String finalizer, Context

context) { + P resource, String finalizer, Context

context) { if (!resource.hasFinalizer(finalizer)) { log.debug("Skipping removing finalizer, since not present."); return resource; } return updateAndCacheResource( - resource, - context, - r -> r, - r -> - context - .getClient() - .resource(r) - .edit( - res -> { - res.removeFinalizer(finalizer); - return res; - })); + resource, + context, + r -> r, + r -> + context + .getClient() + .resource(r) + .edit( + res -> { + res.removeFinalizer(finalizer); + return res; + })); } }