From 92fc68cb6160c651c2b06d7a9b9daa3dcd912fba Mon Sep 17 00:00:00 2001 From: Miguel Campos Date: Sat, 14 Aug 2021 18:25:23 +0200 Subject: [PATCH] Add support for subPath to all volume types Includes work from Miguel Campos (https://github.com/jenkinsci/kubernetes-plugin/pull/1024) refs JENKINS-46253 --- .../kubernetes/PodTemplateBuilder.java | 76 ++++++++----------- .../plugins/kubernetes/PodVolumes.java | 16 ++-- .../kubernetes/volumes/ConfigMapVolume.java | 21 +++-- .../kubernetes/volumes/EmptyDirVolume.java | 22 ++++-- .../kubernetes/volumes/HostPathVolume.java | 9 ++- .../plugins/kubernetes/volumes/NfsVolume.java | 22 ++++-- .../volumes/PersistentVolumeClaim.java | 23 ++++-- .../plugins/kubernetes/volumes/PodVolume.java | 9 ++- .../kubernetes/volumes/SecretVolume.java | 13 +++- .../volumes/ConfigMapVolume/config.jelly | 4 + .../volumes/ConfigMapVolume/help-subPath.html | 1 + .../volumes/EmptyDirVolume/config.jelly | 5 +- .../volumes/EmptyDirVolume/help-subPath.html | 1 + .../volumes/HostPathVolume/config.jelly | 5 +- .../volumes/HostPathVolume/help-subPath.html | 1 + .../kubernetes/volumes/NfsVolume/config.jelly | 3 + .../volumes/NfsVolume/help-subPath.html | 1 + .../PersistentVolumeClaim/config.jelly | 5 +- .../PersistentVolumeClaim/help-subPath.html | 1 + .../volumes/SecretVolume/config.jelly | 4 + .../volumes/SecretVolume/help-subPath.html | 1 + .../kubernetes/KubernetesCloudTest.java | 31 ++------ .../kubernetes/PodTemplateBuilderTest.java | 66 ++++++---------- .../kubernetes/PodTemplateUtilsTest.java | 55 +++++--------- 24 files changed, 199 insertions(+), 196 deletions(-) create mode 100644 src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume/help-subPath.html create mode 100644 src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume/help-subPath.html create mode 100644 src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume/help-subPath.html create mode 100644 src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume/help-subPath.html create mode 100644 src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim/help-subPath.html create mode 100644 src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume/help-subPath.html diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java index d4c6737782..8df42d3abe 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java @@ -24,24 +24,16 @@ package org.csanchez.jenkins.plugins.kubernetes; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import hudson.TcpSlaveAgentListener; import hudson.Util; -import io.fabric8.kubernetes.api.model.PodSpecFluent; +import hudson.slaves.SlaveComputer; +import io.fabric8.kubernetes.api.model.*; +import io.fabric8.kubernetes.api.model.PodFluent.MetadataNested; +import io.fabric8.kubernetes.api.model.PodFluent.SpecNested; +import io.fabric8.kubernetes.client.utils.Serialization; +import io.jenkins.lib.versionnumber.JavaSpecificationVersion; +import jenkins.model.Jenkins; import org.apache.commons.lang.StringUtils; import org.csanchez.jenkins.plugins.kubernetes.model.TemplateEnvVar; import org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateStepExecution; @@ -50,37 +42,19 @@ import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; -import hudson.TcpSlaveAgentListener; -import hudson.slaves.SlaveComputer; -import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.ContainerBuilder; -import io.fabric8.kubernetes.api.model.ContainerPort; -import io.fabric8.kubernetes.api.model.EnvVar; -import io.fabric8.kubernetes.api.model.ExecAction; -import io.fabric8.kubernetes.api.model.LocalObjectReference; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.PodBuilder; -import io.fabric8.kubernetes.api.model.PodFluent.MetadataNested; -import io.fabric8.kubernetes.api.model.PodFluent.SpecNested; -import io.fabric8.kubernetes.api.model.Probe; -import io.fabric8.kubernetes.api.model.ProbeBuilder; -import io.fabric8.kubernetes.api.model.Quantity; -import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; -import io.fabric8.kubernetes.api.model.Volume; -import io.fabric8.kubernetes.api.model.VolumeMount; -import io.fabric8.kubernetes.api.model.VolumeMountBuilder; -import io.fabric8.kubernetes.client.utils.Serialization; -import io.jenkins.lib.versionnumber.JavaSpecificationVersion; -import jenkins.model.Jenkins; - import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import java.nio.file.Paths; +import java.util.*; +import java.util.function.Function; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; import static org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud.JNLP_NAME; -import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.combine; -import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.isNullOrEmpty; -import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.substituteEnv; +import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.*; /** * Helper class to build Pods from PodTemplates @@ -173,8 +147,20 @@ public Pod build() { //We need to normalize the path or we can end up in really hard to debug issues. final String mountPath = substituteEnv(Paths.get(volume.getMountPath()).normalize().toString().replace("\\", "/")); if (!volumeMounts.containsKey(mountPath)) { - volumeMounts.put(mountPath, new VolumeMountBuilder() // - .withMountPath(mountPath).withName(volumeName).withReadOnly(false).build()); + VolumeMountBuilder volumeMountBuilder = new VolumeMountBuilder() // + .withMountPath(mountPath) + .withName(volumeName) + .withReadOnly(false); + + final String volumeSubPath = volume.getSubPath(); + if (StringUtils.isNotBlank(volumeSubPath)) { + // We need to normalize the subPath, or we can end up in really hard to debug issues Just in case. + final String subPath = substituteEnv(Paths.get(volumeSubPath).normalize().toString().replace("\\", "/")); + if (StringUtils.isNotBlank(subPath)) { + volumeMountBuilder = volumeMountBuilder.withSubPath(subPath); + } + } + volumeMounts.put(mountPath, volumeMountBuilder.build()); volumes.put(volumeName, volume.buildVolume(volumeName)); i++; } diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodVolumes.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodVolumes.java index 834e203e42..11d36196a0 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodVolumes.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodVolumes.java @@ -1,9 +1,9 @@ package org.csanchez.jenkins.plugins.kubernetes; -import java.util.List; - import io.fabric8.kubernetes.api.model.VolumeMount; +import java.util.List; + @Deprecated public class PodVolumes { @@ -15,12 +15,12 @@ public static abstract class PodVolume extends org.csanchez.jenkins.plugins.kube public static class EmptyDirVolume extends org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume { public EmptyDirVolume(String mountPath, Boolean memory) { - super(mountPath, memory); + super(mountPath, memory, null); } protected Object readResolve() { return new org.csanchez.jenkins.plugins.kubernetes.volumes.EmptyDirVolume(this.getMountPath(), - this.getMemory()); + this.getMemory(), null); } } @@ -41,12 +41,12 @@ protected Object readResolve() { public static class HostPathVolume extends org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume { public HostPathVolume(String hostPath, String mountPath) { - super(hostPath, mountPath); + super(hostPath, mountPath, null); } protected Object readResolve() { return new org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume(this.getHostPath(), - this.getMountPath()); + this.getMountPath(), null); } } @@ -54,12 +54,12 @@ protected Object readResolve() { public static class NfsVolume extends org.csanchez.jenkins.plugins.kubernetes.volumes.NfsVolume { public NfsVolume(String serverAddress, String serverPath, Boolean readOnly, String mountPath) { - super(serverAddress, serverPath, readOnly, mountPath); + super(serverAddress, serverPath, readOnly, mountPath, null); } protected Object readResolve() { return new org.csanchez.jenkins.plugins.kubernetes.volumes.NfsVolume(this.getServerAddress(), - this.getServerPath(), this.getReadOnly(), this.getMountPath()); + this.getServerPath(), this.getReadOnly(), this.getMountPath(), null); } } diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume.java index 3360c03e99..405bd0f6aa 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume.java @@ -24,26 +24,31 @@ package org.csanchez.jenkins.plugins.kubernetes.volumes; -import org.jenkinsci.Symbol; -import org.kohsuke.stapler.DataBoundConstructor; - import hudson.Extension; import hudson.model.Descriptor; import io.fabric8.kubernetes.api.model.Volume; import io.fabric8.kubernetes.api.model.VolumeBuilder; +import org.jenkinsci.Symbol; +import org.kohsuke.stapler.DataBoundConstructor; public class ConfigMapVolume extends PodVolume { private String mountPath; + private String subPath; private String configMapName; private Boolean optional; - @DataBoundConstructor - public ConfigMapVolume(String mountPath, String configMapName, Boolean optional) { + @DataBoundConstructor + public ConfigMapVolume(String mountPath, String configMapName, Boolean optional, String subPath) { this.mountPath = mountPath; + this.subPath = subPath; this.configMapName = configMapName; this.optional = optional; } + + public ConfigMapVolume(String mountPath, String configMapName, Boolean optional) { + this(mountPath, configMapName, optional, (String) null); + } @Override public Volume buildVolume(String volumeName) { @@ -68,7 +73,11 @@ public String getMountPath() { public Boolean getOptional() { return optional; } - + + public String getSubPath() { + return subPath; + } + @Extension @Symbol("configMapVolume") public static class DescriptorImpl extends Descriptor { diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume.java index 4f1297c4a7..8c18b94032 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume.java @@ -24,16 +24,15 @@ package org.csanchez.jenkins.plugins.kubernetes.volumes; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -import org.jenkinsci.Symbol; -import org.kohsuke.stapler.DataBoundConstructor; - import hudson.Extension; import hudson.model.Descriptor; import io.fabric8.kubernetes.api.model.Volume; import io.fabric8.kubernetes.api.model.VolumeBuilder; +import org.jenkinsci.Symbol; +import org.kohsuke.stapler.DataBoundConstructor; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; public class EmptyDirVolume extends PodVolume { @@ -43,11 +42,13 @@ public class EmptyDirVolume extends PodVolume { private String mountPath; @CheckForNull private Boolean memory; + private String subPath; @DataBoundConstructor - public EmptyDirVolume(String mountPath, Boolean memory) { + public EmptyDirVolume(String mountPath, Boolean memory, String subPath) { this.mountPath = mountPath; this.memory = memory; + this.subPath = subPath; } @Override @@ -55,6 +56,11 @@ public String getMountPath() { return mountPath; } + @Override + public String getSubPath() { + return subPath; + } + public String getMedium() { return getMemory() ? MEMORY_MEDIUM : DEFAULT_MEDIUM; } @@ -82,4 +88,4 @@ public String getDisplayName() { return "Empty Dir Volume"; } } -} \ No newline at end of file +} diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume.java index 6635434a89..3a7f46c002 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume.java @@ -34,12 +34,14 @@ public class HostPathVolume extends PodVolume { private String mountPath; + private String subPath; private String hostPath; @DataBoundConstructor - public HostPathVolume(String hostPath, String mountPath) { + public HostPathVolume(String hostPath, String mountPath, String subPath) { this.hostPath = hostPath; this.mountPath = mountPath; + this.subPath = subPath; } public Volume buildVolume(String volumeName) { @@ -53,6 +55,11 @@ public String getMountPath() { return mountPath; } + @Override + public String getSubPath() { + return subPath; + } + public String getHostPath() { return hostPath; } diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume.java index 6106b350fb..954f9fe14a 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume.java @@ -24,30 +24,31 @@ package org.csanchez.jenkins.plugins.kubernetes.volumes; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -import org.jenkinsci.Symbol; -import org.kohsuke.stapler.DataBoundConstructor; - import hudson.Extension; import hudson.model.Descriptor; import io.fabric8.kubernetes.api.model.Volume; import io.fabric8.kubernetes.api.model.VolumeBuilder; +import org.jenkinsci.Symbol; +import org.kohsuke.stapler.DataBoundConstructor; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; public class NfsVolume extends PodVolume { private String mountPath; + private String subPath; private String serverAddress; private String serverPath; @CheckForNull private Boolean readOnly; @DataBoundConstructor - public NfsVolume(String serverAddress, String serverPath, Boolean readOnly, String mountPath) { + public NfsVolume(String serverAddress, String serverPath, Boolean readOnly, String mountPath, String subPath) { this.serverAddress = serverAddress; this.serverPath = serverPath; this.readOnly = readOnly; this.mountPath = mountPath; + this.subPath = subPath; } public Volume buildVolume(String volumeName) { @@ -61,6 +62,11 @@ public String getMountPath() { return mountPath; } + @Override + public String getSubPath() { + return subPath; + } + public String getServerAddress() { return serverAddress; } @@ -82,4 +88,4 @@ public String getDisplayName() { return "NFS Volume"; } } -} \ No newline at end of file +} diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim.java index a0f029117b..2dc06002a3 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim.java @@ -24,27 +24,29 @@ package org.csanchez.jenkins.plugins.kubernetes.volumes; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -import org.jenkinsci.Symbol; -import org.kohsuke.stapler.DataBoundConstructor; - import hudson.Extension; import hudson.model.Descriptor; import io.fabric8.kubernetes.api.model.Volume; import io.fabric8.kubernetes.api.model.VolumeBuilder; +import org.jenkinsci.Symbol; +import org.kohsuke.stapler.DataBoundConstructor; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; public class PersistentVolumeClaim extends PodVolume { private String mountPath; private String claimName; @CheckForNull + private String subPath; + @CheckForNull private Boolean readOnly; @DataBoundConstructor - public PersistentVolumeClaim(String mountPath, String claimName, Boolean readOnly) { + public PersistentVolumeClaim(String mountPath, String claimName, String subPath, Boolean readOnly) { this.mountPath = mountPath; this.claimName = claimName; + this.subPath = subPath; this.readOnly = readOnly; } @@ -57,6 +59,11 @@ public String getClaimName() { return claimName; } + @Override + public String getSubPath() { + return subPath; + } + @Nonnull public Boolean getReadOnly() { return readOnly != null && readOnly; @@ -81,4 +88,4 @@ public String getDisplayName() { return "Persistent Volume Claim"; } } -} \ No newline at end of file +} diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/PodVolume.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/PodVolume.java index 14ecce082a..f7c1e45fa2 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/PodVolume.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/PodVolume.java @@ -24,13 +24,13 @@ package org.csanchez.jenkins.plugins.kubernetes.volumes; -import java.io.Serializable; -import java.util.List; - import hudson.model.AbstractDescribableImpl; import io.fabric8.kubernetes.api.model.Volume; import io.fabric8.kubernetes.api.model.VolumeMount; +import java.io.Serializable; +import java.util.List; + /** * Base class for all Kubernetes volume types */ @@ -41,6 +41,9 @@ public abstract class PodVolume extends AbstractDescribableImpl imple // Where to mount this volume in the pod. public abstract String getMountPath(); + // What path to mount from the volume + public abstract String getSubPath(); + // Builds a Volume model with the given name. public abstract Volume buildVolume(String volumeName); diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume.java index 150eb93f27..6d8d08d907 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume.java @@ -38,18 +38,20 @@ public class SecretVolume extends PodVolume { private String mountPath; private String secretName; private String defaultMode; + private String subPath; private Boolean optional; @DataBoundConstructor - public SecretVolume(String mountPath, String secretName, String defaultMode, Boolean optional) { + public SecretVolume(String mountPath, String secretName, String defaultMode, String subPath, Boolean optional) { this.mountPath = mountPath; this.secretName = secretName; this.defaultMode = defaultMode; + this.subPath = subPath; this.optional = optional; } public SecretVolume(String mountPath, String secretName) { - this(mountPath, secretName, null, false); + this(mountPath, secretName, null, null, false); } @Override @@ -78,6 +80,11 @@ public String getMountPath() { return mountPath; } + @Override + public String getSubPath() { + return subPath; + } + public String getDefaultMode() { return defaultMode; } @@ -89,7 +96,7 @@ public Boolean getOptional() { @Override public String toString() { return "SecretVolume [mountPath=" + mountPath + ", secretName=" + secretName - + ", defaultMode=" + defaultMode + ", optional=" + String.valueOf(optional) + "]"; + + ", defaultMode=" + defaultMode + ", subPath=" + subPath + ", optional=" + String.valueOf(optional) + "]"; } @Extension diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume/config.jelly index 8f99e63bc5..51e91f3d52 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume/config.jelly @@ -10,6 +10,10 @@ + + + + diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume/help-subPath.html b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume/help-subPath.html new file mode 100644 index 0000000000..f6077e89e1 --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/ConfigMapVolume/help-subPath.html @@ -0,0 +1 @@ +SubPath to mount this volume inside the pod. \ No newline at end of file diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume/config.jelly index 4f8d4fdf1c..36c146b903 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume/config.jelly @@ -10,4 +10,7 @@ - \ No newline at end of file + + + + diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume/help-subPath.html b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume/help-subPath.html new file mode 100644 index 0000000000..f6077e89e1 --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/EmptyDirVolume/help-subPath.html @@ -0,0 +1 @@ +SubPath to mount this volume inside the pod. \ No newline at end of file diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume/config.jelly index 230ccbc410..d4a936b6f3 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume/config.jelly @@ -10,4 +10,7 @@ - \ No newline at end of file + + + + diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume/help-subPath.html b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume/help-subPath.html new file mode 100644 index 0000000000..f6077e89e1 --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/HostPathVolume/help-subPath.html @@ -0,0 +1 @@ +SubPath to mount this volume inside the pod. \ No newline at end of file diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume/config.jelly index a061285a79..17fd67cca1 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume/config.jelly @@ -18,4 +18,7 @@ + + + diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume/help-subPath.html b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume/help-subPath.html new file mode 100644 index 0000000000..f6077e89e1 --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/NfsVolume/help-subPath.html @@ -0,0 +1 @@ +SubPath to mount this volume inside the pod. \ No newline at end of file diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim/config.jelly index 104fe0c8bb..d88b23dd99 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim/config.jelly @@ -14,4 +14,7 @@ - \ No newline at end of file + + + + diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim/help-subPath.html b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim/help-subPath.html new file mode 100644 index 0000000000..f6077e89e1 --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/PersistentVolumeClaim/help-subPath.html @@ -0,0 +1 @@ +SubPath to mount this volume inside the pod. \ No newline at end of file diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume/config.jelly b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume/config.jelly index c7b04c174d..aa1cf89050 100644 --- a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume/config.jelly +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume/config.jelly @@ -14,6 +14,10 @@ + + + + diff --git a/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume/help-subPath.html b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume/help-subPath.html new file mode 100644 index 0000000000..f6077e89e1 --- /dev/null +++ b/src/main/resources/org/csanchez/jenkins/plugins/kubernetes/volumes/SecretVolume/help-subPath.html @@ -0,0 +1 @@ +SubPath to mount this volume inside the pod. \ No newline at end of file diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloudTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloudTest.java index 80be894630..54cbd4cdf0 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloudTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloudTest.java @@ -1,26 +1,7 @@ package org.csanchez.jenkins.plugins.kubernetes; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.gargoylesoftware.htmlunit.html.DomElement; -import com.gargoylesoftware.htmlunit.html.DomNodeList; -import com.gargoylesoftware.htmlunit.html.HtmlButton; -import com.gargoylesoftware.htmlunit.html.HtmlElement; -import com.gargoylesoftware.htmlunit.html.HtmlForm; -import com.gargoylesoftware.htmlunit.html.HtmlFormUtil; -import com.gargoylesoftware.htmlunit.html.HtmlInput; -import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.*; +import jenkins.model.JenkinsLocationConfiguration; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomUtils; @@ -36,7 +17,11 @@ import org.jvnet.hudson.test.LoggerRule; import org.jvnet.hudson.test.recipes.LocalData; -import jenkins.model.JenkinsLocationConfiguration; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +import static org.junit.Assert.*; public class KubernetesCloudTest { @@ -76,7 +61,7 @@ public void testInheritance() { maven.setTtyEnabled(true); maven.setCommand("cat"); - PodVolume podVolume = new EmptyDirVolume("/some/path", true); + PodVolume podVolume = new EmptyDirVolume("/some/path", true, null); PodTemplate parent = new PodTemplate(); parent.setName("parent"); parent.setLabel("parent"); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java index 06dc4e9fee..9fa957462d 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java @@ -1,29 +1,10 @@ package org.csanchez.jenkins.plugins.kubernetes; -import static java.util.stream.Collectors.toList; -import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder.*; -import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.*; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.Collectors; - -import io.fabric8.kubernetes.api.model.PodSecurityContext; +import io.fabric8.kubernetes.api.model.*; +import jenkins.model.Jenkins; +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; +import junitparams.naming.TestCaseName; import org.apache.commons.compress.utils.IOUtils; import org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar; import org.csanchez.jenkins.plugins.kubernetes.model.TemplateEnvVar; @@ -39,28 +20,27 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.jvnet.hudson.test.FlagRule; -import org.jvnet.hudson.test.Issue; -import org.jvnet.hudson.test.JenkinsRule; -import org.jvnet.hudson.test.LoggerRule; +import org.jvnet.hudson.test.*; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.EnvVar; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.Quantity; -import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.Volume; -import io.fabric8.kubernetes.api.model.VolumeMount; -import io.fabric8.kubernetes.api.model.VolumeMountBuilder; -import jenkins.model.Jenkins; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; -import junitparams.naming.TestCaseName; -import org.jvnet.hudson.test.WithoutJenkins; +import java.io.IOException; +import java.util.*; +import java.util.function.Function; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +import static java.util.stream.Collectors.toList; +import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder.*; +import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.combine; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; @RunWith(JUnitParamsRunner.class) public class PodTemplateBuilderTest { @@ -239,8 +219,8 @@ public void testBuildFromTemplate(boolean directConnection) throws Exception { template.setHostNetwork(false); List volumes = new ArrayList(); - volumes.add(new HostPathVolume("/host/data", "/container/data")); - volumes.add(new EmptyDirVolume("/empty/dir", false)); + volumes.add(new HostPathVolume("/host/data", "/container/data", null)); + volumes.add(new EmptyDirVolume("/empty/dir", false, null)); template.setVolumes(volumes); List containers = new ArrayList(); 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 a73fe85352..dc9ffa5e65 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java @@ -24,47 +24,28 @@ package org.csanchez.jenkins.plugins.kubernetes; -import static java.util.Arrays.*; -import static java.util.Collections.*; -import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - +import hudson.model.Node; +import hudson.tools.ToolLocationNodeProperty; +import io.fabric8.kubernetes.api.model.*; +import io.fabric8.kubernetes.api.model.PodFluent.SpecNested; import org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar; import org.csanchez.jenkins.plugins.kubernetes.model.SecretEnvVar; import org.csanchez.jenkins.plugins.kubernetes.volumes.HostPathVolume; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.Issue; - -import hudson.model.Node; -import hudson.tools.ToolLocationNodeProperty; -import io.fabric8.kubernetes.api.model.ConfigMapEnvSource; -import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.ContainerBuilder; -import io.fabric8.kubernetes.api.model.EnvFromSource; -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.PodBuilder; -import io.fabric8.kubernetes.api.model.PodFluent.SpecNested; -import io.fabric8.kubernetes.api.model.PodSpec; -import io.fabric8.kubernetes.api.model.Quantity; -import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; -import io.fabric8.kubernetes.api.model.SecretEnvSource; -import io.fabric8.kubernetes.api.model.Toleration; -import io.fabric8.kubernetes.api.model.VolumeMount; -import io.fabric8.kubernetes.api.model.VolumeMountBuilder; import org.jvnet.hudson.test.JenkinsRule; +import java.util.*; +import java.util.stream.Collectors; + +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + public class PodTemplateUtilsTest { @Rule @@ -506,13 +487,13 @@ public void shouldFilterOutEnvFromSourcesWithNullOrEmptyKey() { @Test public void shouldCombineAllMounts() { PodTemplate template1 = new PodTemplate(); - HostPathVolume hostPathVolume1 = new HostPathVolume("/host/mnt1", "/container/mnt1"); - HostPathVolume hostPathVolume2 = new HostPathVolume("/host/mnt2", "/container/mnt2"); + HostPathVolume hostPathVolume1 = new HostPathVolume("/host/mnt1", "/container/mnt1", null); + HostPathVolume hostPathVolume2 = new HostPathVolume("/host/mnt2", "/container/mnt2", null); template1.setVolumes(asList(hostPathVolume1, hostPathVolume2)); PodTemplate template2 = new PodTemplate(); - HostPathVolume hostPathVolume3 = new HostPathVolume("/host/mnt3", "/container/mnt3"); - HostPathVolume hostPathVolume4 = new HostPathVolume("/host/mnt1", "/container/mnt4"); + HostPathVolume hostPathVolume3 = new HostPathVolume("/host/mnt3", "/container/mnt3", null); + HostPathVolume hostPathVolume4 = new HostPathVolume("/host/mnt1", "/container/mnt4", null); template2.setVolumes(asList(hostPathVolume3, hostPathVolume4)); PodTemplate result = combine(template1, template2);