2222import java .time .Duration ;
2323import java .util .ArrayDeque ;
2424import java .util .Deque ;
25+ import java .util .Optional ;
2526
2627import org .junit .jupiter .api .AfterAll ;
2728import org .junit .jupiter .api .BeforeAll ;
3132import org .slf4j .Logger ;
3233import org .slf4j .LoggerFactory ;
3334
35+ import io .fabric8 .kubernetes .api .model .Pod ;
3436import io .fabric8 .kubernetes .client .CustomResource ;
3537import io .fabric8 .kubernetes .client .KubernetesClient ;
3638import 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