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

Make Slave 🠦 Jenkins conn. timeout configurable #141

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ public Node call() throws Exception {
throw new IllegalStateException("Container is not running after " + j + " attempts, status: " + status);
}

j = t.getSlaveConnectTimeout();

// now wait for slave to be online
for (; i < j; i++) {
if (slave.getComputer() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -39,6 +41,10 @@ public class PodTemplate extends AbstractDescribableImpl<PodTemplate> implements

private static final String FALLBACK_ARGUMENTS = "${computer.jnlpmac} ${computer.name}";

private static final Logger LOGGER = Logger.getLogger(PodTemplate.class.getName());

private static final int DEFAULT_SLAVE_JENKINS_CONNECTION_TIMEOUT = 100;

private String inheritFrom;

private String name;
Expand All @@ -57,6 +63,8 @@ public class PodTemplate extends AbstractDescribableImpl<PodTemplate> implements

private int instanceCap = Integer.MAX_VALUE;

private int slaveConnectTimeout = DEFAULT_SLAVE_JENKINS_CONNECTION_TIMEOUT;

private int idleMinutes;

private String label;
Expand Down Expand Up @@ -102,6 +110,7 @@ public PodTemplate(PodTemplate from) {
this.setInheritFrom(from.getInheritFrom());
this.setNodeSelector(from.getNodeSelector());
this.setServiceAccount(from.getServiceAccount());
this.setSlaveConnectTimeout(from.getSlaveConnectTimeout());
this.setVolumes(from.getVolumes());
this.setWorkspaceVolume(from.getWorkspaceVolume());
}
Expand Down Expand Up @@ -202,6 +211,23 @@ public int getInstanceCap() {
return instanceCap;
}

public void setSlaveConnectTimeout(int slaveConnectTimeout) {
if (slaveConnectTimeout <= 0) {
LOGGER.log(Level.WARNING, "Slave -> Jenkins connection timeout " +
"cannot be <= 0. Falling back to the default value: " +
DEFAULT_SLAVE_JENKINS_CONNECTION_TIMEOUT);
this.slaveConnectTimeout = DEFAULT_SLAVE_JENKINS_CONNECTION_TIMEOUT;
} else {
this.slaveConnectTimeout = slaveConnectTimeout;
}
}

public int getSlaveConnectTimeout() {
if (slaveConnectTimeout == 0)
return DEFAULT_SLAVE_JENKINS_CONNECTION_TIMEOUT;
return slaveConnectTimeout;
}

@DataBoundSetter
public void setInstanceCapStr(String instanceCapStr) {
if (StringUtils.isBlank(instanceCapStr)) {
Expand All @@ -219,6 +245,19 @@ public String getInstanceCapStr() {
}
}

@DataBoundSetter
public void setSlaveConnectTimeoutStr(String slaveConnectTimeoutStr) {
if (StringUtils.isBlank(slaveConnectTimeoutStr)) {
setSlaveConnectTimeout(DEFAULT_SLAVE_JENKINS_CONNECTION_TIMEOUT);
} else {
setSlaveConnectTimeout(Integer.parseInt(slaveConnectTimeoutStr));
}
}

public String getSlaveConnectTimeoutStr() {
return String.valueOf(slaveConnectTimeout);
}

public void setIdleMinutes(int i) {
this.idleMinutes = i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<f:textbox/>
</f:entry>

<f:entry field="slaveConnectTimeoutStr" title="${%Timeout in seconds for Jenkins connection}">
<f:textbox/>
</f:entry>

<f:entry title="${%Annotations}" description="${%List of annotations to set in slave pod}" field="annotations">
<f:repeatableHeteroProperty field="annotations" hasHeader="true" addCaption="Add Annotation"
deleteCaption="Delete annotation Variable" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Specify time in seconds up to which Jenkins should wait for the JNLP slave to
estabilish a connection. Value should be a positive integer, default being 100.