From b2647cb540b2efd546a73d5eea1df2a41396458e Mon Sep 17 00:00:00 2001 From: Bartlomiej Antoniak Date: Mon, 7 May 2018 18:35:24 +0200 Subject: [PATCH] JENKINS-50664 added missing fixed jenkins slave labels --- .../plugins/kubernetes/PodTemplate.java | 3 ++- .../pipeline/KubernetesPipelineTest.java | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java index 64e0acf88b..dcab365dc4 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java @@ -345,9 +345,10 @@ public Set getLabelSet() { public Map getLabelsMap() { Set labelSet = getLabelSet(); - ImmutableMap.Builder builder = ImmutableMap. builder(); + ImmutableMap.Builder builder = ImmutableMap.builder(); if (!labelSet.isEmpty()) { for (LabelAtom label : labelSet) { + builder.put("jenkins/slave", "true"); builder.put(label == null ? DEFAULT_ID : "jenkins/" + label.getName(), "true"); } } diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java index 3fbc31a336..bcaa8cbaf6 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java @@ -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; @@ -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 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);