From 23622c76975cb65a7b8caac134cbcea1d58f113d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 8 Mar 2026 19:21:45 +0100 Subject: [PATCH 1/9] fix: wait for pods to be ready before port-forwarding in MetricsHandlingE2E MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace one-shot pod lookup with an awaitility-based readiness wait (up to 3 minutes) to avoid IllegalStateException when pods are not yet scheduled after observability stack installation. Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: Attila Mészáros --- .../sample/metrics/MetricsHandlingE2E.java | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index fa5bf42a14..e796b41c2e 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -81,7 +81,7 @@ class MetricsHandlingE2E { .build(); @BeforeAll - void setupObservability() throws InterruptedException { + void setupObservability() { log.info("Setting up observability stack..."); installObservabilityServices(); prometheusPortForward = portForward(NAME_LABEL_KEY, "prometheus", PROMETHEUS_PORT); @@ -89,7 +89,6 @@ void setupObservability() throws InterruptedException { otelCollectorPortForward = portForward(NAME_LABEL_KEY, "otel-collector-collector", OTEL_COLLECTOR_PORT); } - Thread.sleep(2000); } @AfterAll @@ -99,25 +98,49 @@ void cleanup() throws IOException { } private LocalPortForward portForward(String labelKey, String labelValue, int port) { + log.info("Waiting for pod with label {}={} to be ready...", labelKey, labelValue); + await() + .atMost(Duration.ofMinutes(3)) + .pollInterval(Duration.ofSeconds(5)) + .until( + () -> { + var pods = + client + .pods() + .inNamespace(OBSERVABILITY_NAMESPACE) + .withLabel(labelKey, labelValue) + .list() + .getItems(); + return pods.stream() + .anyMatch( + pod -> + pod.getStatus() != null + && pod.getStatus().getConditions() != null + && pod.getStatus().getConditions().stream() + .anyMatch( + c -> + "Ready".equals(c.getType()) + && "True".equals(c.getStatus()))); + }); + var pod = + client + .pods() + .inNamespace(OBSERVABILITY_NAMESPACE) + .withLabel(labelKey, labelValue) + .list() + .getItems() + .stream() + .findFirst() + .orElseThrow( + () -> + new IllegalStateException( + "Pod not found for label " + labelKey + "=" + labelValue)); + log.info("Pod {} is ready, establishing port-forward on port {}", pod.getMetadata().getName(), port); return client .pods() .inNamespace(OBSERVABILITY_NAMESPACE) - .withLabel(labelKey, labelValue) - .list() - .getItems() - .stream() - .findFirst() - .map( - pod -> - client - .pods() - .inNamespace(OBSERVABILITY_NAMESPACE) - .withName(pod.getMetadata().getName()) - .portForward(port, port)) - .orElseThrow( - () -> - new IllegalStateException( - "Pod not found for label " + labelKey + "=" + labelValue)); + .withName(pod.getMetadata().getName()) + .portForward(port, port); } private void closePortForward(LocalPortForward pf) throws IOException { From fd18fb46a1be8ea74b8912b307d5e65efe71ff6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 8 Mar 2026 19:23:12 +0100 Subject: [PATCH 2/9] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/sample/metrics/MetricsHandlingE2E.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index e796b41c2e..7983132436 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -135,7 +135,8 @@ private LocalPortForward portForward(String labelKey, String labelValue, int por () -> new IllegalStateException( "Pod not found for label " + labelKey + "=" + labelValue)); - log.info("Pod {} is ready, establishing port-forward on port {}", pod.getMetadata().getName(), port); + log.info( + "Pod {} is ready, establishing port-forward on port {}", pod.getMetadata().getName(), port); return client .pods() .inNamespace(OBSERVABILITY_NAMESPACE) From 2e478ed6200137c034c8529b4a0e05a1bed58865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 8 Mar 2026 19:34:51 +0100 Subject: [PATCH 3/9] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/sample/metrics/MetricsHandlingE2E.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index 7983132436..386e741efc 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -130,6 +130,13 @@ private LocalPortForward portForward(String labelKey, String labelValue, int por .list() .getItems() .stream() + .filter( + p -> + p.getStatus() != null + && p.getStatus().getConditions() != null + && p.getStatus().getConditions().stream() + .anyMatch( + c -> "Ready".equals(c.getType()) && "True".equals(c.getStatus()))) .findFirst() .orElseThrow( () -> From d3ebea55526e2f11db3395213af330a3c1c1e18e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 8 Mar 2026 19:45:01 +0100 Subject: [PATCH 4/9] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../sample/metrics/MetricsHandlingE2E.java | 56 +++++++------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index 386e741efc..8d563c5b7a 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -22,6 +22,7 @@ import java.time.Duration; import java.util.ArrayDeque; import java.util.Deque; +import java.util.Optional; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -31,6 +32,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; @@ -102,42 +104,9 @@ private LocalPortForward portForward(String labelKey, String labelValue, int por await() .atMost(Duration.ofMinutes(3)) .pollInterval(Duration.ofSeconds(5)) - .until( - () -> { - var pods = - client - .pods() - .inNamespace(OBSERVABILITY_NAMESPACE) - .withLabel(labelKey, labelValue) - .list() - .getItems(); - return pods.stream() - .anyMatch( - pod -> - pod.getStatus() != null - && pod.getStatus().getConditions() != null - && pod.getStatus().getConditions().stream() - .anyMatch( - c -> - "Ready".equals(c.getType()) - && "True".equals(c.getStatus()))); - }); + .until(() -> findReadyPod(labelKey, labelValue).isPresent()); var pod = - client - .pods() - .inNamespace(OBSERVABILITY_NAMESPACE) - .withLabel(labelKey, labelValue) - .list() - .getItems() - .stream() - .filter( - p -> - p.getStatus() != null - && p.getStatus().getConditions() != null - && p.getStatus().getConditions().stream() - .anyMatch( - c -> "Ready".equals(c.getType()) && "True".equals(c.getStatus()))) - .findFirst() + findReadyPod(labelKey, labelValue) .orElseThrow( () -> new IllegalStateException( @@ -151,6 +120,23 @@ private LocalPortForward portForward(String labelKey, String labelValue, int por .portForward(port, port); } + private Optional findReadyPod(String labelKey, String labelValue) { + return client + .pods() + .inNamespace(OBSERVABILITY_NAMESPACE) + .withLabel(labelKey, labelValue) + .list() + .getItems() + .stream() + .filter( + pod -> + pod.getStatus() != null + && pod.getStatus().getConditions() != null + && pod.getStatus().getConditions().stream() + .anyMatch(c -> "Ready".equals(c.getType()) && "True".equals(c.getStatus()))) + .findFirst(); + } + private void closePortForward(LocalPortForward pf) throws IOException { if (pf != null) { pf.close(); From b422d482a627a453732c86f466ad451e18d5935c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 8 Mar 2026 20:25:22 +0100 Subject: [PATCH 5/9] list pods as debug message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/sample/metrics/MetricsHandlingE2E.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index 8d563c5b7a..973445383d 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -121,6 +121,19 @@ private LocalPortForward portForward(String labelKey, String labelValue, int por } private Optional findReadyPod(String labelKey, String labelValue) { + if (log.isDebugEnabled()) { + log.debug( + "Pods with label selectors '{}={}': {}", + labelKey, + labelValue, + client + .pods() + .inNamespace(OBSERVABILITY_NAMESPACE) + .withLabel(labelKey, labelValue) + .list() + .getItems()); + } + return client .pods() .inNamespace(OBSERVABILITY_NAMESPACE) From f9cfa12556c0285fc13a0dc3fef5ef2e515c14b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 8 Mar 2026 20:36:33 +0100 Subject: [PATCH 6/9] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/sample/metrics/MetricsHandlingE2E.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index 973445383d..044e71fb09 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -102,8 +102,8 @@ void cleanup() throws IOException { private LocalPortForward portForward(String labelKey, String labelValue, int port) { log.info("Waiting for pod with label {}={} to be ready...", labelKey, labelValue); await() - .atMost(Duration.ofMinutes(3)) - .pollInterval(Duration.ofSeconds(5)) + .atMost(Duration.ofMinutes(7)) + .pollInterval(Duration.ofSeconds(10)) .until(() -> findReadyPod(labelKey, labelValue).isPresent()); var pod = findReadyPod(labelKey, labelValue) From 16adcc7fc172916790f52a58300b598dffb41873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Sun, 8 Mar 2026 21:17:06 +0100 Subject: [PATCH 7/9] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/sample/metrics/MetricsHandlingE2E.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index 044e71fb09..5bc1df59ed 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -102,7 +102,7 @@ void cleanup() throws IOException { private LocalPortForward portForward(String labelKey, String labelValue, int port) { log.info("Waiting for pod with label {}={} to be ready...", labelKey, labelValue); await() - .atMost(Duration.ofMinutes(7)) + .atMost(Duration.ofMinutes(15)) .pollInterval(Duration.ofSeconds(10)) .until(() -> findReadyPod(labelKey, labelValue).isPresent()); var pod = From 53f57ea0e83381a5103d4e86d3bd0ed1aa599180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 9 Mar 2026 11:02:34 +0100 Subject: [PATCH 8/9] remove debug logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../operator/sample/metrics/MetricsHandlingE2E.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index 5bc1df59ed..15842aea70 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -121,19 +121,6 @@ private LocalPortForward portForward(String labelKey, String labelValue, int por } private Optional findReadyPod(String labelKey, String labelValue) { - if (log.isDebugEnabled()) { - log.debug( - "Pods with label selectors '{}={}': {}", - labelKey, - labelValue, - client - .pods() - .inNamespace(OBSERVABILITY_NAMESPACE) - .withLabel(labelKey, labelValue) - .list() - .getItems()); - } - return client .pods() .inNamespace(OBSERVABILITY_NAMESPACE) From 853feb2285b48921a7197a25edc95f6720417fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Mon, 9 Mar 2026 15:46:35 +0100 Subject: [PATCH 9/9] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- .../sample/metrics/MetricsHandlingE2E.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java index 15842aea70..3c17f36ac1 100644 --- a/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java +++ b/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java @@ -23,6 +23,7 @@ import java.util.ArrayDeque; import java.util.Deque; import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -101,16 +102,18 @@ void cleanup() throws IOException { private LocalPortForward portForward(String labelKey, String labelValue, int port) { log.info("Waiting for pod with label {}={} to be ready...", labelKey, labelValue); + AtomicReference portForwardPod = new AtomicReference<>(); + await() .atMost(Duration.ofMinutes(15)) .pollInterval(Duration.ofSeconds(10)) - .until(() -> findReadyPod(labelKey, labelValue).isPresent()); - var pod = - findReadyPod(labelKey, labelValue) - .orElseThrow( - () -> - new IllegalStateException( - "Pod not found for label " + labelKey + "=" + labelValue)); + .untilAsserted( + () -> { + var pod = findReadyPod(labelKey, labelValue); + assertThat(pod).isPresent(); + portForwardPod.set(pod.orElseThrow()); + }); + var pod = portForwardPod.get(); log.info( "Pod {} is ready, establishing port-forward on port {}", pod.getMetadata().getName(), port); return client