Search in sources :

Example 1 with V1Toleration

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));
}
Also used : V1Toleration(io.kubernetes.client.openapi.models.V1Toleration) V1PodSpecBuilder(io.kubernetes.client.openapi.models.V1PodSpecBuilder) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with V1Toleration

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;
}
Also used : V1Toleration(io.kubernetes.client.openapi.models.V1Toleration) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

V1Toleration (io.kubernetes.client.openapi.models.V1Toleration)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)1 V1PodSpecBuilder (io.kubernetes.client.openapi.models.V1PodSpecBuilder)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1