Search in sources :

Example 46 with PodOperator

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

the class KafkaRollerTest method pod3NotReadyAfterRolling.

@Test
public void pod3NotReadyAfterRolling(VertxTestContext testContext) throws InterruptedException {
    PodOperator podOps = mockPodOps(podId -> podId == 3 ? failedFuture(new TimeoutException("Timeout")) : succeededFuture());
    StatefulSet sts = buildStatefulSet();
    TestingKafkaRoller kafkaRoller = rollerWithControllers(sts, podOps, 2);
    // On the first reconciliation we expect it to abort when it gets to pod 3 (but not 2, which is controller)
    doFailingRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), KafkaRoller.FatalProblem.class, "Error while waiting for restarted pod c-kafka-3 to become ready", asList(3));
    // On the next reconciliation only pods 2 (controller) and 4 would need rolling, and we expect it to fail in the same way
    kafkaRoller = rollerWithControllers(sts, podOps, 2);
    clearRestarted();
    doFailingRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 4), KafkaRoller.FatalProblem.class, "Error while waiting for non-restarted pod c-kafka-3 to become ready", emptyList());
}
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 47 with PodOperator

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

the class KafkaRollerTest method testRollHandlesErrorWhenAlteringConfig.

@Test
public void testRollHandlesErrorWhenAlteringConfig(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(), podId -> new KafkaRoller.ForceableProblem("could not get alter exception"), noException(), brokerId -> succeededFuture(true), 2);
    // The algorithm should carry on rolling the pods
    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 48 with PodOperator

use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi 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)

Example 49 with PodOperator

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

the class KafkaRollerTest method testRollHandlesErrorWhenGettingControllerFromNonController.

@Test
public void testRollHandlesErrorWhenGettingControllerFromNonController(VertxTestContext testContext) {
    int controller = 2;
    int nonController = 1;
    PodOperator podOps = mockPodOps(podId -> succeededFuture());
    StatefulSet sts = buildStatefulSet();
    TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, addPodNames(sts.getSpec().getReplicas()), podOps, noException(), null, podId -> podId == nonController ? new RuntimeException("Test Exception") : null, noException(), noException(), brokerId -> succeededFuture(true), controller);
    // The algorithm should carry on rolling the pods (errors are logged),
    // because we never find the controller we get ascending order
    doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 3, 4, nonController, controller));
}
Also used : PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 50 with PodOperator

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

the class KafkaRollerTest method testRollHandlesErrorWhenOpeningAdminClient.

@Test
public void testRollHandlesErrorWhenOpeningAdminClient(VertxTestContext testContext) {
    PodOperator podOps = mockPodOps(podId -> succeededFuture());
    StatefulSet sts = buildStatefulSet();
    TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, addPodNames(sts.getSpec().getReplicas()), podOps, bootstrapBrokers -> bootstrapBrokers != null && bootstrapBrokers.equals(singletonList(1)) ? new RuntimeException("Test Exception") : null, null, noException(), noException(), noException(), brokerId -> succeededFuture(true), 2);
    // The algorithm should carry on rolling the pods (errors are logged),
    // because we never find the controller we get ascending order
    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)

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