Search in sources :

Example 6 with V1ContainerBuilder

use of io.kubernetes.client.openapi.models.V1ContainerBuilder in project heron by twitter.

the class V1ControllerTest method testMountVolumeIfPresent.

@Test
public void testMountVolumeIfPresent() {
    final String pathDefault = "config-host-volume-path";
    final String pathNameDefault = "config-host-volume-name";
    final Config configWithVolumes = Config.newBuilder().put(KubernetesContext.KUBERNETES_CONTAINER_VOLUME_MOUNT_NAME, pathNameDefault).put(KubernetesContext.KUBERNETES_CONTAINER_VOLUME_MOUNT_PATH, pathDefault).build();
    final V1Controller controllerWithMounts = new V1Controller(configWithVolumes, RUNTIME);
    final V1VolumeMount volumeDefault = new V1VolumeMountBuilder().withName(pathNameDefault).withMountPath(pathDefault).build();
    final V1VolumeMount volumeCustom = new V1VolumeMountBuilder().withName("custom-volume-mount").withMountPath("should-be-kept").build();
    final List<V1VolumeMount> expectedMountsDefault = Collections.singletonList(volumeDefault);
    final List<V1VolumeMount> expectedMountsCustom = Arrays.asList(volumeCustom, volumeDefault);
    final List<V1VolumeMount> volumeMountsCustomList = Arrays.asList(new V1VolumeMountBuilder().withName(pathNameDefault).withMountPath("should-be-replaced").build(), volumeCustom);
    // No Volume Mounts set.
    V1Controller controllerDoNotSetMounts = new V1Controller(Config.newBuilder().build(), RUNTIME);
    V1Container containerNoSetMounts = new V1Container();
    controllerDoNotSetMounts.mountVolumeIfPresent(containerNoSetMounts);
    Assert.assertNull(containerNoSetMounts.getVolumeMounts());
    // Default. Null Volume Mounts.
    V1Container containerNull = new V1ContainerBuilder().build();
    controllerWithMounts.mountVolumeIfPresent(containerNull);
    Assert.assertTrue("Default VOLUME MOUNTS should be set in container with null VOLUME MOUNTS", CollectionUtils.containsAll(expectedMountsDefault, containerNull.getVolumeMounts()));
    // Empty Volume Mounts.
    V1Container containerEmpty = new V1ContainerBuilder().withVolumeMounts(new LinkedList<>()).build();
    controllerWithMounts.mountVolumeIfPresent(containerEmpty);
    Assert.assertTrue("Default VOLUME MOUNTS should be set in container with empty VOLUME MOUNTS", CollectionUtils.containsAll(expectedMountsDefault, containerEmpty.getVolumeMounts()));
    // Custom Volume Mounts.
    V1Container containerCustom = new V1ContainerBuilder().withVolumeMounts(volumeMountsCustomList).build();
    controllerWithMounts.mountVolumeIfPresent(containerCustom);
    Assert.assertTrue("Default VOLUME MOUNTS should be set in container with custom VOLUME MOUNTS", CollectionUtils.containsAll(expectedMountsCustom, containerCustom.getVolumeMounts()));
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) Config(org.apache.heron.spi.common.Config) V1ContainerBuilder(io.kubernetes.client.openapi.models.V1ContainerBuilder) Matchers.anyString(org.mockito.Matchers.anyString) V1VolumeMountBuilder(io.kubernetes.client.openapi.models.V1VolumeMountBuilder) LinkedList(java.util.LinkedList) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) Test(org.junit.Test)

Aggregations

V1Container (io.kubernetes.client.openapi.models.V1Container)6 V1ContainerBuilder (io.kubernetes.client.openapi.models.V1ContainerBuilder)6 Test (org.junit.Test)6 LinkedList (java.util.LinkedList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Config (org.apache.heron.spi.common.Config)3 Quantity (io.kubernetes.client.custom.Quantity)2 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)2 V1VolumeMountBuilder (io.kubernetes.client.openapi.models.V1VolumeMountBuilder)2 Resource (org.apache.heron.spi.packing.Resource)2 V1ContainerPort (io.kubernetes.client.openapi.models.V1ContainerPort)1 V1EnvVar (io.kubernetes.client.openapi.models.V1EnvVar)1 V1EnvVarSource (io.kubernetes.client.openapi.models.V1EnvVarSource)1 V1ObjectFieldSelector (io.kubernetes.client.openapi.models.V1ObjectFieldSelector)1 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)1 V1PodSpecBuilder (io.kubernetes.client.openapi.models.V1PodSpecBuilder)1 V1ResourceRequirements (io.kubernetes.client.openapi.models.V1ResourceRequirements)1 V1Volume (io.kubernetes.client.openapi.models.V1Volume)1 V1VolumeBuilder (io.kubernetes.client.openapi.models.V1VolumeBuilder)1 Pair (org.apache.heron.common.basics.Pair)1