Search in sources :

Example 66 with BatchJobExt

use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method podMainContainerHasVolumeMounts.

@Test
public void podMainContainerHasVolumeMounts() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    BatchJobTask task = JobGenerator.oneBatchTask();
    List<VolumeMount> volumeMounts = Arrays.asList(new VolumeMount("volume1", "", NONE_MOUNT_PROPAGATION, false, ""), new VolumeMount("volume2", "", NONE_MOUNT_PROPAGATION, false, ""));
    Container container = job.getJobDescriptor().getContainer().toBuilder().withVolumeMounts(volumeMounts).build();
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().withContainer(container).build()).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    V1Container mainContainer = pod.getSpec().getContainers().get(0);
    List<V1VolumeMount> mounts = mainContainer.getVolumeMounts();
    // dev-shm is third volume
    assertThat(mounts.size()).isEqualTo(3);
    assertThat(mounts.get(0).getName()).isEqualTo("volume1");
    assertThat(mounts.get(1).getName()).isEqualTo("volume2");
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) V1Container(io.kubernetes.client.openapi.models.V1Container) BasicContainer(com.netflix.titus.api.jobmanager.model.job.BasicContainer) Container(com.netflix.titus.api.jobmanager.model.job.Container) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) VolumeMount(com.netflix.titus.api.jobmanager.model.job.VolumeMount) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) Test(org.junit.Test)

Example 67 with BatchJobExt

use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method basicMainContainerTranslation.

@Test
public void basicMainContainerTranslation() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    BatchJobTask task = JobGenerator.oneBatchTask();
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().build()).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    V1Container mainContainer = pod.getSpec().getContainers().get(0);
    String mainContainerImageTag = pod.getMetadata().getAnnotations().get("pod.titus.netflix.com/image-tag-main");
    assertThat(mainContainerImageTag).isEqualTo("latest");
    assertThat(mainContainer.getImage()).contains("titusops/alpine@");
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) V1Pod(io.kubernetes.client.openapi.models.V1Pod) Test(org.junit.Test)

Example 68 with BatchJobExt

use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method testEbsVolumeInfo.

@Test
public void testEbsVolumeInfo() {
    String volName1 = "vol-1";
    String volName2 = "vol-2";
    String fsType = "xfs";
    String mountPath = "/mnt";
    EbsVolume.MountPerm mountPerm = EbsVolume.MountPerm.RW;
    EbsVolume vol1 = EbsVolume.newBuilder().withVolumeId(volName1).withMountPath(mountPath).withMountPermissions(mountPerm).withFsType(fsType).withVolumeAvailabilityZone("us-east-1c").withVolumeCapacityGB(10).build();
    EbsVolume vol2 = EbsVolume.newBuilder().withVolumeId(volName2).withMountPath(mountPath).withMountPermissions(mountPerm).withFsType(fsType).withVolumeAvailabilityZone("us-east-1d").withVolumeCapacityGB(20).build();
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    job = Job.<BatchJobExt>newBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().withContainer(job.getJobDescriptor().getContainer().toBuilder().withContainerResources(job.getJobDescriptor().getContainer().getContainerResources().toBuilder().withEbsVolumes(Arrays.asList(vol1, vol2)).build()).build()).build()).build();
    Task task = JobGenerator.batchTasks(job).getValue();
    task = task.toBuilder().addToTaskContext(TaskAttributes.TASK_ATTRIBUTES_EBS_VOLUME_ID, volName2).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod v1Pod = podFactory.buildV1Pod(job, task);
    V1Volume v1Volume = v1Pod.getSpec().getVolumes().get(0);
    assertThat(v1Volume.getName()).isEqualTo(volName2);
    V1AWSElasticBlockStoreVolumeSource ebsVolumeSource = v1Volume.getAwsElasticBlockStore();
    assertThat(ebsVolumeSource.getFsType()).isEqualTo(fsType);
    V1VolumeMount v1VolumeMount = v1Pod.getSpec().getContainers().get(0).getVolumeMounts().get(0);
    assertThat(v1VolumeMount.getName()).isEqualTo(volName2);
    assertThat(v1VolumeMount.getMountPath()).isEqualTo(mountPath);
    assertThat(v1VolumeMount.getReadOnly()).isFalse();
}
Also used : EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) V1Volume(io.kubernetes.client.openapi.models.V1Volume) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1AWSElasticBlockStoreVolumeSource(io.kubernetes.client.openapi.models.V1AWSElasticBlockStoreVolumeSource) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) Test(org.junit.Test)

Example 69 with BatchJobExt

use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method multipleContainers.

@Test
public void multipleContainers() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    BatchJobTask task = JobGenerator.oneBatchTask();
    Image testImage = Image.newBuilder().withName("testImage").withDigest("123").build();
    List<BasicContainer> extraContainers = Arrays.asList(new BasicContainer("extraContainer1", testImage, Collections.emptyList(), Collections.emptyList(), new HashMap<>(), Collections.emptyList()), new BasicContainer("extraContainer2", testImage, Collections.emptyList(), Collections.emptyList(), new HashMap<>(), Collections.emptyList()));
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().withExtraContainers(extraContainers).build()).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    List<V1Container> containers = Objects.requireNonNull(pod.getSpec()).getContainers();
    // 3 containers here, 1 from the main container, 2 from the extras
    assertThat(containers.size()).isEqualTo(1 + extraContainers.size());
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) HashMap(java.util.HashMap) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) V1Pod(io.kubernetes.client.openapi.models.V1Pod) BasicContainer(com.netflix.titus.api.jobmanager.model.job.BasicContainer) Image(com.netflix.titus.api.jobmanager.model.job.Image) Test(org.junit.Test)

Example 70 with BatchJobExt

use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method testNetworkConfigurationRespectsBeingSet.

@Test
public void testNetworkConfigurationRespectsBeingSet() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    BatchJobTask task = JobGenerator.oneBatchTask();
    NetworkConfiguration networkConfiguration = new NetworkConfiguration(3);
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().withNetworkConfiguration(networkConfiguration).build()).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    String networkModeAnnotationValue = pod.getMetadata().getAnnotations().get("network.netflix.com/network-mode");
    assertThat(networkModeAnnotationValue).isEqualTo("Ipv6AndIpv4Fallback");
}
Also used : V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) V1Pod(io.kubernetes.client.openapi.models.V1Pod) NetworkConfiguration(com.netflix.titus.api.jobmanager.model.job.NetworkConfiguration) Test(org.junit.Test)

Aggregations

BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)73 Test (org.junit.Test)55 Task (com.netflix.titus.api.jobmanager.model.job.Task)30 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)25 List (java.util.List)20 ArrayList (java.util.ArrayList)19 JobStore (com.netflix.titus.api.jobmanager.store.JobStore)17 HashMap (java.util.HashMap)16 V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)14 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)13 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)11 V1Pod (io.kubernetes.client.openapi.models.V1Pod)11 Job (com.netflix.titus.api.jobmanager.model.job.Job)10 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)10 Container (com.netflix.titus.api.jobmanager.model.job.Container)6 Map (java.util.Map)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 V1Container (io.kubernetes.client.openapi.models.V1Container)5 BasicContainer (com.netflix.titus.api.jobmanager.model.job.BasicContainer)4 Image (com.netflix.titus.api.jobmanager.model.job.Image)4