Skip to content

Commit d3ebea5

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 2e478ed commit d3ebea5

File tree

1 file changed

+21
-35
lines changed
  • sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics

1 file changed

+21
-35
lines changed

sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.time.Duration;
2323
import java.util.ArrayDeque;
2424
import java.util.Deque;
25+
import java.util.Optional;
2526

2627
import org.junit.jupiter.api.AfterAll;
2728
import org.junit.jupiter.api.BeforeAll;
@@ -31,6 +32,7 @@
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

35+
import io.fabric8.kubernetes.api.model.Pod;
3436
import io.fabric8.kubernetes.client.CustomResource;
3537
import io.fabric8.kubernetes.client.KubernetesClient;
3638
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
@@ -102,42 +104,9 @@ private LocalPortForward portForward(String labelKey, String labelValue, int por
102104
await()
103105
.atMost(Duration.ofMinutes(3))
104106
.pollInterval(Duration.ofSeconds(5))
105-
.until(
106-
() -> {
107-
var pods =
108-
client
109-
.pods()
110-
.inNamespace(OBSERVABILITY_NAMESPACE)
111-
.withLabel(labelKey, labelValue)
112-
.list()
113-
.getItems();
114-
return pods.stream()
115-
.anyMatch(
116-
pod ->
117-
pod.getStatus() != null
118-
&& pod.getStatus().getConditions() != null
119-
&& pod.getStatus().getConditions().stream()
120-
.anyMatch(
121-
c ->
122-
"Ready".equals(c.getType())
123-
&& "True".equals(c.getStatus())));
124-
});
107+
.until(() -> findReadyPod(labelKey, labelValue).isPresent());
125108
var pod =
126-
client
127-
.pods()
128-
.inNamespace(OBSERVABILITY_NAMESPACE)
129-
.withLabel(labelKey, labelValue)
130-
.list()
131-
.getItems()
132-
.stream()
133-
.filter(
134-
p ->
135-
p.getStatus() != null
136-
&& p.getStatus().getConditions() != null
137-
&& p.getStatus().getConditions().stream()
138-
.anyMatch(
139-
c -> "Ready".equals(c.getType()) && "True".equals(c.getStatus())))
140-
.findFirst()
109+
findReadyPod(labelKey, labelValue)
141110
.orElseThrow(
142111
() ->
143112
new IllegalStateException(
@@ -151,6 +120,23 @@ private LocalPortForward portForward(String labelKey, String labelValue, int por
151120
.portForward(port, port);
152121
}
153122

123+
private Optional<Pod> findReadyPod(String labelKey, String labelValue) {
124+
return client
125+
.pods()
126+
.inNamespace(OBSERVABILITY_NAMESPACE)
127+
.withLabel(labelKey, labelValue)
128+
.list()
129+
.getItems()
130+
.stream()
131+
.filter(
132+
pod ->
133+
pod.getStatus() != null
134+
&& pod.getStatus().getConditions() != null
135+
&& pod.getStatus().getConditions().stream()
136+
.anyMatch(c -> "Ready".equals(c.getType()) && "True".equals(c.getStatus())))
137+
.findFirst();
138+
}
139+
154140
private void closePortForward(LocalPortForward pf) throws IOException {
155141
if (pf != null) {
156142
pf.close();

0 commit comments

Comments
 (0)