Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail faster if a pod enters in error state during provisioning #414

Merged
merged 1 commit into from
Dec 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,7 @@ public void launch(SlaveComputer computer, TaskListener listener) {
}
}

if (!terminatedContainers.isEmpty()) {
Map<String, Integer> errors = terminatedContainers.stream().collect(Collectors
.toMap(ContainerStatus::getName, (info) -> info.getState().getTerminated().getExitCode()));

// Print the last lines of failed containers
logLastLines(terminatedContainers, podId, namespace, slave, errors, client);
throw new IllegalStateException("Containers are terminated with exit codes: " + errors);
}
checkTerminatedContainers(terminatedContainers, podId, namespace, slave, client);

if (!allContainersAreReady) {
continue;
Expand Down Expand Up @@ -203,6 +196,23 @@ public void launch(SlaveComputer computer, TaskListener listener) {
break;
}

containerStatuses = pod.getStatus().getContainerStatuses();
List<ContainerStatus> terminatedContainers = new ArrayList<>();
for (ContainerStatus info : containerStatuses) {
if (info != null) {
if (info.getState().getTerminated() != null) {
// Container has errored
LOGGER.log(INFO, "Container is terminated {0} [{2}]: {1}",
new Object[]{podId, info.getState().getTerminated(), info.getName()});
logger.printf("Container is terminated %1$s [%3$s]: %2$s%n",
podId, info.getState().getTerminated(), info.getName());
terminatedContainers.add(info);
}
}
}

checkTerminatedContainers(terminatedContainers, podId, namespace, slave, client);

LOGGER.log(INFO, "Waiting for agent to connect ({1}/{2}): {0}",
new Object[]{podId, waitedForSlave, waitForSlaveToConnect});
logger.printf("Waiting for agent to connect (%2$s/%3$s): %1$s%n",
Expand Down Expand Up @@ -234,6 +244,18 @@ public void launch(SlaveComputer computer, TaskListener listener) {
}
}

private void checkTerminatedContainers(List<ContainerStatus> terminatedContainers, String podId, String namespace,
KubernetesSlave slave, KubernetesClient client) {
if (!terminatedContainers.isEmpty()) {
Map<String, Integer> errors = terminatedContainers.stream().collect(Collectors
.toMap(ContainerStatus::getName, (info) -> info.getState().getTerminated().getExitCode()));

// Print the last lines of failed containers
logLastLines(terminatedContainers, podId, namespace, slave, errors, client);
throw new IllegalStateException("Containers are terminated with exit codes: " + errors);
}
}

private Pod getPodTemplate(KubernetesClient client, KubernetesSlave slave, PodTemplate template) {
return template == null ? null : template.build(client, slave);
}
Expand Down