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");
}
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@");
}
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();
}
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());
}
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");
}
Aggregations