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

[JENKINS-50268] instanceCap reached with preexisting pods #325

Merged
merged 1 commit into from
May 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateMap;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
import org.jenkinsci.plugins.plaincredentials.FileCredentials;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -325,9 +325,15 @@ public int getConnectTimeout() {
* Labels for all pods started by the plugin
*/
public Map<String, String> getLabels() {
return labels == null ? Collections.emptyMap() : labels;
return labels == null || labels.isEmpty() ? DEFAULT_POD_LABELS : labels;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the current value of DEFAULT_POD_LABELS, the problem would be the same if you have several Jenkins instances running in the same namespace.

Maybe the DEFAULT_POD_LABELS should contain a reference to the current Jenkins instance (root url?) and cloud name in order to disambiguate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like a good improvement :)

}

/**
* No UI yet, so this is never re-set
*
* @param labels
*/
// @DataBoundSetter
public void setLabels(Map<String, String> labels) {
this.labels = labels;
}
Expand Down Expand Up @@ -619,9 +625,6 @@ private Object readResolve() {
if (maxRequestsPerHost == 0) {
maxRequestsPerHost = DEFAULT_MAX_REQUESTS_PER_HOST;
}
if (labels == null) {
labels = DEFAULT_POD_LABELS;
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.csanchez.jenkins.plugins.kubernetes;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import java.util.Arrays;
Expand All @@ -40,9 +41,7 @@
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey;
import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;

Expand All @@ -62,8 +61,8 @@ public class KubernetesTest {

@Before
public void before() throws Exception {
cloud = r.jenkins.clouds.get(KubernetesCloud.class);
r.configRoundtrip();
cloud = r.jenkins.clouds.get(KubernetesCloud.class);
}

@Test
Expand All @@ -77,6 +76,7 @@ public void upgradeFrom_1_1() throws Exception {
FileSystemServiceAccountCredential cred1 = (FileSystemServiceAccountCredential) credentials.get(1);
StringCredentialsImpl cred2 = (StringCredentialsImpl) credentials.get(2);
assertEquals("mytoken", Secret.toString(cred2.getSecret()));
assertThat(cloud.getLabels(), hasEntry("jenkins", "slave"));
}

@Test
Expand Down