Search in sources :

Example 1 with V1Volume

use of io.kubernetes.client.models.V1Volume in project twister2 by DSC-SPIDAL.

the class KubernetesUtils method constructPodTemplate.

public static V1PodTemplateSpec constructPodTemplate(ResourceContainer reqContainer, String serviceLabel, long jobFileSize, Config config) {
    V1PodTemplateSpec template = new V1PodTemplateSpec();
    V1ObjectMeta templateMetaData = new V1ObjectMeta();
    HashMap<String, String> labels = new HashMap<String, String>();
    labels.put("app", serviceLabel);
    templateMetaData.setLabels(labels);
    template.setMetadata(templateMetaData);
    V1PodSpec podSpec = new V1PodSpec();
    podSpec.setTerminationGracePeriodSeconds(0L);
    V1Volume volume = new V1Volume();
    volume.setName(POD_SHARED_VOLUME_NAME);
    V1EmptyDirVolumeSource volumeSource = new V1EmptyDirVolumeSource();
    volumeSource.setMedium("Memory");
    volume.setEmptyDir(volumeSource);
    podSpec.setVolumes(Arrays.asList(volume));
    int containersPerPod = KubernetesContext.containersPerPod(config);
    int basePort = KubernetesContext.workerBasePort(config);
    ArrayList<V1Container> containers = new ArrayList<V1Container>();
    for (int i = 0; i < containersPerPod; i++) {
        containers.add(constructContainer(i, reqContainer, jobFileSize, basePort + 1, config));
    }
    podSpec.setContainers(containers);
    template.setSpec(podSpec);
    return template;
}
Also used : V1Container(io.kubernetes.client.models.V1Container) V1Volume(io.kubernetes.client.models.V1Volume) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1EmptyDirVolumeSource(io.kubernetes.client.models.V1EmptyDirVolumeSource) ArrayList(java.util.ArrayList) V1PodTemplateSpec(io.kubernetes.client.models.V1PodTemplateSpec) IntOrString(io.kubernetes.client.custom.IntOrString) V1PodSpec(io.kubernetes.client.models.V1PodSpec)

Example 2 with V1Volume

use of io.kubernetes.client.models.V1Volume in project incubator-heron by apache.

the class AppsV1beta1Controller method addVolumesIfPresent.

private void addVolumesIfPresent(V1PodSpec spec) {
    final Config config = getConfiguration();
    if (KubernetesContext.hasVolume(config)) {
        final V1Volume volume = Volumes.get().create(config);
        if (volume != null) {
            LOG.fine("Adding volume: " + volume.toString());
            spec.volumes(Collections.singletonList(volume));
        }
    }
}
Also used : V1Volume(io.kubernetes.client.models.V1Volume) Config(com.twitter.heron.spi.common.Config)

Example 3 with V1Volume

use of io.kubernetes.client.models.V1Volume in project incubator-heron by apache.

the class VolumesTests method testAwsEbsVolume.

@Test
public void testAwsEbsVolume() {
    final String volumeId = "aws-ebs-1";
    final String fsType = "ext4";
    final Config config = Config.newBuilder().put(KubernetesContext.HERON_KUBERNETES_VOLUME_TYPE, "awsElasticBlockStore").put(KubernetesContext.HERON_KUBERNETES_VOLUME_AWS_EBS_VOLUME_ID, volumeId).put(KubernetesContext.HERON_KUBERNETES_VOLUME_AWS_EBS_FS_TYPE, fsType).build();
    final V1Volume volume = Volumes.get().create(config);
    Assert.assertNotNull(volume);
    Assert.assertNotNull(volume.getAwsElasticBlockStore());
    Assert.assertEquals(volume.getAwsElasticBlockStore().getVolumeID(), volumeId);
    Assert.assertEquals(volume.getAwsElasticBlockStore().getFsType(), fsType);
}
Also used : V1Volume(io.kubernetes.client.models.V1Volume) Config(com.twitter.heron.spi.common.Config) Test(org.junit.Test)

Example 4 with V1Volume

use of io.kubernetes.client.models.V1Volume in project incubator-heron by apache.

the class VolumesTests method testHostPathVolume.

@Test
public void testHostPathVolume() {
    final String path = "/test/dir1";
    final Config config = Config.newBuilder().put(KubernetesContext.HERON_KUBERNETES_VOLUME_TYPE, "hostPath").put(KubernetesContext.HERON_KUBERNETES_VOLUME_HOSTPATH_PATH, path).build();
    final V1Volume volume = Volumes.get().create(config);
    Assert.assertNotNull(volume);
    Assert.assertNotNull(volume.getHostPath());
    Assert.assertEquals(volume.getHostPath().getPath(), path);
}
Also used : V1Volume(io.kubernetes.client.models.V1Volume) Config(com.twitter.heron.spi.common.Config) Test(org.junit.Test)

Example 5 with V1Volume

use of io.kubernetes.client.models.V1Volume in project incubator-heron by apache.

the class VolumesTests method testNfsVolume.

@Test
public void testNfsVolume() {
    final String path = "/test/dir1";
    final String server = "10.10.10.10";
    final Config config = Config.newBuilder().put(KubernetesContext.HERON_KUBERNETES_VOLUME_TYPE, "nfs").put(KubernetesContext.HERON_KUBERNETES_VOLUME_NFS_PATH, path).put(KubernetesContext.HERON_KUBERNETES_VOLUME_NFS_SERVER, server).build();
    final V1Volume volume = Volumes.get().create(config);
    Assert.assertNotNull(volume);
    Assert.assertNotNull(volume.getNfs());
    Assert.assertEquals(volume.getNfs().getPath(), path);
    Assert.assertEquals(volume.getNfs().getServer(), server);
}
Also used : V1Volume(io.kubernetes.client.models.V1Volume) Config(com.twitter.heron.spi.common.Config) Test(org.junit.Test)

Aggregations

V1Volume (io.kubernetes.client.models.V1Volume)6 Config (com.twitter.heron.spi.common.Config)5 Test (org.junit.Test)4 IntOrString (io.kubernetes.client.custom.IntOrString)1 V1Container (io.kubernetes.client.models.V1Container)1 V1EmptyDirVolumeSource (io.kubernetes.client.models.V1EmptyDirVolumeSource)1 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)1 V1PodSpec (io.kubernetes.client.models.V1PodSpec)1 V1PodTemplateSpec (io.kubernetes.client.models.V1PodTemplateSpec)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1