Search in sources :

Example 1 with V1Affinity

use of io.kubernetes.client.openapi.models.V1Affinity in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method podHasSidecarAnnotations.

@Test
public void podHasSidecarAnnotations() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    BatchJobTask task = JobGenerator.oneBatchTask();
    String json_args = "{\"foo\":true,\"bar\":3.0}";
    List<PlatformSidecar> platformSidecars = Arrays.asList(new PlatformSidecar("mysidecar", "stable", json_args));
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().withPlatformSidecars(platformSidecars).build()).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    Map<String, String> annotations = pod.getMetadata().getAnnotations();
    String expectedSidecarAnnotation = "mysidecar" + KubeConstants.PLATFORM_SIDECAR_SUFFIX;
    assertThat(annotations.get(expectedSidecarAnnotation)).isEqualTo("true");
    String expectedChannelAnnotation = "mysidecar" + KubeConstants.PLATFORM_SIDECAR_CHANNEL_SUFFIX;
    assertThat(annotations.get(expectedChannelAnnotation)).isEqualTo("stable");
    String expectedArgsAnnotation = "mysidecar" + KubeConstants.PLATFORM_SIDECAR_ARGS_SUFFIX;
    assertThat(annotations.get(expectedArgsAnnotation)).isEqualTo(json_args);
}
Also used : PlatformSidecar(com.netflix.titus.api.jobmanager.model.job.PlatformSidecar) 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 2 with V1Affinity

use of io.kubernetes.client.openapi.models.V1Affinity in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method relocationLabel.

@Test
public void relocationLabel() {
    Job<ServiceJobExt> job = JobGenerator.oneServiceJob();
    Job<ServiceJobExt> selfManagedJob = job.toBuilder().withJobDescriptor(job.getJobDescriptor().but(jd -> jd.getDisruptionBudget().toBuilder().withDisruptionBudgetPolicy(SelfManagedDisruptionBudgetPolicy.newBuilder().build()))).build();
    ServiceJobTask task = JobGenerator.oneServiceTask();
    when(podAffinityFactory.buildV1Affinity(any(), eq(task))).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    assertThat(pod.getMetadata().getLabels()).doesNotContainKey(KubeConstants.POD_LABEL_RELOCATION_BINPACK);
    V1Pod selfManagedPod = podFactory.buildV1Pod(selfManagedJob, task);
    assertThat(selfManagedPod.getMetadata().getLabels()).containsEntry(KubeConstants.POD_LABEL_RELOCATION_BINPACK, "SelfManaged");
}
Also used : V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) HashMap(java.util.HashMap) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) Test(org.junit.Test)

Example 3 with V1Affinity

use of io.kubernetes.client.openapi.models.V1Affinity in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method testEFSMountsHandlesDuplicateVolumes.

@Test
public void testEFSMountsHandlesDuplicateVolumes() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    BatchJobTask task = JobGenerator.oneBatchTask();
    EfsMount newEfsMount = new EfsMount("1.2.3.4", "/mountpoint", EfsMount.MountPerm.RO, "/relative");
    EfsMount newEfsMount2 = new EfsMount("1.2.3.4", "/mountpoint2", EfsMount.MountPerm.RO, "/relative");
    EfsMount newEfsMount3 = new EfsMount("1.2.3.4", "/mountpoint3", EfsMount.MountPerm.RW, "/relative");
    Container newContainer = job.getJobDescriptor().getContainer();
    ContainerResources newContainerResources = newContainer.getContainerResources();
    Container newContainerWithEFS = newContainer.toBuilder().withContainerResources(newContainerResources.newBuilder().withEfsMounts(Arrays.asList(newEfsMount, newEfsMount2, newEfsMount3)).build()).build();
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().withContainer(newContainerWithEFS).build()).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    // Part 1: There should only be *one* EFS volume to share
    List<V1Volume> volumes = pod.getSpec().getVolumes();
    // one for nfs, one for shm
    assertThat(volumes.size()).isEqualTo(2);
    V1Volume v1NFSVolume = volumes.get(0);
    assertThat(v1NFSVolume.getName()).isEqualTo("1-2-3-4-relative-vol");
    assertThat(v1NFSVolume.getNfs().getServer()).isEqualTo("1.2.3.4");
    assertThat(v1NFSVolume.getNfs().getPath()).isEqualTo("/relative");
    // All NFS volumes that are generated like this should be RW, and
    // delegating the actual RO/RW state to the volume *mount*.
    assertThat(v1NFSVolume.getNfs().getReadOnly()).isEqualTo(false);
    // Part 2: there should be *3* volume mounts, all sharing the volume
    List<V1VolumeMount> vms = pod.getSpec().getContainers().get(0).getVolumeMounts();
    // 3 for nfs, one for shm
    assertThat(vms.size()).isEqualTo(4);
    V1VolumeMount v1NFSvm1 = vms.get(0);
    assertThat(v1NFSvm1.getName()).isEqualTo("1-2-3-4-relative-vol");
    assertThat(v1NFSvm1.getMountPath()).isEqualTo("/mountpoint");
    assertThat(v1NFSvm1.getReadOnly()).isTrue();
    V1VolumeMount v1NFSvm2 = vms.get(1);
    assertThat(v1NFSvm2.getName()).isEqualTo("1-2-3-4-relative-vol");
    assertThat(v1NFSvm2.getMountPath()).isEqualTo("/mountpoint2");
    assertThat(v1NFSvm2.getReadOnly()).isTrue();
    V1VolumeMount v1NFSvm3 = vms.get(2);
    assertThat(v1NFSvm3.getName()).isEqualTo("1-2-3-4-relative-vol");
    assertThat(v1NFSvm3.getMountPath()).isEqualTo("/mountpoint3");
    assertThat(v1NFSvm3.getReadOnly()).isFalse();
}
Also used : HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) 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) V1Volume(io.kubernetes.client.openapi.models.V1Volume) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) V1Pod(io.kubernetes.client.openapi.models.V1Pod) EfsMount(com.netflix.titus.api.model.EfsMount) ContainerResources(com.netflix.titus.api.jobmanager.model.job.ContainerResources) Test(org.junit.Test)

Example 4 with V1Affinity

use of io.kubernetes.client.openapi.models.V1Affinity in project titus-control-plane by Netflix.

the class V1SpecPodFactoryTest method testEFSMountsGetTransformedSafely.

@Test
public void testEFSMountsGetTransformedSafely() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    BatchJobTask task = JobGenerator.oneBatchTask();
    EfsMount newEfsMount = new EfsMount("1.2.3.4", "/mountpoint", EfsMount.MountPerm.RO, "/relative/");
    Container newContainer = job.getJobDescriptor().getContainer();
    ContainerResources newContainerResources = newContainer.getContainerResources();
    Container newContainerWithEFS = newContainer.toBuilder().withContainerResources(newContainerResources.newBuilder().withEfsMounts(Collections.singletonList(newEfsMount)).build()).build();
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().withContainer(newContainerWithEFS).build()).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    // Part 1: the volume section needs to be well-formed
    List<V1Volume> volumes = pod.getSpec().getVolumes();
    // one for nfs, one for shm
    assertThat(volumes.size()).isEqualTo(2);
    V1Volume v1NFSVolume = volumes.get(0);
    assertThat(v1NFSVolume.getName()).isEqualTo("1-2-3-4-relative--vol");
    assertThat(v1NFSVolume.getNfs().getServer()).isEqualTo("1.2.3.4");
    assertThat(v1NFSVolume.getNfs().getPath()).isEqualTo("/relative/");
    assertThat(v1NFSVolume.getNfs().getReadOnly()).isEqualTo(false);
    // Part 2: the volume mount section needs to applied to the first container in the podspec
    List<V1VolumeMount> vms = pod.getSpec().getContainers().get(0).getVolumeMounts();
    // one for nfs, one for shm
    assertThat(vms.size()).isEqualTo(2);
    V1VolumeMount v1NFSvm = vms.get(0);
    assertThat(v1NFSvm.getName()).isEqualTo("1-2-3-4-relative--vol");
    assertThat(v1NFSvm.getMountPath()).isEqualTo("/mountpoint");
    assertThat(v1NFSvm.getReadOnly()).isEqualTo(true);
}
Also used : HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) 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) V1Volume(io.kubernetes.client.openapi.models.V1Volume) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) V1Pod(io.kubernetes.client.openapi.models.V1Pod) EfsMount(com.netflix.titus.api.model.EfsMount) ContainerResources(com.netflix.titus.api.jobmanager.model.job.ContainerResources) Test(org.junit.Test)

Example 5 with V1Affinity

use of io.kubernetes.client.openapi.models.V1Affinity in project titus-control-plane by Netflix.

the class DefaultPodAffinityFactoryTest method testIpAllocationAzAffinity.

@Test
public void testIpAllocationAzAffinity() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    List<SignedIpAddressAllocation> ipAddressAllocations = JobIpAllocationGenerator.jobIpAllocations(1).toList();
    job = job.toBuilder().withJobDescriptor(JobFunctions.jobWithIpAllocations(job.getJobDescriptor(), ipAddressAllocations)).build();
    Pair<V1Affinity, Map<String, String>> affinityWithAnnotations = factory.buildV1Affinity(job, JobIpAllocationGenerator.appendIpAllocationAttribute(JobGenerator.oneBatchTask(), ipAddressAllocations.get(0).getIpAddressAllocation().getAllocationId()));
    V1NodeSelector nodeSelector = affinityWithAnnotations.getLeft().getNodeAffinity().getRequiredDuringSchedulingIgnoredDuringExecution();
    assertThat(nodeSelector.getNodeSelectorTerms()).hasSize(1);
    assertThat(nodeSelector.getNodeSelectorTerms().get(0).getMatchExpressions().get(0).getKey()).isEqualTo(KubeConstants.NODE_LABEL_ZONE);
    assertThat(nodeSelector.getNodeSelectorTerms().get(0).getMatchExpressions().get(0).getValues().get(0)).isEqualTo(ipAddressAllocations.get(0).getIpAddressAllocation().getIpAddressLocation().getAvailabilityZone());
}
Also used : SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) V1NodeSelector(io.kubernetes.client.openapi.models.V1NodeSelector) Map(java.util.Map) Test(org.junit.Test)

Aggregations

V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)23 Test (org.junit.Test)21 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)15 V1Pod (io.kubernetes.client.openapi.models.V1Pod)13 HashMap (java.util.HashMap)13 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)11 Map (java.util.Map)9 V1NodeSelector (io.kubernetes.client.openapi.models.V1NodeSelector)8 V1Container (io.kubernetes.client.openapi.models.V1Container)6 BasicContainer (com.netflix.titus.api.jobmanager.model.job.BasicContainer)5 Container (com.netflix.titus.api.jobmanager.model.job.Container)5 V1Volume (io.kubernetes.client.openapi.models.V1Volume)5 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)4 EbsVolume (com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume)4 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)4 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)3 ContainerResources (com.netflix.titus.api.jobmanager.model.job.ContainerResources)2 SignedIpAddressAllocation (com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation)2 EfsMount (com.netflix.titus.api.model.EfsMount)2 Pair (com.netflix.titus.common.util.tuple.Pair)2