From d1c5afb9084bd23155c3f398cc5899efceee4393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 13:40:00 +0200 Subject: [PATCH 01/18] Resource version comparison utility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../PrimaryUpdateAndCacheUtils.java | 20 +++++++++++ .../PrimaryUpdateAndCacheUtilsTest.java | 35 +++++++++++++++++++ 2 files changed, 55 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 6103b4b12b..d353c9649a 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 @@ -450,4 +450,24 @@ public static

P addFinalizerWithSSA( e); } } + + public static int compareResourceVersions(String v1, String v2) { + var v1Length = v1.length(); + var v2Length = v2.length(); + if (v1Length > v2Length) { + return 1; + } + if (v2Length > v1Length) { + return -1; + } + for (int i = 0; i < v1Length; i++) { + if (v1.charAt(i) > v2.charAt(i)) { + return 1; + } + if (v1.charAt(i) < v2.charAt(i)) { + return -1; + } + } + return 0; + } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index c85442f00a..ce310200de 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -20,6 +20,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.KubernetesClient; @@ -37,6 +39,7 @@ import io.javaoperatorsdk.operator.sample.simple.TestCustomResource; import static io.javaoperatorsdk.operator.api.reconciler.PrimaryUpdateAndCacheUtils.DEFAULT_MAX_RETRY; +import static io.javaoperatorsdk.operator.api.reconciler.PrimaryUpdateAndCacheUtils.compareResourceVersions; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -47,6 +50,8 @@ class PrimaryUpdateAndCacheUtilsTest { + private static final Logger log = LoggerFactory.getLogger(PrimaryUpdateAndCacheUtilsTest.class); + Context context = mock(Context.class); KubernetesClient client = mock(KubernetesClient.class); Resource resource = mock(Resource.class); @@ -176,4 +181,34 @@ void cachePollTimeouts() { 10L)); assertThat(ex.getMessage()).contains("Timeout"); } + + @Test + public void compareResourceVersionsTest() { + assertThat(compareResourceVersions("11", "22")).isNegative(); + assertThat(compareResourceVersions("22", "11")).isPositive(); + assertThat(compareResourceVersions("11", "11")).isZero(); + + assertThat(compareResourceVersions("123", "2")).isPositive(); + assertThat(compareResourceVersions("3", "211")).isNegative(); + } + + // naive performance that compares the works case scenario for non parsing variant + @Test + public void compareResourcePerformanceTest() { + var execNum = 10000000; + var startTime = System.currentTimeMillis(); + for (int i = 0; i < execNum; i++) { + var res = compareResourceVersions("123456788", "123456789"); + } + var dur1 = System.currentTimeMillis() - startTime; + log.info("Duration without parsing: {}", dur1); + startTime = System.currentTimeMillis(); + for (int i = 0; i < execNum; i++) { + var res = Long.parseLong("123456788") > Long.parseLong("123456789"); + } + var dur2 = System.currentTimeMillis() - startTime; + log.info("Duration with parsing: {}", dur2); + + assertThat(dur1).isLessThan(dur2); + } } From bc91248dab0390fe65edad1f387ef524c01ea90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 14:54:55 +0200 Subject: [PATCH 02/18] sanity check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../api/reconciler/PrimaryUpdateAndCacheUtils.java | 13 +++++++++++-- .../reconciler/PrimaryUpdateAndCacheUtilsTest.java | 3 +++ 2 files changed, 14 insertions(+), 2 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 d353c9649a..11c0f12864 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 @@ -461,10 +461,19 @@ public static int compareResourceVersions(String v1, String v2) { return -1; } for (int i = 0; i < v1Length; i++) { - if (v1.charAt(i) > v2.charAt(i)) { + var char1 = v1.charAt(i); + var char2 = v2.charAt(i); + if (!Character.isDigit(char1)) { + throw new IllegalStateException("Non numeric characters in resource version (1): " + char1); + } + if (!Character.isDigit(char2)) { + throw new IllegalStateException("Non numeric characters in resource version (2): " + char2); + } + + if (char1 > char2) { return 1; } - if (v1.charAt(i) < v2.charAt(i)) { + if (char1 < char2) { return -1; } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index ce310200de..0db50e2c3b 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -190,6 +190,9 @@ public void compareResourceVersionsTest() { assertThat(compareResourceVersions("123", "2")).isPositive(); assertThat(compareResourceVersions("3", "211")).isNegative(); + + assertThrows(IllegalStateException.class, () -> compareResourceVersions("aa", "22")); + assertThrows(IllegalStateException.class, () -> compareResourceVersions("11", "ba")); } // naive performance that compares the works case scenario for non parsing variant From 4560a0d60d2e7e7f44a6b659290273f8ed796a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 14:57:57 +0200 Subject: [PATCH 03/18] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 0db50e2c3b..ff63056325 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -198,7 +198,7 @@ public void compareResourceVersionsTest() { // naive performance that compares the works case scenario for non parsing variant @Test public void compareResourcePerformanceTest() { - var execNum = 10000000; + var execNum = 100000000; var startTime = System.currentTimeMillis(); for (int i = 0; i < execNum; i++) { var res = compareResourceVersions("123456788", "123456789"); From 97a68f10fbd75ad140aaa4903d0731383d15798d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 16:14:09 +0200 Subject: [PATCH 04/18] Update operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java Co-authored-by: Steven Hawkins --- .../PrimaryUpdateAndCacheUtils.java | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 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 11c0f12864..5990134e03 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 @@ -453,30 +453,54 @@ public static

P addFinalizerWithSSA( public static int compareResourceVersions(String v1, String v2) { var v1Length = v1.length(); - var v2Length = v2.length(); - if (v1Length > v2Length) { - return 1; + if (v1Length == 0) { + throw new IllegalStateException("Resource version (1) is empty"); } - if (v2Length > v1Length) { - return -1; + var v2Length = v2.length(); + if (v2Length == 0) { + throw new IllegalStateException("Resource version (2) is empty"); } - for (int i = 0; i < v1Length; i++) { - var char1 = v1.charAt(i); - var char2 = v2.charAt(i); - if (!Character.isDigit(char1)) { - throw new IllegalStateException("Non numeric characters in resource version (1): " + char1); - } - if (!Character.isDigit(char2)) { - throw new IllegalStateException("Non numeric characters in resource version (2): " + char2); - } - - if (char1 > char2) { - return 1; + var maxLength = Math.max(v1Length, v2Length); + boolean v1LeadingZero = true; + boolean v2LeadingZero = true; + int lengthComparison = 0; + int comparison = 0; + for (int i = 0; i < maxLength; i++) { + char char1 = 0; + if (i < v1Length) { + char1 = v1.charAt(i); + if (v1LeadingZero) { + if (char1 == '0') { + throw new IllegalStateException("Resource version (1) cannot begin with 0"); + } + v1LeadingZero = false; + } + if (!Character.isDigit(char1)) { + throw new IllegalStateException( + "Non numeric characters in resource version (1): " + char1); + } } - if (char1 < char2) { - return -1; + if (i < v2Length) { + var char2 = v2.charAt(i); + if (v2LeadingZero) { + if (char2 == '0') { + throw new IllegalStateException("Resource version (1) cannot begin with 0"); + } + v2LeadingZero = false; + } + if (!Character.isDigit(char2)) { + throw new IllegalStateException( + "Non numeric characters in resource version (2): " + char2); + } + if (char1 == 0) { + lengthComparison = -1; + } else if (comparison == 0) { + comparison = Character.compare(char1, char2); + } + } else { + lengthComparison = 1; } } - return 0; + return lengthComparison != 0 ? lengthComparison : comparison; } } From b65b8c29a01e3fc447c6dee92717942349e07dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 16:18:08 +0200 Subject: [PATCH 05/18] shorter test run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index ff63056325..0db50e2c3b 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -198,7 +198,7 @@ public void compareResourceVersionsTest() { // naive performance that compares the works case scenario for non parsing variant @Test public void compareResourcePerformanceTest() { - var execNum = 100000000; + var execNum = 10000000; var startTime = System.currentTimeMillis(); for (int i = 0; i < execNum; i++) { var res = compareResourceVersions("123456788", "123456789"); From c9f9ae4b3928e86ada507e59801a579cef192c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 16:25:02 +0200 Subject: [PATCH 06/18] Update operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java Co-authored-by: Steven Hawkins --- .../operator/api/reconciler/PrimaryUpdateAndCacheUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5990134e03..1da3e455e8 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 @@ -484,7 +484,7 @@ public static int compareResourceVersions(String v1, String v2) { var char2 = v2.charAt(i); if (v2LeadingZero) { if (char2 == '0') { - throw new IllegalStateException("Resource version (1) cannot begin with 0"); + throw new IllegalStateException("Resource version (2) cannot begin with 0"); } v2LeadingZero = false; } From 69a81e343f1a44aa4503e6539e768ce97d78bec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 16:35:44 +0200 Subject: [PATCH 07/18] Update operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java Co-authored-by: Steven Hawkins --- .../api/reconciler/PrimaryUpdateAndCacheUtils.java | 7 +++---- 1 file changed, 3 insertions(+), 4 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 1da3e455e8..7a858b9ff8 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 @@ -463,7 +463,6 @@ public static int compareResourceVersions(String v1, String v2) { var maxLength = Math.max(v1Length, v2Length); boolean v1LeadingZero = true; boolean v2LeadingZero = true; - int lengthComparison = 0; int comparison = 0; for (int i = 0; i < maxLength; i++) { char char1 = 0; @@ -493,14 +492,14 @@ public static int compareResourceVersions(String v1, String v2) { "Non numeric characters in resource version (2): " + char2); } if (char1 == 0) { - lengthComparison = -1; + comparison = -1; } else if (comparison == 0) { comparison = Character.compare(char1, char2); } } else { - lengthComparison = 1; + comparison = 1; } } - return lengthComparison != 0 ? lengthComparison : comparison; + return comparison; } } From 50de71184be5d1ab7760e029d46596665c2419a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 18:12:15 +0200 Subject: [PATCH 08/18] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../PrimaryUpdateAndCacheUtils.java | 56 +++++++------------ .../PrimaryUpdateAndCacheUtilsTest.java | 6 +- 2 files changed, 24 insertions(+), 38 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 7a858b9ff8..55cf8daa03 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 @@ -453,53 +453,39 @@ public static

P addFinalizerWithSSA( public static int compareResourceVersions(String v1, String v2) { var v1Length = v1.length(); + var v2Length = v2.length(); if (v1Length == 0) { - throw new IllegalStateException("Resource version (1) is empty"); + throw new IllegalArgumentException("resource version must not be empty (1)"); } - var v2Length = v2.length(); if (v2Length == 0) { - throw new IllegalStateException("Resource version (2) is empty"); + throw new IllegalArgumentException("resource version must not be empty (2)"); } - var maxLength = Math.max(v1Length, v2Length); - boolean v1LeadingZero = true; - boolean v2LeadingZero = true; - int comparison = 0; - for (int i = 0; i < maxLength; i++) { - char char1 = 0; - if (i < v1Length) { - char1 = v1.charAt(i); - if (v1LeadingZero) { - if (char1 == '0') { - throw new IllegalStateException("Resource version (1) cannot begin with 0"); - } - v1LeadingZero = false; - } + if (v1Length > v2Length) { + return 1; + } + if (v2Length > v1Length) { + return -1; + } + for (int i = 0; i < v1Length; i++) { + if (v1.charAt(i) > v2.charAt(i)) { + var char1 = v1.charAt(i); + var char2 = v2.charAt(i); if (!Character.isDigit(char1)) { - throw new IllegalStateException( + throw new IllegalArgumentException( "Non numeric characters in resource version (1): " + char1); } - } - if (i < v2Length) { - var char2 = v2.charAt(i); - if (v2LeadingZero) { - if (char2 == '0') { - throw new IllegalStateException("Resource version (2) cannot begin with 0"); - } - v2LeadingZero = false; - } if (!Character.isDigit(char2)) { - throw new IllegalStateException( + throw new IllegalArgumentException( "Non numeric characters in resource version (2): " + char2); } - if (char1 == 0) { - comparison = -1; - } else if (comparison == 0) { - comparison = Character.compare(char1, char2); + if (char1 > char2) { + return 1; + } + if (char1 < char2) { + return -1; } - } else { - comparison = 1; } } - return comparison; + return 0; } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 0db50e2c3b..82cb16434a 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -191,14 +191,14 @@ public void compareResourceVersionsTest() { assertThat(compareResourceVersions("123", "2")).isPositive(); assertThat(compareResourceVersions("3", "211")).isNegative(); - assertThrows(IllegalStateException.class, () -> compareResourceVersions("aa", "22")); - assertThrows(IllegalStateException.class, () -> compareResourceVersions("11", "ba")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("aa", "22")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "ba")); } // naive performance that compares the works case scenario for non parsing variant @Test public void compareResourcePerformanceTest() { - var execNum = 10000000; + var execNum = 20000000; var startTime = System.currentTimeMillis(); for (int i = 0; i < execNum; i++) { var res = compareResourceVersions("123456788", "123456789"); From e76e706f8d7f70f5f840861cbfefa1d4de67666f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 18:13:50 +0200 Subject: [PATCH 09/18] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../PrimaryUpdateAndCacheUtils.java | 34 +++++++++---------- .../PrimaryUpdateAndCacheUtilsTest.java | 2 ++ 2 files changed, 18 insertions(+), 18 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 55cf8daa03..4b477904fa 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 @@ -463,27 +463,25 @@ public static int compareResourceVersions(String v1, String v2) { if (v1Length > v2Length) { return 1; } - if (v2Length > v1Length) { + if (v1Length < v2Length) { return -1; } for (int i = 0; i < v1Length; i++) { - if (v1.charAt(i) > v2.charAt(i)) { - var char1 = v1.charAt(i); - var char2 = v2.charAt(i); - if (!Character.isDigit(char1)) { - throw new IllegalArgumentException( - "Non numeric characters in resource version (1): " + char1); - } - if (!Character.isDigit(char2)) { - throw new IllegalArgumentException( - "Non numeric characters in resource version (2): " + char2); - } - if (char1 > char2) { - return 1; - } - if (char1 < char2) { - return -1; - } + var char1 = v1.charAt(i); + var char2 = v2.charAt(i); + if (!Character.isDigit(char1)) { + throw new IllegalArgumentException( + "Non numeric characters in resource version (1): " + char1); + } + if (!Character.isDigit(char2)) { + throw new IllegalArgumentException( + "Non numeric characters in resource version (2): " + char2); + } + if (char1 > char2) { + return 1; + } + if (char1 < char2) { + return -1; } } return 0; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 82cb16434a..0074059b35 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -193,6 +193,8 @@ public void compareResourceVersionsTest() { assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("aa", "22")); assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "ba")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("", "22")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "")); } // naive performance that compares the works case scenario for non parsing variant From 111350c1237028dece28eb45df4c04d3572d76ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Fri, 10 Oct 2025 18:19:43 +0200 Subject: [PATCH 10/18] improve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/api/reconciler/PrimaryUpdateAndCacheUtils.java | 6 ++++++ .../api/reconciler/PrimaryUpdateAndCacheUtilsTest.java | 2 ++ 2 files changed, 8 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 4b477904fa..6edb0fc379 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 @@ -460,6 +460,12 @@ public static int compareResourceVersions(String v1, String v2) { if (v2Length == 0) { throw new IllegalArgumentException("resource version must not be empty (2)"); } + if (v1.charAt(0) == '0') { + throw new IllegalArgumentException("resource version (1) must not start with 0"); + } + if (v2.charAt(0) == '0') { + throw new IllegalArgumentException("resource version (2) must not start with 0"); + } if (v1Length > v2Length) { return 1; } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 0074059b35..085e1507d7 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -195,6 +195,8 @@ public void compareResourceVersionsTest() { assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "ba")); assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("", "22")); assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("01", "123")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("123", "01")); } // naive performance that compares the works case scenario for non parsing variant From d212e39f67ab7a3b4e3e843827492ff8a8eb484f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sat, 11 Oct 2025 14:33:14 +0200 Subject: [PATCH 11/18] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../PrimaryUpdateAndCacheUtils.java | 20 ------------------- .../PrimaryUpdateAndCacheUtilsTest.java | 7 ------- 2 files changed, 27 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 6edb0fc379..1690dd5972 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 @@ -454,18 +454,6 @@ public static

P addFinalizerWithSSA( public static int compareResourceVersions(String v1, String v2) { var v1Length = v1.length(); var v2Length = v2.length(); - if (v1Length == 0) { - throw new IllegalArgumentException("resource version must not be empty (1)"); - } - if (v2Length == 0) { - throw new IllegalArgumentException("resource version must not be empty (2)"); - } - if (v1.charAt(0) == '0') { - throw new IllegalArgumentException("resource version (1) must not start with 0"); - } - if (v2.charAt(0) == '0') { - throw new IllegalArgumentException("resource version (2) must not start with 0"); - } if (v1Length > v2Length) { return 1; } @@ -475,14 +463,6 @@ public static int compareResourceVersions(String v1, String v2) { for (int i = 0; i < v1Length; i++) { var char1 = v1.charAt(i); var char2 = v2.charAt(i); - if (!Character.isDigit(char1)) { - throw new IllegalArgumentException( - "Non numeric characters in resource version (1): " + char1); - } - if (!Character.isDigit(char2)) { - throw new IllegalArgumentException( - "Non numeric characters in resource version (2): " + char2); - } if (char1 > char2) { return 1; } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 085e1507d7..46b3b28330 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -190,13 +190,6 @@ public void compareResourceVersionsTest() { assertThat(compareResourceVersions("123", "2")).isPositive(); assertThat(compareResourceVersions("3", "211")).isNegative(); - - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("aa", "22")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "ba")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("", "22")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("01", "123")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("123", "01")); } // naive performance that compares the works case scenario for non parsing variant From 4b5406fe2c40ba61f8138d11a3e622eb1065d0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sat, 11 Oct 2025 14:56:51 +0200 Subject: [PATCH 12/18] revert to KEP compatible way MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../PrimaryUpdateAndCacheUtils.java | 56 ++++++++++++++----- .../PrimaryUpdateAndCacheUtilsTest.java | 9 ++- 2 files changed, 51 insertions(+), 14 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 1690dd5972..ddeef3459b 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 @@ -453,23 +453,53 @@ public static

P addFinalizerWithSSA( public static int compareResourceVersions(String v1, String v2) { var v1Length = v1.length(); - var v2Length = v2.length(); - if (v1Length > v2Length) { - return 1; + if (v1Length == 0) { + throw new IllegalArgumentException("Resource version (1) is empty"); } - if (v1Length < v2Length) { - return -1; + var v2Length = v2.length(); + if (v2Length == 0) { + throw new IllegalArgumentException("Resource version (2) is empty"); } - for (int i = 0; i < v1Length; i++) { - var char1 = v1.charAt(i); - var char2 = v2.charAt(i); - if (char1 > char2) { - return 1; + var maxLength = Math.max(v1Length, v2Length); + boolean v1LeadingZero = true; + boolean v2LeadingZero = true; + int comparison = 0; + for (int i = 0; i < maxLength; i++) { + char char1 = 0; + if (i < v1Length) { + char1 = v1.charAt(i); + if (v1LeadingZero) { + if (char1 == '0') { + throw new IllegalArgumentException("Resource version (1) cannot begin with 0"); + } + v1LeadingZero = false; + } + if (!Character.isDigit(char1)) { + throw new IllegalArgumentException( + "Non numeric characters in resource version (1): " + char1); + } } - if (char1 < char2) { - return -1; + if (i < v2Length) { + var char2 = v2.charAt(i); + if (v2LeadingZero) { + if (char2 == '0') { + throw new IllegalArgumentException("Resource version (2) cannot begin with 0"); + } + v2LeadingZero = false; + } + if (!Character.isDigit(char2)) { + throw new IllegalArgumentException( + "Non numeric characters in resource version (2): " + char2); + } + if (char1 == 0) { + comparison = -1; + } else if (comparison == 0) { + comparison = Character.compare(char1, char2); + } + } else { + comparison = 1; } } - return 0; + return comparison; } } diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 46b3b28330..78415cc861 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -190,12 +190,19 @@ public void compareResourceVersionsTest() { assertThat(compareResourceVersions("123", "2")).isPositive(); assertThat(compareResourceVersions("3", "211")).isNegative(); + + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("aa", "22")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "ba")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("", "22")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("01", "123")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("123", "01")); } // naive performance that compares the works case scenario for non parsing variant @Test public void compareResourcePerformanceTest() { - var execNum = 20000000; + var execNum = 30000000; var startTime = System.currentTimeMillis(); for (int i = 0; i < execNum; i++) { var res = compareResourceVersions("123456788", "123456789"); From 28e39b7fd35a6bcefda5252d65d64eaa923e6cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sat, 11 Oct 2025 15:30:07 +0200 Subject: [PATCH 13/18] additional tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 78415cc861..2f563d2d6b 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -197,6 +197,8 @@ public void compareResourceVersionsTest() { assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "")); assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("01", "123")); assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("123", "01")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("3213", "123a")); + assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("321", "123a")); } // naive performance that compares the works case scenario for non parsing variant From 868124c574edd00bc671de6f1f6cfe60850976ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sat, 11 Oct 2025 15:30:53 +0200 Subject: [PATCH 14/18] tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 2f563d2d6b..e50a80334f 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -186,8 +186,8 @@ void cachePollTimeouts() { public void compareResourceVersionsTest() { assertThat(compareResourceVersions("11", "22")).isNegative(); assertThat(compareResourceVersions("22", "11")).isPositive(); + assertThat(compareResourceVersions("1", "1")).isZero(); assertThat(compareResourceVersions("11", "11")).isZero(); - assertThat(compareResourceVersions("123", "2")).isPositive(); assertThat(compareResourceVersions("3", "211")).isNegative(); From a029b61e69c072730368c1f09da6fdfcc0326a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 13 Oct 2025 11:32:10 +0200 Subject: [PATCH 15/18] Update operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java Co-authored-by: Martin Stefanko --- .../operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index e50a80334f..3c9dfbf6f0 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -201,7 +201,7 @@ public void compareResourceVersionsTest() { assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("321", "123a")); } - // naive performance that compares the works case scenario for non parsing variant + // naive performance test that compares the work case scenario for the parsing and non-parsing variants @Test public void compareResourcePerformanceTest() { var execNum = 30000000; From 3c2f5dd92a416249ddfd5a528459338c33f09ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 13 Oct 2025 11:33:26 +0200 Subject: [PATCH 16/18] format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../api/reconciler/PrimaryUpdateAndCacheUtilsTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 3c9dfbf6f0..3a3dc38bb4 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -201,7 +201,8 @@ public void compareResourceVersionsTest() { assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("321", "123a")); } - // naive performance test that compares the work case scenario for the parsing and non-parsing variants + // naive performance test that compares the work case scenario for the parsing and non-parsing + // variants @Test public void compareResourcePerformanceTest() { var execNum = 30000000; From 5202fcb954f452c88421096adc874741da4ba543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 14 Oct 2025 17:53:26 +0200 Subject: [PATCH 17/18] explicit exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- ...NonComparableResourceVersionException.java | 10 ++++++++ .../PrimaryUpdateAndCacheUtils.java | 14 ++++++----- .../PrimaryUpdateAndCacheUtilsTest.java | 24 ++++++++++++------- 3 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/NonComparableResourceVersionException.java diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/NonComparableResourceVersionException.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/NonComparableResourceVersionException.java new file mode 100644 index 0000000000..8d0f13d1fb --- /dev/null +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/NonComparableResourceVersionException.java @@ -0,0 +1,10 @@ +package io.javaoperatorsdk.operator.api.reconciler; + +import io.javaoperatorsdk.operator.OperatorException; + +public class NonComparableResourceVersionException extends OperatorException { + + public NonComparableResourceVersionException(String message) { + super(message); + } +} 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 ddeef3459b..6f22de4b90 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 @@ -454,11 +454,11 @@ public static

P addFinalizerWithSSA( public static int compareResourceVersions(String v1, String v2) { var v1Length = v1.length(); if (v1Length == 0) { - throw new IllegalArgumentException("Resource version (1) is empty"); + throw new NonComparableResourceVersionException("Resource version (1) is empty"); } var v2Length = v2.length(); if (v2Length == 0) { - throw new IllegalArgumentException("Resource version (2) is empty"); + throw new NonComparableResourceVersionException("Resource version (1) is empty"); } var maxLength = Math.max(v1Length, v2Length); boolean v1LeadingZero = true; @@ -470,12 +470,13 @@ public static int compareResourceVersions(String v1, String v2) { char1 = v1.charAt(i); if (v1LeadingZero) { if (char1 == '0') { - throw new IllegalArgumentException("Resource version (1) cannot begin with 0"); + throw new NonComparableResourceVersionException( + "Resource version (1) cannot begin with 0"); } v1LeadingZero = false; } if (!Character.isDigit(char1)) { - throw new IllegalArgumentException( + throw new NonComparableResourceVersionException( "Non numeric characters in resource version (1): " + char1); } } @@ -483,12 +484,13 @@ public static int compareResourceVersions(String v1, String v2) { var char2 = v2.charAt(i); if (v2LeadingZero) { if (char2 == '0') { - throw new IllegalArgumentException("Resource version (2) cannot begin with 0"); + throw new NonComparableResourceVersionException( + "Resource version (2) cannot begin with 0"); } v2LeadingZero = false; } if (!Character.isDigit(char2)) { - throw new IllegalArgumentException( + throw new NonComparableResourceVersionException( "Non numeric characters in resource version (2): " + char2); } if (char1 == 0) { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java index 3a3dc38bb4..8918ba4f25 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtilsTest.java @@ -191,14 +191,22 @@ public void compareResourceVersionsTest() { assertThat(compareResourceVersions("123", "2")).isPositive(); assertThat(compareResourceVersions("3", "211")).isNegative(); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("aa", "22")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "ba")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("", "22")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("11", "")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("01", "123")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("123", "01")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("3213", "123a")); - assertThrows(IllegalArgumentException.class, () -> compareResourceVersions("321", "123a")); + assertThrows( + NonComparableResourceVersionException.class, () -> compareResourceVersions("aa", "22")); + assertThrows( + NonComparableResourceVersionException.class, () -> compareResourceVersions("11", "ba")); + assertThrows( + NonComparableResourceVersionException.class, () -> compareResourceVersions("", "22")); + assertThrows( + NonComparableResourceVersionException.class, () -> compareResourceVersions("11", "")); + assertThrows( + NonComparableResourceVersionException.class, () -> compareResourceVersions("01", "123")); + assertThrows( + NonComparableResourceVersionException.class, () -> compareResourceVersions("123", "01")); + assertThrows( + NonComparableResourceVersionException.class, () -> compareResourceVersions("3213", "123a")); + assertThrows( + NonComparableResourceVersionException.class, () -> compareResourceVersions("321", "123a")); } // naive performance test that compares the work case scenario for the parsing and non-parsing From 808f6d97e363561260a00e754e7a94cb9890c813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Tue, 14 Oct 2025 18:13:57 +0200 Subject: [PATCH 18/18] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../NonComparableResourceVersionException.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/NonComparableResourceVersionException.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/NonComparableResourceVersionException.java index 8d0f13d1fb..03045ed88a 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/NonComparableResourceVersionException.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/NonComparableResourceVersionException.java @@ -1,3 +1,18 @@ +/* + * Copyright Java Operator SDK Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.javaoperatorsdk.operator.api.reconciler; import io.javaoperatorsdk.operator.OperatorException;