use of io.kubernetes.client.openapi.models.V1PodAffinity 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);
}
}
Aggregations