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

Do not wait for agent connection if pod has failed #412

Merged
merged 3 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
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
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