Search in sources :

Example 86 with PodOperator

use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.

the class KafkaRollerTest method controllerNotReadyAfterRolling.

@Test
public void controllerNotReadyAfterRolling(VertxTestContext testContext) throws InterruptedException {
    PodOperator podOps = mockPodOps(podId -> podId == 2 ? failedFuture(new TimeoutException("Timeout")) : succeededFuture());
    StatefulSet sts = buildStatefulSet();
    TestingKafkaRoller kafkaRoller = rollerWithControllers(sts, podOps, 2);
    // On the first reconciliation we expect it to fail when rolling the controller (i.e. as rolling all the rest)
    doFailingRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), KafkaRoller.FatalProblem.class, "Error while waiting for restarted pod c-kafka-2 to become ready", asList(0, 1, 3, 4, 2));
    // On the next reconciliation only pod 2 would need rolling, and we expect it to fail in the same way
    kafkaRoller = rollerWithControllers(sts, podOps, 2);
    clearRestarted();
    doFailingRollingRestart(testContext, kafkaRoller, singletonList(2), KafkaRoller.FatalProblem.class, "Error while waiting for restarted pod c-kafka-2 to become ready", singletonList(2));
}
Also used : PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) TimeoutException(io.strimzi.operator.common.operator.resource.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 87 with PodOperator

use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.

the class KafkaRollerTest method testRollHandlesErrorWhenGettingConfigFromNonController.

@Test
public void testRollHandlesErrorWhenGettingConfigFromNonController(VertxTestContext testContext) {
    PodOperator podOps = mockPodOps(podId -> succeededFuture());
    StatefulSet sts = buildStatefulSet();
    TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, addPodNames(sts.getSpec().getReplicas()), podOps, noException(), null, noException(), noException(), podId -> podId == 1 ? new KafkaRoller.ForceableProblem("could not get config exception") : null, brokerId -> succeededFuture(true), 2);
    // The algorithm should carry on rolling the pods
    doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 3, 4, 1, 2));
}
Also used : PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Test(org.junit.jupiter.api.Test)

Example 88 with PodOperator

use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.

the class KafkaRollerTest method testRollWithPod2AsController.

@Test
public void testRollWithPod2AsController(VertxTestContext testContext) {
    PodOperator podOps = mockPodOps(podId -> succeededFuture());
    StatefulSet sts = buildStatefulSet();
    TestingKafkaRoller kafkaRoller = rollerWithControllers(sts, podOps, 2);
    doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 1, 3, 4, 2));
}
Also used : PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Test(org.junit.jupiter.api.Test)

Example 89 with PodOperator

use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.

the class KafkaRollerTest method testNonControllerNotInitiallyRollable.

@Test
public void testNonControllerNotInitiallyRollable(VertxTestContext testContext) {
    PodOperator podOps = mockPodOps(podId -> succeededFuture());
    StatefulSet sts = buildStatefulSet();
    AtomicInteger count = new AtomicInteger(3);
    TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, addPodNames(sts.getSpec().getReplicas()), podOps, noException(), null, noException(), noException(), noException(), brokerId -> brokerId == 1 ? succeededFuture(count.getAndDecrement() == 0) : succeededFuture(true), 2);
    doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 3, 4, 1, 2));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Test(org.junit.jupiter.api.Test)

Example 90 with PodOperator

use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.

the class KafkaRollerTest method mockPodOps.

private PodOperator mockPodOps(Function<Integer, Future<Void>> readiness) {
    PodOperator podOps = mock(PodOperator.class);
    when(podOps.get(any(), any())).thenAnswer(invocation -> new PodBuilder().withNewMetadata().withNamespace(invocation.getArgument(0)).withName(invocation.getArgument(1)).endMetadata().build());
    when(podOps.readiness(any(), any(), any(), anyLong(), anyLong())).thenAnswer(invocationOnMock -> {
        String podName = invocationOnMock.getArgument(2);
        return readiness.apply(podName2Number(podName));
    });
    when(podOps.isReady(anyString(), anyString())).thenAnswer(invocationOnMock -> {
        String podName = invocationOnMock.getArgument(1);
        Future<Void> ready = readiness.apply(podName2Number(podName));
        if (ready.succeeded()) {
            return true;
        } else {
            if (ready.cause() instanceof TimeoutException) {
                return false;
            } else {
                throw ready.cause();
            }
        }
    });
    return podOps;
}
Also used : PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TimeoutException(io.strimzi.operator.common.operator.resource.TimeoutException)

Aggregations

PodOperator (io.strimzi.operator.common.operator.resource.PodOperator)180 Test (org.junit.jupiter.api.Test)166 Checkpoint (io.vertx.junit5.Checkpoint)138 Reconciliation (io.strimzi.operator.common.Reconciliation)134 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)114 Future (io.vertx.core.Future)114 VertxTestContext (io.vertx.junit5.VertxTestContext)112 CoreMatchers.is (org.hamcrest.CoreMatchers.is)112 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)112 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)112 Mockito.when (org.mockito.Mockito.when)112 Vertx (io.vertx.core.Vertx)104 VertxExtension (io.vertx.junit5.VertxExtension)102 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)102 List (java.util.List)100 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)100 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)98 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)98 CrdOperator (io.strimzi.operator.common.operator.resource.CrdOperator)94 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)92