From f928da881b870fd02e9ece6815e927ca8c05b95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 7 Sep 2025 15:23:23 +0200 Subject: [PATCH] improve: GenericRetry does not provide mutable singleton instance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This might easily result in unintended side effect if someone uses `DEFAULT` instance in one controller, changes some paramter; then uses the instance for an other controller, in that case the changed parameter will apply also for other controller what is quite unintuitive Signed-off-by: Attila Mészáros --- .../operator/api/config/ControllerConfiguration.java | 2 +- .../operator/processing/retry/GenericRetry.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java index 2c18fa55d3..3898493c82 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java @@ -57,7 +57,7 @@ default boolean isGenerationAware() { String getAssociatedReconcilerClassName(); default Retry getRetry() { - return GenericRetry.DEFAULT; + return GenericRetry.defaultLimitedExponentialRetry(); } @SuppressWarnings("rawtypes") diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java index 9b42971e7c..0ff44a6fe7 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java @@ -10,10 +10,15 @@ public class GenericRetry implements Retry, AnnotationConfigurable private double intervalMultiplier = GradualRetry.DEFAULT_MULTIPLIER; private long maxInterval = GradualRetry.DEFAULT_MAX_INTERVAL; + /** + * @deprecated use {@link GenericRetry#defaultLimitedExponentialRetry()} instead this instance. + * Since GenericRetry is mutable, singleton is problematic. + */ + @Deprecated(forRemoval = true) public static final Retry DEFAULT = new GenericRetry(); public static GenericRetry defaultLimitedExponentialRetry() { - return (GenericRetry) DEFAULT; + return new GenericRetry(); } public static GenericRetry noRetry() {