Search in sources :

Example 1 with SignedIpAddressAllocation

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

the class JobAssertionsTest method testEbsAndIpZoneMatchValidation.

@Test
public void testEbsAndIpZoneMatchValidation() {
    int size = 4;
    List<String> availabilityZones = JobEbsVolumeGenerator.availabilityZones().getValues(size);
    List<EbsVolume> ebsVolumes = JobEbsVolumeGenerator.jobEbsVolumes(size).toList();
    List<SignedIpAddressAllocation> ipAddressAllocations = JobIpAllocationGenerator.jobIpAllocations(size).toList();
    for (int i = 0; i < size; i++) {
        String az = availabilityZones.get(i);
        EbsVolume updatedEbsVolume = ebsVolumes.get(i).toBuilder().withVolumeAvailabilityZone(az).build();
        ebsVolumes.set(i, updatedEbsVolume);
        SignedIpAddressAllocation updatedIpAllocation = ipAddressAllocations.get(i).toBuilder().withIpAddressAllocation(ipAddressAllocations.get(i).getIpAddressAllocation().toBuilder().withIpAddressLocation(ipAddressAllocations.get(i).getIpAddressAllocation().getIpAddressLocation().toBuilder().withAvailabilityZone(az).build()).build()).build();
        ipAddressAllocations.set(i, updatedIpAllocation);
    }
    Map<String, String> violations = jobAssertions.matchingEbsAndIpZones(ebsVolumes, ipAddressAllocations);
    assertThat(violations).hasSize(0);
}
Also used : EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) Test(org.junit.Test)

Example 2 with SignedIpAddressAllocation

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

the class JobAssertions method validateMatchingEbsAndIpZones.

public static Set<ValidationError> validateMatchingEbsAndIpZones(List<EbsVolume> ebsVolumes, List<SignedIpAddressAllocation> ipSignedAddressAllocations) {
    if (ebsVolumes == null || ipSignedAddressAllocations == null) {
        return Collections.emptySet();
    }
    if (ebsVolumes.isEmpty() || ipSignedAddressAllocations.isEmpty()) {
        return Collections.emptySet();
    }
    int numElements = Math.min(ebsVolumes.size(), ipSignedAddressAllocations.size());
    for (int i = 0; i < numElements; i++) {
        EbsVolume ebsVolume = ebsVolumes.get(i);
        IpAddressAllocation ipAddressAllocation = ipSignedAddressAllocations.get(i).getIpAddressAllocation();
        if (!ebsVolume.getVolumeAvailabilityZone().equals(ipAddressAllocation.getIpAddressLocation().getAvailabilityZone())) {
            return Collections.singleton(new ValidationError("containerResources.ebsVolumes", String.format("EBS volume %s zone %s conflicts with Static IP %s zone %s and index %d", ebsVolume.getVolumeId(), ebsVolume.getVolumeAvailabilityZone(), ipAddressAllocation.getAllocationId(), ipAddressAllocation.getIpAddressLocation().getAvailabilityZone(), i)));
        }
    }
    return Collections.emptySet();
}
Also used : SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) IpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.IpAddressAllocation) EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError)

Example 3 with SignedIpAddressAllocation

use of com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation 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)

Example 4 with SignedIpAddressAllocation

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

the class JobAssertionsTest method testEbsAndIpZoneDoNotMatchValidation.

@Test
public void testEbsAndIpZoneDoNotMatchValidation() {
    int size = 4;
    List<String> availabilityZones = JobEbsVolumeGenerator.availabilityZones().getValues(size);
    List<EbsVolume> ebsVolumes = JobEbsVolumeGenerator.jobEbsVolumes(size).toList();
    List<SignedIpAddressAllocation> ipAddressAllocations = JobIpAllocationGenerator.jobIpAllocations(size).toList();
    for (int i = 0; i < size; i++) {
        String az = availabilityZones.get(i);
        EbsVolume updatedEbsVolume = ebsVolumes.get(i).toBuilder().withVolumeAvailabilityZone(az).build();
        ebsVolumes.set(i, updatedEbsVolume);
    }
    Map<String, String> violations = jobAssertions.matchingEbsAndIpZones(ebsVolumes, ipAddressAllocations);
    assertThat(violations).hasSize(1);
}
Also used : EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) Test(org.junit.Test)

Aggregations

SignedIpAddressAllocation (com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation)4 EbsVolume (com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume)3 Test (org.junit.Test)3 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)1 IpAddressAllocation (com.netflix.titus.api.jobmanager.model.job.vpc.IpAddressAllocation)1 ValidationError (com.netflix.titus.common.model.sanitizer.ValidationError)1 V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)1 V1NodeSelector (io.kubernetes.client.openapi.models.V1NodeSelector)1 Map (java.util.Map)1