@@ -155,14 +155,7 @@ public void launch(SlaveComputer computer, TaskListener listener) {
155
155
}
156
156
}
157
157
158
- if (!terminatedContainers .isEmpty ()) {
159
- Map <String , Integer > errors = terminatedContainers .stream ().collect (Collectors
160
- .toMap (ContainerStatus ::getName , (info ) -> info .getState ().getTerminated ().getExitCode ()));
161
-
162
- // Print the last lines of failed containers
163
- logLastLines (terminatedContainers , podId , namespace , slave , errors , client );
164
- throw new IllegalStateException ("Containers are terminated with exit codes: " + errors );
165
- }
158
+ checkTerminatedContainers (terminatedContainers , podId , namespace , slave , client );
166
159
167
160
if (!allContainersAreReady ) {
168
161
continue ;
@@ -203,6 +196,23 @@ public void launch(SlaveComputer computer, TaskListener listener) {
203
196
break ;
204
197
}
205
198
199
+ containerStatuses = pod .getStatus ().getContainerStatuses ();
200
+ List <ContainerStatus > terminatedContainers = new ArrayList <>();
201
+ for (ContainerStatus info : containerStatuses ) {
202
+ if (info != null ) {
203
+ if (info .getState ().getTerminated () != null ) {
204
+ // Container has errored
205
+ LOGGER .log (INFO , "Container is terminated {0} [{2}]: {1}" ,
206
+ new Object []{podId , info .getState ().getTerminated (), info .getName ()});
207
+ logger .printf ("Container is terminated %1$s [%3$s]: %2$s%n" ,
208
+ podId , info .getState ().getTerminated (), info .getName ());
209
+ terminatedContainers .add (info );
210
+ }
211
+ }
212
+ }
213
+
214
+ checkTerminatedContainers (terminatedContainers , podId , namespace , slave , client );
215
+
206
216
LOGGER .log (INFO , "Waiting for agent to connect ({1}/{2}): {0}" ,
207
217
new Object []{podId , waitedForSlave , waitForSlaveToConnect });
208
218
logger .printf ("Waiting for agent to connect (%2$s/%3$s): %1$s%n" ,
@@ -234,6 +244,18 @@ public void launch(SlaveComputer computer, TaskListener listener) {
234
244
}
235
245
}
236
246
247
+ private void checkTerminatedContainers (List <ContainerStatus > terminatedContainers , String podId , String namespace ,
248
+ KubernetesSlave slave , KubernetesClient client ) {
249
+ if (!terminatedContainers .isEmpty ()) {
250
+ Map <String , Integer > errors = terminatedContainers .stream ().collect (Collectors
251
+ .toMap (ContainerStatus ::getName , (info ) -> info .getState ().getTerminated ().getExitCode ()));
252
+
253
+ // Print the last lines of failed containers
254
+ logLastLines (terminatedContainers , podId , namespace , slave , errors , client );
255
+ throw new IllegalStateException ("Containers are terminated with exit codes: " + errors );
256
+ }
257
+ }
258
+
237
259
private Pod getPodTemplate (KubernetesClient client , KubernetesSlave slave , PodTemplate template ) {
238
260
return template == null ? null : template .build (client , slave );
239
261
}
0 commit comments