Skip to content

Commit 80d49f0

Browse files
committed
skip rest of introspector steps if job failed with DeadlineExceeded
1 parent 1ed7fa6 commit 80d49f0

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

operator/src/main/java/oracle/kubernetes/operator/JobWatcher.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ public static boolean isFailed(V1Job job) {
129129
return false;
130130
}
131131

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+
132144
@Override
133145
public WatchI<V1Job> initiateWatch(WatchBuilder watchBuilder) throws ApiException {
134146
return watchBuilder
@@ -150,7 +162,7 @@ public void receivedResponse(Watch.Response<V1Job> item) {
150162
if (isComplete || isFailed) {
151163
Complete complete = completeCallbackRegistrations.get(jobName);
152164
if (complete != null) {
153-
complete.isComplete(job);
165+
complete.isComplete(job, isFailed);
154166
}
155167
}
156168
break;
@@ -175,7 +187,7 @@ public Step waitForReady(V1Job job, Step next) {
175187

176188
@FunctionalInterface
177189
private interface Complete {
178-
void isComplete(V1Job job);
190+
void isComplete(V1Job job, boolean isJobFailed);
179191
}
180192

181193
static class JobWatcherFactory {
@@ -231,14 +243,21 @@ public NextAction apply(Packet packet) {
231243
return doSuspend(
232244
(fiber) -> {
233245
Complete complete =
234-
(V1Job job) -> {
246+
(V1Job job, boolean isJobFailed) -> {
235247
if (!shouldProcessJob(job)) {
236248
return;
237249
}
238250
completeCallbackRegistrations.remove(job.getMetadata().getName());
239251
if (didResume.compareAndSet(false, true)) {
240252
LOGGER.fine("Job status: " + job.getStatus());
241253
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+
}
242261
fiber.resume(packet);
243262
}
244263
};
@@ -283,4 +302,17 @@ public NextAction onSuccess(
283302
});
284303
}
285304
}
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+
}
286318
}

0 commit comments

Comments
 (0)