Search in sources :

Example 76 with PodOperator

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

the class StatefulSetOperatorTest method testNonCascadingDeleteAsync.

@Test
public void testNonCascadingDeleteAsync(VertxTestContext context) {
    Deletable mockDeletable = mock(Deletable.class);
    when(mockDeletable.delete()).thenReturn(Boolean.TRUE);
    Resource mockERPD = mock(resourceType());
    when(mockERPD.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockDeletable);
    when(mockERPD.withGracePeriod(anyLong())).thenReturn(mockDeletable);
    RollableScalableResource mockRSR = mock(RollableScalableResource.class);
    ArgumentCaptor<DeletionPropagation> cascadingCaptor = ArgumentCaptor.forClass(DeletionPropagation.class);
    when(mockRSR.withPropagationPolicy(cascadingCaptor.capture())).thenReturn(mockERPD);
    ArgumentCaptor<Watcher> watcherCaptor = ArgumentCaptor.forClass(Watcher.class);
    when(mockRSR.watch(watcherCaptor.capture())).thenReturn(mock(Watch.class));
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockRSR);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
    PodOperator podOperator = mock(PodOperator.class);
    PvcOperator pvcOperator = mock(PvcOperator.class);
    KubernetesClient mockClient = mock(KubernetesClient.class);
    mocker(mockClient, mockCms);
    StatefulSetOperator op = new StatefulSetOperator(AbstractResourceOperatorTest.vertx, mockClient, 5_000L, podOperator) {

        @Override
        protected boolean shouldIncrementGeneration(Reconciliation reconciliation, StatefulSetDiff diff) {
            return true;
        }
    };
    Checkpoint a = context.checkpoint();
    op.deleteAsync(new Reconciliation("test", "kind", "namespace", "name"), NAMESPACE, RESOURCE_NAME, false).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(cascadingCaptor.getValue(), is(DeletionPropagation.ORPHAN));
        a.flag();
    })));
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) AbstractScalableResourceOperator(io.strimzi.operator.common.operator.resource.AbstractScalableResourceOperator) VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DeletionPropagation(io.fabric8.kubernetes.api.model.DeletionPropagation) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ScalableResourceOperatorTest(io.strimzi.operator.common.operator.resource.ScalableResourceOperatorTest) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Watcher(io.fabric8.kubernetes.client.Watcher) Watch(io.fabric8.kubernetes.client.Watch) HashMap(java.util.HashMap) MockitoException(org.mockito.exceptions.base.MockitoException) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) BiPredicate(java.util.function.BiPredicate) Resource(io.fabric8.kubernetes.client.dsl.Resource) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) ArgumentCaptor(org.mockito.ArgumentCaptor) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) StatefulSetList(io.fabric8.kubernetes.api.model.apps.StatefulSetList) Map(java.util.Map) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Deletable(io.fabric8.kubernetes.client.dsl.Deletable) EditReplacePatchDeletable(io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable) AbstractResourceOperatorTest(io.strimzi.operator.common.operator.resource.AbstractResourceOperatorTest) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) ArgumentMatchers.matches(org.mockito.ArgumentMatchers.matches) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Checkpoint(io.vertx.junit5.Checkpoint) AppsAPIGroupDSL(io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Resource(io.fabric8.kubernetes.client.dsl.Resource) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) DeletionPropagation(io.fabric8.kubernetes.api.model.DeletionPropagation) Watcher(io.fabric8.kubernetes.client.Watcher) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Checkpoint(io.vertx.junit5.Checkpoint) Reconciliation(io.strimzi.operator.common.Reconciliation) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) Watch(io.fabric8.kubernetes.client.Watch) Deletable(io.fabric8.kubernetes.client.dsl.Deletable) EditReplacePatchDeletable(io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) ScalableResourceOperatorTest(io.strimzi.operator.common.operator.resource.ScalableResourceOperatorTest) AbstractResourceOperatorTest(io.strimzi.operator.common.operator.resource.AbstractResourceOperatorTest) Test(org.junit.jupiter.api.Test)

Example 77 with PodOperator

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

the class ZooKeeperRollerTest method testAllPodsAreRolled.

@Test
public void testAllPodsAreRolled(VertxTestContext context) {
    PodOperator podOperator = mock(PodOperator.class);
    when(podOperator.listAsync(any(), any(Labels.class))).thenReturn(Future.succeededFuture(PODS));
    ZookeeperLeaderFinder leaderFinder = mock(ZookeeperLeaderFinder.class);
    when(leaderFinder.findZookeeperLeader(any(), any(), any(), any())).thenReturn(Future.succeededFuture(ZookeeperLeaderFinder.UNKNOWN_LEADER));
    MockZooKeeperRoller roller = new MockZooKeeperRoller(podOperator, leaderFinder, 300_00L);
    Checkpoint async = context.checkpoint();
    roller.maybeRollingUpdate(Reconciliation.DUMMY_RECONCILIATION, DUMMY_SELECTOR, pod -> List.of("Should restart"), new Secret(), new Secret()).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(roller.podRestarts.size(), is(3));
        assertThat(roller.podRestarts.contains("my-cluster-zookeeper-0"), is(true));
        assertThat(roller.podRestarts.contains("my-cluster-zookeeper-1"), is(true));
        assertThat(roller.podRestarts.contains("my-cluster-zookeeper-2"), is(true));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Deque(java.util.Deque) Future(io.vertx.core.Future) Function(java.util.function.Function) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Map(java.util.Map) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArrayDeque(java.util.ArrayDeque) Mockito.mock(org.mockito.Mockito.mock) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Labels(io.strimzi.operator.common.model.Labels) Test(org.junit.jupiter.api.Test)

Example 78 with PodOperator

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

the class ZooKeeperRollerTest method testLeaderIsLast.

@Test
public void testLeaderIsLast(VertxTestContext context) {
    PodOperator podOperator = mock(PodOperator.class);
    when(podOperator.listAsync(any(), any(Labels.class))).thenReturn(Future.succeededFuture(PODS));
    ZookeeperLeaderFinder leaderFinder = mock(ZookeeperLeaderFinder.class);
    when(leaderFinder.findZookeeperLeader(any(), any(), any(), any())).thenReturn(Future.succeededFuture("my-cluster-zookeeper-1"));
    MockZooKeeperRoller roller = new MockZooKeeperRoller(podOperator, leaderFinder, 300_00L);
    Checkpoint async = context.checkpoint();
    roller.maybeRollingUpdate(Reconciliation.DUMMY_RECONCILIATION, DUMMY_SELECTOR, pod -> List.of("Should restart"), new Secret(), new Secret()).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(roller.podRestarts.size(), is(3));
        assertThat(roller.podRestarts.removeLast(), is("my-cluster-zookeeper-1"));
        assertThat(roller.podRestarts.contains("my-cluster-zookeeper-2"), is(true));
        assertThat(roller.podRestarts.contains("my-cluster-zookeeper-0"), is(true));
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Deque(java.util.Deque) Future(io.vertx.core.Future) Function(java.util.function.Function) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Map(java.util.Map) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArrayDeque(java.util.ArrayDeque) Mockito.mock(org.mockito.Mockito.mock) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Labels(io.strimzi.operator.common.model.Labels) Test(org.junit.jupiter.api.Test)

Example 79 with PodOperator

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

the class KafkaRollerTest method pod0NotReadyAfterRolling.

@Test
public void pod0NotReadyAfterRolling(VertxTestContext testContext) throws InterruptedException {
    PodOperator podOps = mockPodOps(podId -> podId == 0 ? failedFuture(new TimeoutException("Timeout")) : succeededFuture());
    StatefulSet sts = buildStatefulSet();
    TestingKafkaRoller kafkaRoller = rollerWithControllers(sts, podOps, 2);
    // What does/did the ZK algo do?
    doFailingRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), KafkaRoller.FatalProblem.class, "Error while waiting for restarted pod c-kafka-0 to become ready", singletonList(0));
// TODO assert subsequent rolls
}
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 80 with PodOperator

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

the class KafkaRollerTest method testRollHandlesErrorWhenGettingConfigFromController.

@Test
public void testRollHandlesErrorWhenGettingConfigFromController(VertxTestContext testContext) {
    int controller = 2;
    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 == controller ? new KafkaRoller.ForceableProblem("could not get config exception") : null, brokerId -> succeededFuture(true), controller);
    // The algorithm should carry on rolling the pods
    doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 1, 3, 4, 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)

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