Skip to content

Commit

Permalink
fix(provider/kubernetes): v2 check job failed (#2608)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander committed May 8, 2018
1 parent c82f94f commit 29c78d9
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import io.kubernetes.client.models.V1JobStatus;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import static com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.KubernetesHandler.DeployPriority.WORKLOAD_CONTROLLER_PRIORITY;

Expand Down Expand Up @@ -99,10 +101,13 @@ private Status status(V1Job job) {
if (status.getSucceeded() != null) {
succeeded = status.getSucceeded();
}

if (succeeded < completions) {
List<V1JobCondition> conditions = status.getConditions();
if (conditions != null && conditions.stream().anyMatch(this::jobDeadlineExceeded)) {
return result.failed("Job deadline exceeded");
conditions = conditions != null ? conditions : Collections.emptyList();
Optional<V1JobCondition> condition = conditions.stream().filter(this::jobFailed).findAny();
if (condition.isPresent()) {
return result.failed(condition.get().getMessage());
} else {
return result.unstable("Waiting for jobs to finish");
}
Expand All @@ -111,7 +116,7 @@ private Status status(V1Job job) {
return result;
}

private boolean jobDeadlineExceeded(V1JobCondition condition) {
return "DeadlineExceeded".equalsIgnoreCase(condition.getReason()) && "True".equalsIgnoreCase(condition.getStatus());
private boolean jobFailed(V1JobCondition condition) {
return "Failed".equalsIgnoreCase(condition.getType()) && "True".equalsIgnoreCase(condition.getStatus());
}
}

0 comments on commit 29c78d9

Please sign in to comment.