in src/main/java/com/epam/aidial/util/KubernetesUtils.java [34:64]
public boolean extractJobCompletionStatus(V1Job job) {
String name = job.getMetadata().getName();
V1JobStatus status = job.getStatus();
if (status != null && status.getConditions() != null) {
for (V1JobCondition condition : status.getConditions()) {
// From documentation (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#jobstatus-v1-batch):
// When a Job fails, one of the conditions will have type "Failed" and status true.
// When a Job is suspended, one of the conditions will have type "Suspended" and status true;
// when the Job is resumed, the status of this condition will become false.
// When a Job is completed, one of the conditions will have type "Complete" and status true.
if ("True".equals(condition.getStatus())) {
if ("Complete".equals(condition.getType())) {
return true;
}
if ("Failed".equals(condition.getType())) {
throw new IllegalStateException("Job %s has failed: %s".formatted(name, condition.getMessage()));
}
}
if (condition.getMessage() == null) {
log.info("Job: {}, status: {}", name, condition.getType());
} else {
log.info("Job: {}, status: {}, reason: {}, message: {}",
name, condition.getType(), condition.getReason(), condition.getMessage());
}
}
}
return false;
}