From 230fc97ad50867b1291b68d2c98ca45e9dc9ee1a Mon Sep 17 00:00:00 2001 From: Matthew Ludlum Date: Wed, 6 Nov 2019 17:38:53 -0600 Subject: [PATCH] Placeholder Change-Id: I59b5f85d36e892be17d7a6a9bb214d68a07fa3d9 --- .../jenkins/plugins/kubernetes/PodLabel.java | 2 +- .../jenkins/plugins/kubernetes/PodTemplate.java | 14 +++++++------- .../pipeline/KubernetesPipelineTest.java | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodLabel.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodLabel.java index 6af8eaaeef..008dccfe77 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodLabel.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodLabel.java @@ -112,5 +112,5 @@ public static class DescriptorImpl extends Descriptor { public String getDisplayName() { return "Pod Label"; } - } + } } 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 1c75d0682f..08cf38a304 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java @@ -75,9 +75,9 @@ public class PodTemplate extends AbstractDescribableImpl implements private String image; private boolean privileged; - + private Long runAsUser; - + private Long runAsGroup; private boolean capOnlyOnAlivePods; @@ -381,7 +381,7 @@ public Map getLabelsMap() { ImmutableMap.Builder builder = ImmutableMap. builder(); if (!labelSet.isEmpty()) { for (LabelAtom label : labelSet) { - builder.put(label == null ? DEFAULT_ID : "jenkins/" + label.getName(), "true"); + builder.put("jenkins/label",label == null ? DEFAULT_ID : label.getName()); } } return builder.build(); @@ -434,7 +434,7 @@ public boolean isPrivileged() { public void setRunAsUser(String runAsUser) { this.runAsUser = PodTemplateUtils.parseLong(runAsUser); } - + public String getRunAsUser() { return runAsUser == null ? null : runAsUser.toString(); } @@ -734,12 +734,12 @@ protected Object readResolve() { containerTemplate.setWorkingDir(remoteFs); containers.add(containerTemplate); } - + if (podRetention == null) { // https://issues.jenkins-ci.org/browse/JENKINS-53260 - // various legacy paths for injecting pod templates can + // various legacy paths for injecting pod templates can // bypass the defaulting paths and the - // value can still be null, so check for it here so + // value can still be null, so check for it here so // as to not blow up things like termination path podRetention = PodRetention.getPodTemplateDefault(); } 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 de5cd84179..329116c710 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 @@ -142,12 +142,12 @@ public void runInPod() throws Exception { } assertTrue(foundBuildUrl); assertEquals(Integer.MAX_VALUE, template.getInstanceCap()); - assertThat(template.getLabelsMap(), hasEntry("jenkins/" + name.getMethodName(), "true")); + assertThat(template.getLabelsMap(), hasEntry("jenkins/label", name.getMethodName())); Pod pod = pods.getItems().get(0); LOGGER.log(Level.INFO, "One pod found: {0}", pod); assertThat(pod.getMetadata().getLabels(), hasEntry("jenkins", "slave")); - assertThat("Pod labels are wrong: " + pod, pod.getMetadata().getLabels(), hasEntry("jenkins/" + name.getMethodName(), "true")); + assertThat("Pod labels are wrong: " + pod, pod.getMetadata().getLabels(), hasEntry("jenkins/label", name.getMethodName())); r.assertBuildStatusSuccess(r.waitForCompletion(b)); r.assertLogContains("script file contents: ", b); @@ -167,10 +167,10 @@ public void runIn2Pods() throws Exception { PodTemplate template1 = podTemplatesWithLabel(label1, cloud.getAllTemplates()).get(0); SemaphoreStep.success("podTemplate1/1", null); assertEquals(Integer.MAX_VALUE, template1.getInstanceCap()); - assertThat(template1.getLabelsMap(), hasEntry("jenkins/" + label1, "true")); + assertThat(template1.getLabelsMap(), hasEntry("jenkins/label", label1)); SemaphoreStep.waitForStart("pod1/1", b); Map labels1 = getLabels(cloud, this, name); - labels1.put("jenkins/"+label1, "true"); + labels1.put("jenkins/label","jenkins/"+label1); PodList pods = cloud.connect().pods().withLabels(labels1).list(); assertTrue(!pods.getItems().isEmpty()); SemaphoreStep.success("pod1/1", null); @@ -180,11 +180,11 @@ public void runIn2Pods() throws Exception { PodTemplate template2 = podTemplatesWithLabel(label2, cloud.getAllTemplates()).get(0); SemaphoreStep.success("podTemplate2/1", null); assertEquals(Integer.MAX_VALUE, template2.getInstanceCap()); - assertThat(template2.getLabelsMap(), hasEntry("jenkins/" + label2, "true")); + assertThat(template2.getLabelsMap(), hasEntry("jenkins/label", label2)); assertNull(label2 + " should not inherit from anything", template2.getInheritFrom()); SemaphoreStep.waitForStart("pod2/1", b); Map labels2 = getLabels(cloud, this, name); - labels1.put("jenkins/" + label2, "true"); + labels1.put("jenkins/label", label2); PodList pods2 = cloud.connect().pods().withLabels(labels2).list(); assertTrue(!pods2.getItems().isEmpty()); SemaphoreStep.success("pod2/1", null); @@ -436,7 +436,7 @@ private void assertNotXPath(HtmlPage page, String xpath) { HtmlElement documentElement = page.getDocumentElement(); assertNull("There should not be an object that matches XPath:" + xpath, DomNodeUtil.selectSingleNode(documentElement, xpath)); } - + @Issue("JENKINS-57717") @Test public void runInPodWithShowRawYamlFalse() throws Exception {