@@ -129,6 +129,18 @@ public static boolean isFailed(V1Job job) {
129
129
return false ;
130
130
}
131
131
132
+ public static String getFailedReason (V1Job job ) {
133
+ V1JobStatus status = job .getStatus ();
134
+ if (status != null && status .getConditions () != null ) {
135
+ for (V1JobCondition cond : status .getConditions ()) {
136
+ if ("Failed" .equals (cond .getType ()) && "True" .equals (cond .getStatus ())) {
137
+ return cond .getReason ();
138
+ }
139
+ }
140
+ }
141
+ return null ;
142
+ }
143
+
132
144
@ Override
133
145
public WatchI <V1Job > initiateWatch (WatchBuilder watchBuilder ) throws ApiException {
134
146
return watchBuilder
@@ -150,7 +162,7 @@ public void receivedResponse(Watch.Response<V1Job> item) {
150
162
if (isComplete || isFailed ) {
151
163
Complete complete = completeCallbackRegistrations .get (jobName );
152
164
if (complete != null ) {
153
- complete .isComplete (job );
165
+ complete .isComplete (job , isFailed );
154
166
}
155
167
}
156
168
break ;
@@ -175,7 +187,7 @@ public Step waitForReady(V1Job job, Step next) {
175
187
176
188
@ FunctionalInterface
177
189
private interface Complete {
178
- void isComplete (V1Job job );
190
+ void isComplete (V1Job job , boolean isJobFailed );
179
191
}
180
192
181
193
static class JobWatcherFactory {
@@ -231,14 +243,21 @@ public NextAction apply(Packet packet) {
231
243
return doSuspend (
232
244
(fiber ) -> {
233
245
Complete complete =
234
- (V1Job job ) -> {
246
+ (V1Job job , boolean isJobFailed ) -> {
235
247
if (!shouldProcessJob (job )) {
236
248
return ;
237
249
}
238
250
completeCallbackRegistrations .remove (job .getMetadata ().getName ());
239
251
if (didResume .compareAndSet (false , true )) {
240
252
LOGGER .fine ("Job status: " + job .getStatus ());
241
253
packet .put (ProcessingConstants .DOMAIN_INTROSPECTOR_JOB , job );
254
+ // Do not proceed to next step such as ReadDomainIntrospectorPodLog if job
255
+ // failed due to DeadlineExceeded, as the pod container would likely not
256
+ // be available for reading
257
+ if (isJobFailed && "DeadlineExceeded" .equals (getFailedReason (job ))) {
258
+ fiber .terminate (
259
+ new DeadlineExceededException (job .getMetadata ().getName ()), packet );
260
+ }
242
261
fiber .resume (packet );
243
262
}
244
263
};
@@ -283,4 +302,17 @@ public NextAction onSuccess(
283
302
});
284
303
}
285
304
}
305
+
306
+ static class DeadlineExceededException extends Exception {
307
+ final String job ;
308
+
309
+ public DeadlineExceededException (String job ) {
310
+ super ();
311
+ this .job = job ;
312
+ }
313
+
314
+ public String toString () {
315
+ return "Job " + job + " failed. Reason: DeadlineExceeded" ;
316
+ }
317
+ }
286
318
}
0 commit comments