use of io.kubernetes.client.openapi.models.V1Toleration in project heron by twitter.
the class V1ControllerTest method testConfigureTolerations.
@Test
public void testConfigureTolerations() {
final V1Toleration keptToleration = new V1Toleration().key("kept toleration").operator("Some Operator").effect("Some Effect").tolerationSeconds(5L);
final List<V1Toleration> expectedTolerationBase = Collections.unmodifiableList(V1Controller.getTolerations());
final List<V1Toleration> inputTolerationsBase = Collections.unmodifiableList(Arrays.asList(new V1Toleration().key(KubernetesConstants.TOLERATIONS.get(0)).operator("replace").effect("replace"), new V1Toleration().key(KubernetesConstants.TOLERATIONS.get(1)).operator("replace").effect("replace"), keptToleration));
// Null Tolerations. This is the default case.
final V1PodSpec podSpecNullTolerations = new V1PodSpecBuilder().build();
v1ControllerWithPodTemplate.configureTolerations(podSpecNullTolerations);
Assert.assertTrue("Pod Spec has null TOLERATIONS and should be set to Heron's defaults", CollectionUtils.containsAll(podSpecNullTolerations.getTolerations(), expectedTolerationBase));
// Empty Tolerations.
final V1PodSpec podSpecWithEmptyTolerations = new V1PodSpecBuilder().withTolerations(new LinkedList<>()).build();
v1ControllerWithPodTemplate.configureTolerations(podSpecWithEmptyTolerations);
Assert.assertTrue("Pod Spec has empty TOLERATIONS and should be set to Heron's defaults", CollectionUtils.containsAll(podSpecWithEmptyTolerations.getTolerations(), expectedTolerationBase));
// Toleration overriding.
final V1PodSpec podSpecWithTolerations = new V1PodSpecBuilder().withTolerations(inputTolerationsBase).build();
final List<V1Toleration> expectedTolerationsOverriding = new LinkedList<>(expectedTolerationBase);
expectedTolerationsOverriding.add(keptToleration);
v1ControllerWithPodTemplate.configureTolerations(podSpecWithTolerations);
Assert.assertTrue("Pod Spec has TOLERATIONS and should be overridden with Heron's defaults", CollectionUtils.containsAll(podSpecWithTolerations.getTolerations(), expectedTolerationsOverriding));
}
use of io.kubernetes.client.openapi.models.V1Toleration in project heron by twitter.
the class V1Controller method getTolerations.
/**
* Generates a list of <code>tolerations</code> which Heron requires.
* @return A list of configured <code>tolerations</code>.
*/
@VisibleForTesting
protected static List<V1Toleration> getTolerations() {
final List<V1Toleration> tolerations = new ArrayList<>();
KubernetesConstants.TOLERATIONS.forEach(t -> {
final V1Toleration toleration = new V1Toleration().key(t).operator("Exists").effect("NoExecute").tolerationSeconds(10L);
tolerations.add(toleration);
});
return tolerations;
}
Aggregations