Skip to content

Commit

Permalink
Terminate instances immediately if they fail to launch. This gets rid…
Browse files Browse the repository at this point in the history
… of zombie offline nodes in jenkins that failed to start in the cloud.
  • Loading branch information
Theoderich committed Nov 7, 2024
1 parent b14ecd1 commit 5ba199e
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,16 @@ public void launch(SlaveComputer slaveComputer, TaskListener listener) {
}
if (opError != null) {
LOGGER.info(String.format(
"Launch failed while waiting for operation %s to complete. Operation error was %s",
"Launch failed while waiting for operation %s to complete. Operation error was %s. Terminating instance.",
insertOperationId, opError.getErrors().get(0).getMessage()));
terminateNode(computer, listener);
return;
}
} catch (InterruptedException e) {
LOGGER.info(String.format(
"Launch failed while waiting for operation %s to complete. Operation error was %s",
"Launch failed while waiting for operation %s to complete. Operation error was %s. Terminating instance",
insertOperationId, opError.getErrors().get(0).getMessage()));
terminateNode(computer, listener);
return;
}

Expand Down Expand Up @@ -214,19 +216,23 @@ public void launch(SlaveComputer slaveComputer, TaskListener listener) {
launch(computer, listener);
} catch (IOException ioe) {
ioe.printStackTrace(listener.error(ioe.getMessage()));
node = (ComputeEngineInstance) slaveComputer.getNode();
if (node != null) {
try {
node.terminate();
} catch (Exception e) {
listener.error(String.format("Failed to terminate node %s", node.getDisplayName()));
}
}
terminateNode(slaveComputer, listener);
} catch (InterruptedException ie) {

}
}

private static void terminateNode(SlaveComputer slaveComputer, TaskListener listener) {
ComputeEngineInstance node = (ComputeEngineInstance) slaveComputer.getNode();

Check warning on line 226 in src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineComputerLauncher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 159-226 are not covered by tests
if (node != null) {
try {
node.terminate();
} catch (Exception e) {
listener.error(String.format("Failed to terminate node %s", node.getDisplayName()));
}
}
}

private boolean testCommand(
ComputeEngineComputer computer,
Connection conn,
Expand Down

0 comments on commit 5ba199e

Please sign in to comment.