Skip to content

Commit

Permalink
Merge pull request #412 from jenkinsci/do-not-wait-if-pod-errored
Browse files Browse the repository at this point in the history
Do not wait for agent connection if pod has failed
  • Loading branch information
carlossg authored Dec 19, 2018
2 parents 2641f3d + 56bac79 commit 14a420b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
buildPlugin()
buildPlugin(platforms: ['linux'])
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void launch(SlaveComputer computer, TaskListener listener) {
logger.printf("Waiting for Pod to be scheduled (%2$s/%3$s): %1$s%n", podId, waitedSec, waitForPodSec);

Thread.sleep(1000);
++waitedSec;
pod = client.pods().inNamespace(namespace).withName(podId).get();
if (pod == null) {
throw new IllegalStateException("Pod no longer exists: " + podId);
Expand Down Expand Up @@ -165,7 +166,6 @@ public void launch(SlaveComputer computer, TaskListener listener) {
break;
}

++waitedSec;
} while (waitedSec < waitForPodSec);
String status = pod.getStatus().getPhase();
if (!validStates.contains(status)) {
Expand All @@ -174,26 +174,39 @@ public void launch(SlaveComputer computer, TaskListener listener) {
}

int waitForSlaveToConnect = unwrappedTemplate.getSlaveConnectTimeout();
int waitedForSlave;

// now wait for agent to be online
for (int waitedForSlave = 0; waitedForSlave < waitForSlaveToConnect; waitedForSlave++) {
SlaveComputer slaveComputer = slave.getComputer();
SlaveComputer slaveComputer = null;
for (waitedForSlave = 0; waitedForSlave < waitForSlaveToConnect; waitedForSlave++) {
slaveComputer = slave.getComputer();
if (slaveComputer == null) {
throw new IllegalStateException("Node was deleted, computer is null");
}
if (slaveComputer.isOnline()) {
break;
}

// Check that the pod hasn't failed already
pod = client.pods().inNamespace(namespace).withName(podId).get();
if (pod == null) {
throw new IllegalStateException("Pod no longer exists: " + podId);
}
status = pod.getStatus().getPhase();
if (!validStates.contains(status)) {
break;
}

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",
podId, waitedForSlave, waitForSlaveToConnect);
Thread.sleep(1000);
}
if (slave.getComputer() == null || slave.getComputer().isOffline()) {
if (slaveComputer == null || slaveComputer.isOffline()) {
logLastLines(containerStatuses, podId, namespace, slave, null, client);
throw new IllegalStateException(
"Agent is not connected after " + waitForSlaveToConnect + " seconds, status: " + status);
"Agent is not connected after " + waitedForSlave + " seconds, status: " + status);
}
computer.setAcceptingTasks(true);
} catch (Throwable ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private static KubernetesCloud getKubernetesCloud(String cloudName) {
if (cloud instanceof KubernetesCloud) {
return (KubernetesCloud) cloud;
} else {
throw new IllegalStateException(KubernetesSlave.class.getName() + " can be launched only by instances of " + KubernetesCloud.class.getName());
throw new IllegalStateException(KubernetesSlave.class.getName() + " can be launched only by instances of " + KubernetesCloud.class.getName() + ". Cloud is " + cloud.getClass().getName());
}
}

Expand Down

0 comments on commit 14a420b

Please sign in to comment.