Skip to content

Commit

Permalink
Merge pull request #863 from Vlatombe/containerCap
Browse files Browse the repository at this point in the history
Make sure `containerCap` defaults to Integer.MAX_VALUE when starting from an empty `KubernetesCloud`
  • Loading branch information
Vlatombe authored Oct 9, 2020
2 parents 75b788a + 8545527 commit dedad44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public class KubernetesCloud extends Cloud {
private String jenkinsTunnel;
@CheckForNull
private String credentialsId;
private int containerCap = Integer.MAX_VALUE;
private Integer containerCap;
private int retentionTimeout = DEFAULT_RETENTION_TIMEOUT_MINUTES;
private int connectTimeout = DEFAULT_CONNECT_TIMEOUT_SECONDS;
private int readTimeout = DEFAULT_READ_TIMEOUT_SECONDS;
Expand Down Expand Up @@ -381,33 +381,21 @@ public void setCredentialsId(String credentialsId) {
}

public int getContainerCap() {
return containerCap;
return containerCap != null ? containerCap : Integer.MAX_VALUE;
}

@DataBoundSetter
public void setContainerCapStr(String containerCapStr) {
if (containerCapStr.equals("")) {
setContainerCap(Integer.MAX_VALUE);
} else {
setContainerCap(Integer.parseInt(containerCapStr));
}
setContainerCap(containerCapStr.equals("") ? null : Integer.parseInt(containerCapStr));
}

@DataBoundSetter
public void setContainerCap(int containerCap) {
if (containerCap < 0) {
this.containerCap = Integer.MAX_VALUE;
} else {
this.containerCap = containerCap;
}
public void setContainerCap(Integer containerCap) {
this.containerCap = (containerCap != null && containerCap >= 0) ? containerCap : null;
}

public String getContainerCapStr() {
if (containerCap == Integer.MAX_VALUE) {
return "";
} else {
return String.valueOf(containerCap);
}
// serialized Integer.MAX_VALUE means no limit
return (containerCap == null || containerCap == Integer.MAX_VALUE) ? "" : String.valueOf(containerCap);
}

public int getReadTimeout() {
Expand Down Expand Up @@ -586,6 +574,7 @@ public synchronized Collection<NodeProvisioner.PlannedNode> provision(@CheckForN
*
*/
private boolean addProvisionedSlave(@Nonnull PodTemplate template, @CheckForNull Label label, int scheduledCount) throws Exception {
int containerCap = getContainerCap();
if (containerCap == 0) {
return false;
}
Expand Down Expand Up @@ -725,7 +714,7 @@ public boolean equals(Object o) {
return skipTlsVerify == that.skipTlsVerify &&
addMasterProxyEnvVars == that.addMasterProxyEnvVars &&
capOnlyOnAlivePods == that.capOnlyOnAlivePods &&
containerCap == that.containerCap &&
Objects.equals(containerCap, that.containerCap) &&
retentionTimeout == that.retentionTimeout &&
connectTimeout == that.connectTimeout &&
readTimeout == that.readTimeout &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,13 @@ public void minRetentionTimeout() {

@Test
@LocalData
public void minRetentionTimeoutReadResolve() {
public void emptyKubernetesCloudReadResolve() {
KubernetesCloud cloud = j.jenkins.clouds.get(KubernetesCloud.class);
assertEquals(KubernetesCloud.DEFAULT_RETENTION_TIMEOUT_MINUTES, cloud.getRetentionTimeout());
assertEquals(Integer.MAX_VALUE, cloud.getContainerCap());
assertEquals(KubernetesCloud.DEFAULT_MAX_REQUESTS_PER_HOST, cloud.getMaxRequestsPerHost());
assertEquals(PodRetention.getKubernetesCloudDefault(), cloud.getPodRetention());
assertEquals(KubernetesCloud.DEFAULT_WAIT_FOR_POD_SEC, cloud.getWaitForPodSec());
}

public HtmlInput getInputByName(DomElement root, String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.1' encoding='UTF-8'?>
<hudson>
<disabledAdministrativeMonitors/>
<version>2.190.1</version>
<version>2.222.4</version>
<installStateName>DEVELOPMENT</installStateName>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
Expand Down

0 comments on commit dedad44

Please sign in to comment.