Search in sources :

Example 1 with V1PodAntiAffinity

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

the class RequestObjectBuilder method setUniformMappingAffinity.

public static void setUniformMappingAffinity(V1Affinity affinity) {
    String mappingType = KubernetesContext.workerMappingUniform(config);
    String key = "t2-wp";
    String operator = "In";
    String serviceLabel = jobID;
    List<String> values = Arrays.asList(serviceLabel);
    V1LabelSelectorRequirement labelRequirement = new V1LabelSelectorRequirement();
    labelRequirement.setKey(key);
    labelRequirement.setOperator(operator);
    labelRequirement.setValues(values);
    V1LabelSelector labelSelector = new V1LabelSelector();
    labelSelector.addMatchExpressionsItem(labelRequirement);
    V1PodAffinityTerm affinityTerm = new V1PodAffinityTerm();
    affinityTerm.setLabelSelector(labelSelector);
    affinityTerm.setTopologyKey("kubernetes.io/hostname");
    if ("all-same-node".equalsIgnoreCase(mappingType)) {
        V1PodAffinity podAffinity = new V1PodAffinity();
        podAffinity.requiredDuringSchedulingIgnoredDuringExecution(Arrays.asList(affinityTerm));
        affinity.setPodAffinity(podAffinity);
    } else if ("all-separate-nodes".equalsIgnoreCase(mappingType)) {
        V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity();
        podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution(Arrays.asList(affinityTerm));
        affinity.setPodAntiAffinity(podAntiAffinity);
    }
}
Also used : V1PodAffinity(io.kubernetes.client.openapi.models.V1PodAffinity) V1PodAntiAffinity(io.kubernetes.client.openapi.models.V1PodAntiAffinity) V1LabelSelectorRequirement(io.kubernetes.client.openapi.models.V1LabelSelectorRequirement) V1PodAffinityTerm(io.kubernetes.client.openapi.models.V1PodAffinityTerm) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector)

Aggregations

V1LabelSelector (io.kubernetes.client.openapi.models.V1LabelSelector)1 V1LabelSelectorRequirement (io.kubernetes.client.openapi.models.V1LabelSelectorRequirement)1 V1PodAffinity (io.kubernetes.client.openapi.models.V1PodAffinity)1 V1PodAffinityTerm (io.kubernetes.client.openapi.models.V1PodAffinityTerm)1 V1PodAntiAffinity (io.kubernetes.client.openapi.models.V1PodAntiAffinity)1