Skip to content

Commit

Permalink
[JENKINS-60537] Fix support of pod templates with multiple labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe committed Dec 19, 2019
1 parent 922ecf3 commit 89d6282
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,7 @@ public Set<LabelAtom> getLabelSet() {
}

public Map<String, String> getLabelsMap() {
Set<LabelAtom> labelSet = getLabelSet();
ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder();
if (!labelSet.isEmpty()) {
for (LabelAtom label : labelSet) {
builder.put("jenkins/label",label == null ? DEFAULT_ID : label.getName());
}
}
return builder.build();
return ImmutableMap.of("jenkins/label", label == null ? DEFAULT_ID : label);
}

@DataBoundSetter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.csanchez.jenkins.plugins.kubernetes;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.assertEquals;

public class PodTemplateJenkinsTest {
@Rule
public JenkinsRule j = new JenkinsRule();

@Test
@Issue("JENKINS-60537")
public void singleLabel() {
PodTemplate podTemplate = new PodTemplate();
podTemplate.setLabel("foo");
assertEquals("foo" , podTemplate.getLabelsMap().get("jenkins/label"));
}

@Test
@Issue("JENKINS-60537")
public void multiLabel() {
PodTemplate podTemplate = new PodTemplate();
podTemplate.setLabel("foo bar");
assertEquals("foo bar", podTemplate.getLabelsMap().get("jenkins/label"));
}
}

1 comment on commit 89d6282

@guipal
Copy link

@guipal guipal commented on 89d6282 Jan 8, 2020

Choose a reason for hiding this comment

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

Hello.

Have you tried this fix on kubernetes?

API is complaining Error from server (BadRequest): Unable to find "/v1, Resource=pods" that match label selector "jenkins=slave,jenkins/label=base linux", field selector "": found 'linux', expected: ',' or 'end of string'

Basically kubernetes api is not able to handle labels separated by blank space.

Best.

Please sign in to comment.