11package io .kestra .plugin .kubernetes .services ;
22
3- import io .fabric8 .kubernetes .api .model .*;
4- import io .fabric8 .kubernetes .client .Config ;
5- import io .fabric8 .kubernetes .client .KubernetesClient ;
6- import io .fabric8 .kubernetes .client .KubernetesClientException ;
7- import io .fabric8 .kubernetes .client .dsl .PodResource ;
8- import io .kestra .core .exceptions .IllegalVariableEvaluationException ;
9- import io .kestra .core .models .tasks .retrys .Exponential ;
10- import io .kestra .core .models .tasks .runners .AbstractLogConsumer ;
11- import io .kestra .core .runners .RunContext ;
12- import io .kestra .core .utils .RetryUtils ;
13- import io .kestra .plugin .kubernetes .models .Connection ;
14- import org .slf4j .Logger ;
15-
163import java .io .File ;
174import java .io .IOException ;
185import java .nio .file .Path ;
2815
2916import io .kestra .core .exceptions .IllegalVariableEvaluationException ;
3017import io .kestra .core .models .tasks .retrys .Exponential ;
18+ import io .kestra .core .models .tasks .runners .AbstractLogConsumer ;
3119import io .kestra .core .runners .RunContext ;
3220import io .kestra .core .utils .RetryUtils ;
3321import io .kestra .plugin .kubernetes .models .Connection ;
@@ -72,25 +60,24 @@ public static Pod waitForPodReady(KubernetesClient client, Pod pod, Duration wai
7260 return PodService .podRef (client , pod )
7361 .waitUntilCondition (
7462 j -> j != null &&
75- j .getStatus () != null && (
76- PodPhase . FAILED . value (). equals ( j .getStatus ().getPhase ()) ||
77- ( j .getStatus ().getContainerStatuses () != null &&
78- j . getStatus (). getContainerStatuses (). stream ()
79- . anyMatch ( cs -> cs .getState () != null &&
63+ j .getStatus () != null && (PodPhase . FAILED . value (). equals ( j . getStatus (). getPhase ()) ||
64+ ( j .getStatus ().getContainerStatuses () != null &&
65+ j .getStatus ().getContainerStatuses (). stream ()
66+ . anyMatch (
67+ cs -> cs .getState () != null &&
8068 cs .getState ().getWaiting () != null &&
8169 cs .getState ().getWaiting ().getReason () != null &&
8270 !TransientWaitingReason .contains (cs .getState ().getWaiting ().getReason ())
83- )
84- ) ||
71+ ) )
72+ ||
8573 j .getStatus ()
8674 .getConditions ()
8775 .stream ()
88- .anyMatch (podCondition ->
89- ("ContainersReady" .equals (podCondition .getType ()) &&
76+ .anyMatch (
77+ podCondition -> ("ContainersReady" .equals (podCondition .getType ()) &&
9078 (hasSidecar || "True" .equals (podCondition .getStatus ()))) ||
9179 ("PodCompleted" .equals (podCondition .getReason ()))
92- )
93- ),
80+ )),
9481 waitUntilRunning .toSeconds (),
9582 TimeUnit .SECONDS
9683 );
@@ -100,11 +87,10 @@ public static Pod waitForContainersStartedOrCompleted(KubernetesClient client, P
10087 return PodService .podRef (client , pod )
10188 .waitUntilCondition (
10289 j -> j != null &&
103- j .getStatus () != null && (
104- (PodPhase .RUNNING .value ().equals (j .getStatus ().getPhase ()) &&
105- j .getStatus ().getContainerStatuses () != null &&
106- j .getStatus ().getContainerStatuses ().stream ()
107- .anyMatch (c -> c .getState ().getRunning () != null ))
90+ j .getStatus () != null && ((PodPhase .RUNNING .value ().equals (j .getStatus ().getPhase ()) &&
91+ j .getStatus ().getContainerStatuses () != null &&
92+ j .getStatus ().getContainerStatuses ().stream ()
93+ .anyMatch (c -> c .getState ().getRunning () != null ))
10894 ||
10995 COMPLETED_PHASES .contains (j .getStatus ().getPhase ())),
11096 waitUntilRunning .toSeconds (),
@@ -201,12 +187,15 @@ public static IllegalStateException failedMessage(Pod pod) throws IllegalStateEx
201187 .filter (containerStatus -> containerStatus .getState () != null && containerStatus .getState ().getTerminated () != null )
202188 .map (containerStatus -> containerStatus .getState ().getTerminated ())
203189 .findFirst ()
204- .map (containerStateTerminated -> new IllegalStateException (
205- "Pods terminated with status '" + pod .getStatus ().getPhase () + "', " +
206- "exitcode '" + containerStateTerminated .getExitCode () + "' & " +
207- "message '" + containerStateTerminated .getMessage () + "'"
208- ))
209- .orElseGet (() -> {
190+ .map (
191+ containerStateTerminated -> new IllegalStateException (
192+ "Pods terminated with status '" + pod .getStatus ().getPhase () + "', " +
193+ "exitcode '" + containerStateTerminated .getExitCode () + "' & " +
194+ "message '" + containerStateTerminated .getMessage () + "'"
195+ )
196+ )
197+ .orElseGet (() ->
198+ {
210199 if (pod .getStatus ().getContainerStatuses () != null ) {
211200 Optional <String > waitingReason = pod .getStatus ().getContainerStatuses ().stream ()
212201 .filter (cs -> cs .getState () != null && cs .getState ().getWaiting () != null )
@@ -324,11 +313,14 @@ public static void logPodEvents(KubernetesClient client, Pod pod, Logger logger,
324313 .getItems ()
325314 .stream ()
326315 .filter (event -> "Warning" .equals (event .getType ()))
327- .sorted (Comparator .comparing (
328- Event ::getLastTimestamp ,
329- Comparator .nullsLast (Comparator .naturalOrder ())
330- ))
331- .forEach (event -> {
316+ .sorted (
317+ Comparator .comparing (
318+ Event ::getLastTimestamp ,
319+ Comparator .nullsLast (Comparator .naturalOrder ())
320+ )
321+ )
322+ .forEach (event ->
323+ {
332324 String reason = event .getReason () == null ? "" : event .getReason ();
333325 String message = event .getMessage () == null ? "" : event .getMessage ();
334326
@@ -348,8 +340,9 @@ public static boolean hasAnyContainerStarted(Pod pod) {
348340 return false ;
349341 }
350342 return pod .getStatus ().getContainerStatuses ().stream ()
351- .anyMatch (cs -> cs .getState () != null &&
352- (cs .getState ().getRunning () != null || cs .getState ().getTerminated () != null )
343+ .anyMatch (
344+ cs -> cs .getState () != null &&
345+ (cs .getState ().getRunning () != null || cs .getState ().getTerminated () != null )
353346 );
354347 }
355348
@@ -358,10 +351,11 @@ public static boolean hasNonTransientWaitingContainer(Pod pod) {
358351 return false ;
359352 }
360353 return pod .getStatus ().getContainerStatuses ().stream ()
361- .anyMatch (cs -> cs .getState () != null &&
362- cs .getState ().getWaiting () != null &&
363- cs .getState ().getWaiting ().getReason () != null &&
364- !TransientWaitingReason .contains (cs .getState ().getWaiting ().getReason ())
354+ .anyMatch (
355+ cs -> cs .getState () != null &&
356+ cs .getState ().getWaiting () != null &&
357+ cs .getState ().getWaiting ().getReason () != null &&
358+ !TransientWaitingReason .contains (cs .getState ().getWaiting ().getReason ())
365359 );
366360 }
367361
@@ -398,8 +392,12 @@ public enum PodPhase {
398392
399393 private final String value ;
400394
401- PodPhase (String value ) { this .value = value ; }
395+ PodPhase (String value ) {
396+ this .value = value ;
397+ }
402398
403- public String value () { return value ; }
399+ public String value () {
400+ return value ;
401+ }
404402 }
405403}
0 commit comments