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-50664] added missing fixed jenkins slave labels #320

Closed
wants to merge 1 commit into from
Closed
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 @@ -345,9 +345,10 @@ public Set<LabelAtom> getLabelSet() {

public Map<String, String> getLabelsMap() {
Set<LabelAtom> labelSet = getLabelSet();
ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
if (!labelSet.isEmpty()) {
for (LabelAtom label : labelSet) {
builder.put("jenkins/slave", "true");
Copy link

@hrishin hrishin May 11, 2018

Choose a reason for hiding this comment

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

Expecting default labels as follow, right?

labels:
   jenkins : 'slave'

rather than

labels:
   jenkins/slave : true

builder.put(label == null ? DEFAULT_ID : "jenkins/" + label.getName(), "true");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.csanchez.jenkins.plugins.kubernetes.pipeline;

import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.*;
import static org.hamcrest.Matchers.hasEntry;
import static org.junit.Assert.*;

import java.util.List;
Expand Down Expand Up @@ -54,6 +55,31 @@ public class KubernetesPipelineTest extends AbstractKubernetesPipelineTest {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();

@Test
public void verifyDefaultSlaveLabels() throws Exception {
deletePods(cloud.connect(), getLabels(this), false);

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runInPod.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
List<PodTemplate> templates = cloud.getAllTemplates();
while (hasPodTemplateWithLabel("mypod", templates)) {
LOGGER.log(Level.INFO, "Waiting for template to be created");
templates = cloud.getAllTemplates();
Thread.sleep(1000);
}
assertFalse(templates.isEmpty());
PodTemplate template = templates.get(0);

assertThat(template.getLabelsMap(), hasEntry("jenkins/slave", "true"));

r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("script file contents: ", b);
assertFalse("There are pods leftover after test execution, see previous logs",
deletePods(cloud.connect(), getLabels(this), true));
}

@Test
public void runInPod() throws Exception {
deletePods(cloud.connect(), getLabels(this), false);
Expand Down