diff --git a/pom.xml b/pom.xml index 17a223b5a9..db28bf5cbc 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ io.fabric8 kubernetes-client - 3.2.0 + 4.0.0 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 58d522e29d..7890b06bfc 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilder.java @@ -69,6 +69,7 @@ import io.fabric8.kubernetes.api.model.Volume; import io.fabric8.kubernetes.api.model.VolumeBuilder; import io.fabric8.kubernetes.api.model.VolumeMount; +import io.fabric8.kubernetes.api.model.VolumeMountBuilder; /** * Helper class to build Pods from PodTemplates @@ -126,7 +127,8 @@ 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 VolumeMount(mountPath, volumeName, false, null)); + volumeMounts.put(mountPath, new VolumeMountBuilder() // + .withMountPath(mountPath).withName(volumeName).withReadOnly(false).build()); volumes.put(volumeName, volume.buildVolume(volumeName)); i++; } @@ -365,7 +367,7 @@ private VolumeMount getDefaultVolumeMount(@CheckForNull String workingDir) { wd = ContainerTemplate.DEFAULT_WORKING_DIR; LOGGER.log(Level.FINE, "Container workingDir is null, defaulting to {0}", wd); } - return new VolumeMount(wd, WORKSPACE_VOLUME_NAME, false, null); + return new VolumeMountBuilder().withMountPath(wd).withName(WORKSPACE_VOLUME_NAME).withReadOnly(false).build(); } private List getContainerVolumeMounts(Collection volumeMounts, String workingDir) { 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 69be932b64..a957486a4e 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 @@ -29,6 +29,7 @@ import hudson.Extension; import hudson.model.Descriptor; +import io.fabric8.kubernetes.api.model.HostPathVolumeSource; import io.fabric8.kubernetes.api.model.Volume; import io.fabric8.kubernetes.api.model.VolumeBuilder; @@ -43,9 +44,9 @@ public HostPathVolume(String hostPath, String mountPath) { } public Volume buildVolume(String volumeName) { - return new VolumeBuilder() - .withName(volumeName) - .withNewHostPath(getHostPath()) + return new VolumeBuilder() // + .withName(volumeName) // + .withNewHostPath().withPath(getHostPath()).endHostPath() // .build(); } diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/workspace/HostPathWorkspaceVolume.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/workspace/HostPathWorkspaceVolume.java index 9805b9f55f..d54773e047 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/workspace/HostPathWorkspaceVolume.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes/workspace/HostPathWorkspaceVolume.java @@ -41,9 +41,9 @@ public HostPathWorkspaceVolume(String hostPath) { } public Volume buildVolume(String volumeName) { - return new VolumeBuilder() - .withName(volumeName) - .withNewHostPath(getHostPath()) + return new VolumeBuilder() // + .withName(volumeName) // + .withNewHostPath().withPath(getHostPath()).endHostPath() // .build(); } 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 de043df05e..42b9e5bb4e 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateBuilderTest.java @@ -39,6 +39,7 @@ import io.fabric8.kubernetes.api.model.Quantity; import io.fabric8.kubernetes.api.model.Volume; import io.fabric8.kubernetes.api.model.VolumeMount; +import io.fabric8.kubernetes.api.model.VolumeMountBuilder; public class PodTemplateBuilderTest { @@ -128,8 +129,10 @@ public void testBuildWithCustomWorkspaceVolume() throws Exception { assertEquals(2, containers.size()); Container container0 = containers.get(0); Container container1 = containers.get(1); - ImmutableList volumeMounts = ImmutableList - .of(new VolumeMount("/home/jenkins", "workspace-volume", false, null)); + + ImmutableList volumeMounts = ImmutableList.of(new VolumeMountBuilder() + .withMountPath("/home/jenkins").withName("workspace-volume").withReadOnly(false).build()); + assertEquals(volumeMounts, container0.getVolumeMounts()); assertEquals(volumeMounts, container1.getVolumeMounts()); } @@ -197,13 +200,18 @@ private void validatePod(Pod pod, boolean fromYaml) { List mounts = containers.get("busybox").getVolumeMounts(); if (fromYaml) { assertEquals(2, mounts.size()); - assertEquals(new VolumeMount("/container/data", "host-volume", null, null), mounts.get(0)); - assertEquals(new VolumeMount("/home/jenkins", "workspace-volume", false, null), mounts.get(1)); + assertEquals(new VolumeMountBuilder().withMountPath("/container/data").withName("host-volume").build(), + mounts.get(0)); + assertEquals(new VolumeMountBuilder().withMountPath("/home/jenkins").withName("workspace-volume") + .withReadOnly(false).build(), mounts.get(1)); } else { assertEquals(3, mounts.size()); - assertEquals(new VolumeMount("/container/data", "volume-0", null, null), mounts.get(0)); - assertEquals(new VolumeMount("/empty/dir", "volume-1", null, null), mounts.get(1)); - assertEquals(new VolumeMount("/home/jenkins", "workspace-volume", false, null), mounts.get(2)); + assertEquals(new VolumeMountBuilder().withMountPath("/container/data").withName("volume-0").build(), + mounts.get(0)); + assertEquals(new VolumeMountBuilder().withMountPath("/empty/dir").withName("volume-1").build(), + mounts.get(1)); + assertEquals(new VolumeMountBuilder().withMountPath("/home/jenkins").withName("workspace-volume") + .withReadOnly(false).build(), mounts.get(2)); } validateJnlpContainer(containers.get("jnlp"), slave); 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 7b7abbe051..4a91ee14af 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtilsTest.java @@ -59,6 +59,7 @@ 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; public class PodTemplateUtilsTest { @@ -469,10 +470,14 @@ private ContainerBuilder containerBuilder() { @Test public void shouldCombineAllPodMounts() { - VolumeMount vm1 = new VolumeMount("/host/mnt1", "volume-1", false, null); - VolumeMount vm2 = new VolumeMount("/host/mnt2", "volume-2", false, null); - VolumeMount vm3 = new VolumeMount("/host/mnt3", "volume-3", false, null); - VolumeMount vm4 = new VolumeMount("/host/mnt1", "volume-4", false, null); + VolumeMount vm1 = new VolumeMountBuilder().withMountPath("/host/mnt1").withName("volume-1").withReadOnly(false) + .build(); + VolumeMount vm2 = new VolumeMountBuilder().withMountPath("/host/mnt2").withName("volume-2").withReadOnly(false) + .build(); + VolumeMount vm3 = new VolumeMountBuilder().withMountPath("/host/mnt3").withName("volume-3").withReadOnly(false) + .build(); + VolumeMount vm4 = new VolumeMountBuilder().withMountPath("/host/mnt1").withName("volume-4").withReadOnly(false) + .build(); Container container1 = containerBuilder().withName("jnlp").withVolumeMounts(vm1, vm2).build(); Pod pod1 = podBuilder().withContainers(container1).endSpec().build(); Container container2 = containerBuilder().withName("jnlp").withVolumeMounts(vm3, vm4).build();