Skip to content

Commit

Permalink
Merge pull request #358 from jenkinsci/kubernetes-client-v4
Browse files Browse the repository at this point in the history
Update kubernetes-client to 4.0.0
  • Loading branch information
carlossg authored Jul 31, 2018
2 parents 34fc3b4 + 3d940cf commit bfdc63b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>3.2.0</version>
<version>4.0.0</version>
<exclusions>
<!-- Jackson logic comes from plugins -->
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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<VolumeMount> getContainerVolumeMounts(Collection<VolumeMount> volumeMounts, String workingDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -128,8 +129,10 @@ public void testBuildWithCustomWorkspaceVolume() throws Exception {
assertEquals(2, containers.size());
Container container0 = containers.get(0);
Container container1 = containers.get(1);
ImmutableList<VolumeMount> volumeMounts = ImmutableList
.of(new VolumeMount("/home/jenkins", "workspace-volume", false, null));

ImmutableList<VolumeMount> volumeMounts = ImmutableList.of(new VolumeMountBuilder()
.withMountPath("/home/jenkins").withName("workspace-volume").withReadOnly(false).build());

assertEquals(volumeMounts, container0.getVolumeMounts());
assertEquals(volumeMounts, container1.getVolumeMounts());
}
Expand Down Expand Up @@ -197,13 +200,18 @@ private void validatePod(Pod pod, boolean fromYaml) {
List<VolumeMount> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit bfdc63b

Please sign in to comment.