From a6c4541644473bc677d56bc38ac74e14bd7e7b4a Mon Sep 17 00:00:00 2001 From: bajacondor Date: Sat, 26 Aug 2017 16:55:57 -0700 Subject: [PATCH 1/3] Add podAnnotations to combined pod template --- .../jenkins/plugins/kubernetes/PodTemplateUtils.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java index 8219784551..60b2d722fa 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java @@ -19,6 +19,7 @@ import org.csanchez.jenkins.plugins.kubernetes.volumes.PodVolume; import org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.WorkspaceVolume; + import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -88,7 +89,11 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) { String nodeSelector = Strings.isNullOrEmpty(template.getNodeSelector()) ? parent.getNodeSelector() : template.getNodeSelector(); String serviceAccount = Strings.isNullOrEmpty(template.getServiceAccount()) ? parent.getServiceAccount() : template.getServiceAccount(); Node.Mode nodeUsageMode = template.getNodeUsageMode() == null ? parent.getNodeUsageMode() : template.getNodeUsageMode(); - + + Set podAnnotaions = new LinkedHashSet<>(); + podAnnotations.addAll(parent.getAnnotations()); + podAnnotations.addAll(template.getAnnotations()); + Set imagePullSecrets = new LinkedHashSet<>(); imagePullSecrets.addAll(parent.getImagePullSecrets()); imagePullSecrets.addAll(template.getImagePullSecrets()); @@ -124,6 +129,7 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) { podTemplate.setWorkspaceVolume(workspaceVolume); podTemplate.setVolumes(new ArrayList<>(combinedVolumes.values())); podTemplate.setImagePullSecrets(new ArrayList<>(imagePullSecrets)); + podTemplate.setAnnotations(new ArrayList<>(podAnnotations)); podTemplate.setNodeProperties(toolLocationNodeProperties); podTemplate.setNodeUsageMode(nodeUsageMode); From 94b1f28b9fda34dec63b07994ccbe286d4913429 Mon Sep 17 00:00:00 2001 From: bajacondor Date: Mon, 28 Aug 2017 16:59:24 -0700 Subject: [PATCH 2/3] Update PodTemplateUtils.java --- .../csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java index 60b2d722fa..1f46530ff2 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java @@ -90,7 +90,7 @@ public static PodTemplate combine(PodTemplate parent, PodTemplate template) { String serviceAccount = Strings.isNullOrEmpty(template.getServiceAccount()) ? parent.getServiceAccount() : template.getServiceAccount(); Node.Mode nodeUsageMode = template.getNodeUsageMode() == null ? parent.getNodeUsageMode() : template.getNodeUsageMode(); - Set podAnnotaions = new LinkedHashSet<>(); + Set podAnnotations = new LinkedHashSet<>(); podAnnotations.addAll(parent.getAnnotations()); podAnnotations.addAll(template.getAnnotations()); From aa731c142d6b622b809b4115fea9225de94d9d6e Mon Sep 17 00:00:00 2001 From: David Schile Date: Fri, 1 Sep 2017 12:00:31 -0700 Subject: [PATCH 3/3] added test for combine pod annotations --- .../kubernetes/PodTemplateUtilsTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java index 32979a89e9..3ec106c644 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java @@ -43,6 +43,9 @@ public class PodTemplateUtilsTest { private static final PodImagePullSecret SECRET_2 = new PodImagePullSecret("secret2"); private static final PodImagePullSecret SECRET_3 = new PodImagePullSecret("secret3"); + private static final PodAnnotation ANNOTATION_1 = new PodAnnotation("key1", "value1"); + private static final PodAnnotation ANNOTATION_2 = new PodAnnotation("key2", "value2"); + private static final ContainerTemplate JNLP_1 = new ContainerTemplate("jnlp", "jnlp:1"); private static final ContainerTemplate JNLP_2 = new ContainerTemplate("jnlp", "jnlp:2"); @@ -144,6 +147,22 @@ public void shouldCombineAllImagePullSecrets() { } + @Test + public void shouldCombineAllAnnotations() { + PodTemplate parent = new PodTemplate(); + parent.setName("parent"); + parent.setNodeSelector("key:value"); + parent.setAnnotations(asList(ANNOTATION_1)); + + PodTemplate template1 = new PodTemplate(); + template1.setName("template"); + template1.setAnnotations(asList(ANNOTATION_2)); + + PodTemplate result = combine(parent, template1); + assertEquals(2, result.getAnnotations().size()); + } + + @Test public void shouldUnwrapParent() { PodTemplate parent = new PodTemplate();