use of io.fabric8.kubernetes.api.model.NodeAffinity in project syndesis-qe by syndesisio.
the class OperatorValidationSteps method checkAffinity.
@When("^check (affinity|tolerations)( not set)? for (infra|integration) pods$")
public void checkAffinity(String test, String notSet, String method) {
List<Pod> pods = "infra".equals(method) ? ComponentUtils.getComponentPods().stream().filter(p -> !p.getMetadata().getName().contains("operator")).collect(Collectors.toList()) : OpenShiftUtils.findPodsByPredicates(p -> "integration".equals(p.getMetadata().getLabels().get("syndesis.io/type")));
for (Pod p : pods) {
String name = p.getMetadata().getName();
if ("affinity".equals(test)) {
Affinity podAffinity = p.getSpec().getAffinity();
if (notSet == null) {
assertThat(podAffinity).as(name + ": affinity is null").isNotNull();
NodeAffinity nodeAffinity = podAffinity.getNodeAffinity();
assertThat(nodeAffinity).as(name + ": node affinity is null").isNotNull();
NodeSelector selector = nodeAffinity.getRequiredDuringSchedulingIgnoredDuringExecution();
assertThat(selector).as(name + ": required is null").isNotNull();
List<NodeSelectorTerm> terms = selector.getNodeSelectorTerms();
assertThat(terms).as(name + ": node selector is null").isNotNull();
assertThat(terms).as(name + ": node selector size isn't 1").hasSize(1);
} else {
assertThat(podAffinity).isNull();
}
} else {
Optional<Toleration> toleration = p.getSpec().getTolerations().stream().filter(t -> "node.kubernetes.io/network-unavailable".equals(t.getKey())).findAny();
if (notSet == null) {
assertThat(toleration).as(name + ": Expected toleration setting is not present").isPresent();
} else {
assertThat(toleration).as(name + ": Toleration shouldn't be present").isNotPresent();
}
}
}
}
Aggregations