Search in sources :

Example 1 with V1NodeSelectorRequirement

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

the class RequestObjectBuilder method setNodeAffinity.

public static void setNodeAffinity(V1Affinity affinity) {
    String key = KubernetesContext.workerMappingKey(config);
    String operator = KubernetesContext.workerMappingOperator(config);
    List<String> values = KubernetesContext.workerMappingValues(config);
    V1NodeSelectorRequirement nsRequirement = new V1NodeSelectorRequirement();
    nsRequirement.setKey(key);
    nsRequirement.setOperator(operator);
    nsRequirement.setValues(values);
    V1NodeSelectorTerm selectorTerm = new V1NodeSelectorTerm();
    selectorTerm.addMatchExpressionsItem(nsRequirement);
    V1NodeSelector nodeSelector = new V1NodeSelector();
    nodeSelector.addNodeSelectorTermsItem(selectorTerm);
    V1NodeAffinity nodeAffinity = new V1NodeAffinity();
    nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution(nodeSelector);
    affinity.setNodeAffinity(nodeAffinity);
}
Also used : V1NodeSelectorTerm(io.kubernetes.client.openapi.models.V1NodeSelectorTerm) V1NodeAffinity(io.kubernetes.client.openapi.models.V1NodeAffinity) V1NodeSelectorRequirement(io.kubernetes.client.openapi.models.V1NodeSelectorRequirement) V1NodeSelector(io.kubernetes.client.openapi.models.V1NodeSelector)

Example 2 with V1NodeSelectorRequirement

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

the class DefaultPodAffinityFactoryTest method testKubeBackendAffinity.

@Test
public void testKubeBackendAffinity() {
    Pair<V1Affinity, Map<String, String>> affinityWithAnnotations = factory.buildV1Affinity(newJobWithHardConstraint(JobConstraints.KUBE_BACKEND, "kublet"), JobGenerator.oneBatchTask());
    V1NodeSelector nodeSelector = affinityWithAnnotations.getLeft().getNodeAffinity().getRequiredDuringSchedulingIgnoredDuringExecution();
    assertThat(nodeSelector.getNodeSelectorTerms()).hasSize(1);
    V1NodeSelectorRequirement requirement = nodeSelector.getNodeSelectorTerms().get(0).getMatchExpressions().get(0);
    assertThat(requirement.getKey()).isEqualTo(KubeConstants.TAINT_KUBE_BACKEND);
    assertThat(requirement.getValues()).contains("kublet");
}
Also used : V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) V1NodeSelectorRequirement(io.kubernetes.client.openapi.models.V1NodeSelectorRequirement) V1NodeSelector(io.kubernetes.client.openapi.models.V1NodeSelector) Map(java.util.Map) Test(org.junit.Test)

Aggregations

V1NodeSelector (io.kubernetes.client.openapi.models.V1NodeSelector)2 V1NodeSelectorRequirement (io.kubernetes.client.openapi.models.V1NodeSelectorRequirement)2 V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)1 V1NodeAffinity (io.kubernetes.client.openapi.models.V1NodeAffinity)1 V1NodeSelectorTerm (io.kubernetes.client.openapi.models.V1NodeSelectorTerm)1 Map (java.util.Map)1 Test (org.junit.Test)1