From d17ccd7ae0941d2764791565640778c1f20cc3b8 Mon Sep 17 00:00:00 2001 From: Austin Moore Date: Tue, 6 Dec 2016 10:09:52 -0500 Subject: [PATCH 1/6] Add annotations configuration field to podTemplate --- .../jenkins/plugins/kubernetes/PodAnnotation.java | 2 ++ .../plugins/kubernetes/pipeline/PodTemplateStep.java | 11 +++++++++++ .../kubernetes/pipeline/PodTemplateStepExecution.java | 1 + 3 files changed, 14 insertions(+) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodAnnotation.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodAnnotation.java index 4d9ef24f78..009444c9b6 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodAnnotation.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodAnnotation.java @@ -3,6 +3,7 @@ import hudson.Extension; import hudson.model.AbstractDescribableImpl; import hudson.model.Descriptor; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import java.io.Serializable; @@ -37,6 +38,7 @@ public void setValue(String value) { } @Extension + @Symbol("podAnnotation") public static class DescriptorImpl extends Descriptor { @Override public String getDisplayName() { diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep.java index 3519db94f6..fdfa6dd00a 100755 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep.java @@ -6,6 +6,7 @@ import java.util.Set; import org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate; +import org.csanchez.jenkins.plugins.kubernetes.PodAnnotation; import org.csanchez.jenkins.plugins.kubernetes.volumes.PodVolume; import org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.WorkspaceVolume; import org.jenkinsci.plugins.workflow.steps.Step; @@ -36,6 +37,7 @@ public class PodTemplateStep extends Step implements Serializable { private List containers = new ArrayList<>(); private List volumes = new ArrayList(); private WorkspaceVolume workspaceVolume; + private List annotations = new ArrayList<>(); private int instanceCap; private String serviceAccount; @@ -142,6 +144,15 @@ public StepExecution start(StepContext context) throws Exception { return new PodTemplateStepExecution(this, context); } + public List getAnnotations() { + return annotations; + } + + @DataBoundSetter + public void setAnnotations(List annotations) { + this.annotations = annotations; + } + @Extension public static class DescriptorImpl extends StepDescriptor { diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecution.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecution.java index 7c22ed8f43..b74e54d46a 100755 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecution.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStepExecution.java @@ -59,6 +59,7 @@ public boolean start() throws Exception { newTemplate.setContainers(step.getContainers()); newTemplate.setNodeSelector(step.getNodeSelector()); newTemplate.setServiceAccount(step.getServiceAccount()); + newTemplate.setAnnotations(step.getAnnotations()); kubernetesCloud.addTemplate(newTemplate); getContext().newBodyInvoker().withContext(step).withCallback(new PodTemplateCallback(newTemplate)).start(); From f8ed599f0e1cc2da51ef4b6e793bb6a913ff18e7 Mon Sep 17 00:00:00 2001 From: Austin Moore Date: Tue, 6 Dec 2016 10:20:27 -0500 Subject: [PATCH 2/6] Add info about annotations to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 78d06634a7..eee512fb57 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Either way it provides access to the following fields: * **nodeSelector** The node selector of the pod. * **volumes** Volumes that are defined for the pod and are mounted by **ALL** containers. * **envVars*** Environment variables that are applied to **ALL** containers. +* **annotations** Annotations to apply to the pod. * **inheritFrom** List of one or more pod templates to inherit from *(more details below)*. The `containerTemplate` is a template of container that will be added to the pod. Again, its configurable via the user interface or via pipeline and allows you to set the following fields: From 32d441ae40781b43a4707e7cccbcf51a8041a44f Mon Sep 17 00:00:00 2001 From: Austin Moore Date: Wed, 1 Feb 2017 17:32:00 -0500 Subject: [PATCH 3/6] Add annotations to jelly --- .../plugins/kubernetes/pipeline/PodTemplateStep/config.jelly | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/config.jelly index 8e226df238..22aebc6e49 100755 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/config.jelly @@ -25,6 +25,11 @@ deleteCaption="Delete Volume" /> + + + + From ef4faebdfc3265e2f144855ef83884e93a33f1cf Mon Sep 17 00:00:00 2001 From: Austin Moore Date: Thu, 2 Feb 2017 11:20:36 -0500 Subject: [PATCH 4/6] Add annotations help blurb --- .../jenkins/plugins/kubernetes/PodTemplate/config.jelly | 2 +- .../plugins/kubernetes/PodTemplate/help-annotations.html | 2 ++ .../plugins/kubernetes/pipeline/PodTemplateStep/config.jelly | 2 +- .../kubernetes/pipeline/PodTemplateStep/help-annotations.html | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/help-annotations.html create mode 100644 src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/help-annotations.html diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/config.jelly index 14d4ef61cf..4153a56df8 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/config.jelly @@ -40,7 +40,7 @@ - + diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/help-annotations.html b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/help-annotations.html new file mode 100644 index 0000000000..48d793e01a --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/PodTemplate/help-annotations.html @@ -0,0 +1,2 @@ +Annotations to set on pod metadata
+https://kubernetes.io/docs/user-guide/annotations/ \ No newline at end of file diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/config.jelly index 22aebc6e49..0fa09500c5 100755 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/config.jelly @@ -25,7 +25,7 @@ deleteCaption="Delete Volume" />
- + diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/help-annotations.html b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/help-annotations.html new file mode 100644 index 0000000000..48d793e01a --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateStep/help-annotations.html @@ -0,0 +1,2 @@ +Annotations to set on pod metadata
+https://kubernetes.io/docs/user-guide/annotations/ \ No newline at end of file From 0c5f0211754e6f626724fef2d1454d5b2f6991c8 Mon Sep 17 00:00:00 2001 From: Austin Moore Date: Thu, 2 Feb 2017 11:26:21 -0500 Subject: [PATCH 5/6] Add annotations example to README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index eee512fb57..be47f0b305 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,10 @@ volumes: [ hostPathVolume(mountPath: '/etc/mount4', hostPath: '/mnt/my-mount'), nfsVolume(mountPath: '/etc/mount5', serverAddress: '127.0.0.1', serverPath: '/', readOnly: true), persistentVolumeClaim(mountPath: '/etc/mount6', claimName: 'myClaim', readOnly: true) +], +annotations: [ + podAnnotation(key: "my-key", value: "my-value") + ... ]) { ... } From cbe6fca5151a289b1ba0a7de02f4f92531f42d2b Mon Sep 17 00:00:00 2001 From: Austin Moore Date: Wed, 8 Feb 2017 10:24:22 -0500 Subject: [PATCH 6/6] Add annotations null check to readResolve to ensure smooth upgrade --- .../csanchez/jenkins/plugins/kubernetes/PodTemplate.java | 7 ++++++- 1 file changed, 6 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 5c9ec00d50..697d45aab0 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java @@ -82,7 +82,7 @@ public class PodTemplate extends AbstractDescribableImpl implements private final List envVars = new ArrayList(); - private final List annotations = new ArrayList(); + private List annotations = new ArrayList(); private final List imagePullSecrets = new ArrayList(); @@ -460,6 +460,11 @@ protected Object readResolve() { containerTemplate.setWorkingDir(remoteFs); containers.add(containerTemplate); } + + if (annotations == null) { + annotations = new ArrayList<>(); + } + return this; }