Search in sources :

Example 36 with ClusterOperatorConfig

use of io.strimzi.operator.cluster.ClusterOperatorConfig in project strimzi-kafka-operator by strimzi.

the class ManualPodCleanerTest method manualPodCleanup.

private void manualPodCleanup(VertxTestContext context, boolean useStrimziPodSets, List<Pod> pods, List<PersistentVolumeClaim> pvcs, List<String> podsToBeDeleted, List<String> pvcsToBeDeleted) {
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    StrimziPodSetOperator mockPodSetOps = supplier.strimziPodSetOperator;
    StatefulSetOperator mockStsOps = supplier.stsOperations;
    ArgumentCaptor<StatefulSet> stsReconciliationCaptor = ArgumentCaptor.forClass(StatefulSet.class);
    ArgumentCaptor<StrimziPodSet> podSetReconciliationCaptor = ArgumentCaptor.forClass(StrimziPodSet.class);
    if (useStrimziPodSets) {
        when(mockPodSetOps.getAsync(any(), eq(CONTROLLER_NAME))).thenReturn(Future.succeededFuture(new StrimziPodSetBuilder().withNewMetadata().withName(CONTROLLER_NAME).endMetadata().withNewSpec().withPods(PodSetUtils.podsToMaps(pods)).endSpec().build()));
        when(mockPodSetOps.reconcile(any(), any(), eq(CONTROLLER_NAME), podSetReconciliationCaptor.capture())).thenReturn(Future.succeededFuture());
    } else {
        when(mockStsOps.getAsync(any(), eq(CONTROLLER_NAME))).thenReturn(Future.succeededFuture(new StatefulSetBuilder().withNewMetadata().withName(CONTROLLER_NAME).endMetadata().build()));
        when(mockStsOps.deleteAsync(any(), any(), eq(CONTROLLER_NAME), anyBoolean())).thenReturn(Future.succeededFuture());
        when(mockStsOps.reconcile(any(), any(), eq(CONTROLLER_NAME), stsReconciliationCaptor.capture())).thenReturn(Future.succeededFuture());
    }
    PodOperator mockPodOps = supplier.podOperations;
    when(mockPodOps.listAsync(any(), eq(SELECTOR))).thenReturn(Future.succeededFuture(pods));
    ArgumentCaptor<String> podDeletionCaptor = ArgumentCaptor.forClass(String.class);
    when(mockPodOps.deleteAsync(any(), any(), podDeletionCaptor.capture(), anyBoolean())).thenReturn(Future.succeededFuture());
    when(mockPodOps.readiness(any(), any(), any(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    PvcOperator mockPvcOps = supplier.pvcOperations;
    when(mockPvcOps.listAsync(any(), eq(SELECTOR))).thenReturn(Future.succeededFuture(pvcs));
    ArgumentCaptor<String> pvcDeletionCaptor = ArgumentCaptor.forClass(String.class);
    when(mockPvcOps.deleteAsync(any(), any(), pvcDeletionCaptor.capture(), anyBoolean())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> pvcReconciliationCaptor = ArgumentCaptor.forClass(String.class);
    when(mockPvcOps.reconcile(any(), any(), pvcReconciliationCaptor.capture(), any())).thenReturn(Future.succeededFuture());
    ClusterOperatorConfig config;
    if (useStrimziPodSets) {
        config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS, ClusterOperatorConfig.DEFAULT_OPERATION_TIMEOUT_MS, "+UseStrimziPodSets");
    } else {
        config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS, ClusterOperatorConfig.DEFAULT_OPERATION_TIMEOUT_MS);
    }
    ManualPodCleaner cleaner = new ManualPodCleaner(Reconciliation.DUMMY_RECONCILIATION, CONTROLLER_NAME, SELECTOR, config, supplier);
    Checkpoint async = context.checkpoint();
    cleaner.maybeManualPodCleaning(pvcs).onComplete(context.succeeding(v -> context.verify(() -> {
        if (useStrimziPodSets) {
            if (podsToBeDeleted.size() > 0) {
                // PodSet was reconciled twice => once teo remove the deleted pod and once to add it back
                assertThat(podSetReconciliationCaptor.getAllValues().size(), is(2));
                assertThat(podSetReconciliationCaptor.getAllValues().get(0).getSpec().getPods().size(), is(2));
                assertThat(podSetReconciliationCaptor.getAllValues().get(1).getSpec().getPods().size(), is(3));
            } else {
                assertThat(podSetReconciliationCaptor.getAllValues().size(), is(0));
            }
        } else {
            if (podsToBeDeleted.size() > 0) {
                // StatefulSet was deleted once and reconciled once to recreate it
                verify(mockStsOps, times(1)).deleteAsync(any(), any(), eq(CONTROLLER_NAME), anyBoolean());
                assertThat(stsReconciliationCaptor.getAllValues().size(), is(1));
                assertThat(stsReconciliationCaptor.getValue(), is(notNullValue()));
            } else {
                verify(mockStsOps, never()).deleteAsync(any(), any(), eq(CONTROLLER_NAME), anyBoolean());
                assertThat(stsReconciliationCaptor.getAllValues().size(), is(0));
            }
        }
        // Verify the deleted pod
        assertThat(podDeletionCaptor.getAllValues().size(), is(podsToBeDeleted.size()));
        assertThat(podDeletionCaptor.getAllValues(), is(podsToBeDeleted));
        // Verify the deleted and recreated pvc
        assertThat(pvcDeletionCaptor.getAllValues().size(), is(pvcsToBeDeleted.size()));
        assertThat(pvcDeletionCaptor.getAllValues(), is(pvcsToBeDeleted));
        assertThat(pvcReconciliationCaptor.getAllValues().size(), is(pvcsToBeDeleted.size()));
        assertThat(pvcReconciliationCaptor.getAllValues(), is(pvcsToBeDeleted));
        async.flag();
    })));
}
Also used : 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) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) StrimziPodSetBuilder(io.strimzi.api.kafka.model.StrimziPodSetBuilder) Map(java.util.Map) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Pod(io.fabric8.kubernetes.api.model.Pod) PodSetUtils(io.strimzi.operator.cluster.model.PodSetUtils) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) 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) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Labels(io.strimzi.operator.common.model.Labels) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Checkpoint(io.vertx.junit5.Checkpoint) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) StrimziPodSetBuilder(io.strimzi.api.kafka.model.StrimziPodSetBuilder) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet)

Example 37 with ClusterOperatorConfig

use of io.strimzi.operator.cluster.ClusterOperatorConfig in project strimzi-kafka-operator by strimzi.

the class KafkaRebalanceAssemblyOperatorTest method testKafkaClusterNotMatchingLabelSelector.

/**
 * When the Kafka cluster does not match the selector labels in the cluster operator configuration, the
 * KafkaRebalance resource should be ignored and not reconciled.
 */
@Test
public void testKafkaClusterNotMatchingLabelSelector(VertxTestContext context) {
    KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, EMPTY_KAFKA_REBALANCE_SPEC);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
    mockKafkaOps = supplier.kafkaOperator;
    mockRebalanceOps = supplier.kafkaRebalanceOperator;
    when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
    ClusterOperatorConfig config = new ClusterOperatorConfig(singleton(CLUSTER_NAMESPACE), 60_000, 120_000, 300_000, false, true, KafkaVersionTestUtils.getKafkaVersionLookup(), null, null, null, null, Labels.fromMap(Map.of("selectorLabel", "value")), "", 10, 10_000, 30, false, 1024);
    kcrao = new KafkaRebalanceAssemblyOperator(Vertx.vertx(), supplier, config);
    Checkpoint checkpoint = context.checkpoint();
    kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> context.verify(() -> {
        // The labels of the Kafka resource do not match the => the KafkaRebalance should not be reconciled and the
        // rebalance ops should have no interactions.
        verifyNoInteractions(mockRebalanceOps);
        checkpoint.flag();
    })));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) URISyntaxException(java.net.URISyntaxException) Annotations(io.strimzi.operator.common.Annotations) KafkaRebalanceSpecBuilder(io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Collections.singleton(java.util.Collections.singleton) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MockKube2(io.strimzi.test.mockkube2.MockKube2) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) VertxExtension(io.vertx.junit5.VertxExtension) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) KafkaRebalanceAnnotation(io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation) Future(io.vertx.core.Future) NoSuchResourceException(io.strimzi.operator.cluster.model.NoSuchResourceException) ClientAndServer(org.mockserver.integration.ClientAndServer) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) Test(org.junit.jupiter.api.Test) Labels(io.strimzi.operator.common.model.Labels) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.is(org.hamcrest.Matchers.is) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KafkaList(io.strimzi.api.kafka.KafkaList) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) Crds(io.strimzi.api.kafka.Crds) KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) CruiseControlEndpoints(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlEndpoints) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) TestUtils(io.strimzi.test.TestUtils) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) ConnectException(java.net.ConnectException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NoStackTraceTimeoutException(io.strimzi.operator.common.operator.resource.NoStackTraceTimeoutException) CruiseControl(io.strimzi.operator.cluster.model.CruiseControl) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException) MockCruiseControl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.MockCruiseControl) Collections(java.util.Collections) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Test(org.junit.jupiter.api.Test)

Example 38 with ClusterOperatorConfig

use of io.strimzi.operator.cluster.ClusterOperatorConfig in project strimzi-kafka-operator by strimzi.

the class KafkaAssemblyOperatorManualRollingUpdatesTest method manualRollingUpdate.

public void manualRollingUpdate(VertxTestContext context, boolean useStrimziPodSets) {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withGeneration(2L).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().endSpec().build();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ZookeeperCluster zkCluster = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    if (useStrimziPodSets) {
        StrimziPodSetOperator mockPodSetOps = supplier.strimziPodSetOperator;
        when(mockPodSetOps.getAsync(any(), eq(zkCluster.getName()))).thenAnswer(i -> {
            StrimziPodSet zkPodSet = zkCluster.generatePodSet(kafka.getSpec().getZookeeper().getReplicas(), false, null, null, null);
            zkPodSet.getMetadata().getAnnotations().put(Annotations.ANNO_STRIMZI_IO_MANUAL_ROLLING_UPDATE, "true");
            return Future.succeededFuture(zkPodSet);
        });
        when(mockPodSetOps.getAsync(any(), eq(kafkaCluster.getName()))).thenAnswer(i -> {
            StrimziPodSet kafkaPodSet = kafkaCluster.generatePodSet(kafka.getSpec().getKafka().getReplicas(), false, null, null, brokerId -> null);
            kafkaPodSet.getMetadata().getAnnotations().put(Annotations.ANNO_STRIMZI_IO_MANUAL_ROLLING_UPDATE, "true");
            return Future.succeededFuture(kafkaPodSet);
        });
        StatefulSetOperator mockStsOps = supplier.stsOperations;
        when(mockStsOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    } else {
        StatefulSetOperator mockStsOps = supplier.stsOperations;
        when(mockStsOps.getAsync(any(), eq(zkCluster.getName()))).thenAnswer(i -> {
            StatefulSet sts = zkCluster.generateStatefulSet(false, null, null);
            sts.getMetadata().getAnnotations().put(Annotations.ANNO_STRIMZI_IO_MANUAL_ROLLING_UPDATE, "true");
            return Future.succeededFuture(sts);
        });
        when(mockStsOps.getAsync(any(), eq(kafkaCluster.getName()))).thenAnswer(i -> {
            StatefulSet sts = kafkaCluster.generateStatefulSet(false, null, null, null);
            sts.getMetadata().getAnnotations().put(Annotations.ANNO_STRIMZI_IO_MANUAL_ROLLING_UPDATE, "true");
            return Future.succeededFuture(sts);
        });
        StrimziPodSetOperator mockPodSetOps = supplier.strimziPodSetOperator;
        when(mockPodSetOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    }
    PodOperator mockPodOps = supplier.podOperations;
    when(mockPodOps.listAsync(any(), eq(zkCluster.getSelectorLabels()))).thenReturn(Future.succeededFuture(Collections.emptyList()));
    when(mockPodOps.listAsync(any(), eq(kafkaCluster.getSelectorLabels()))).thenReturn(Future.succeededFuture(Collections.emptyList()));
    CrdOperator<KubernetesClient, Kafka, KafkaList> mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(NAMESPACE), eq(CLUSTER_NAME))).thenReturn(Future.succeededFuture(kafka));
    when(mockKafkaOps.get(eq(NAMESPACE), eq(CLUSTER_NAME))).thenReturn(kafka);
    when(mockKafkaOps.updateStatusAsync(any(), any())).thenReturn(Future.succeededFuture());
    ClusterOperatorConfig config;
    if (useStrimziPodSets) {
        config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS, ClusterOperatorConfig.DEFAULT_OPERATION_TIMEOUT_MS, "+UseStrimziPodSets");
    } else {
        config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS, ClusterOperatorConfig.DEFAULT_OPERATION_TIMEOUT_MS);
    }
    MockZooKeeperReconciler zr = new MockZooKeeperReconciler(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), vertx, config, supplier, new PlatformFeaturesAvailability(false, KUBERNETES_VERSION), kafka, VERSION_CHANGE, null, 0, null);
    MockKafkaReconciler kr = new MockKafkaReconciler(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), vertx, config, supplier, new PlatformFeaturesAvailability(false, KUBERNETES_VERSION), kafka, VERSION_CHANGE, null, 0, null, null);
    MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, KUBERNETES_VERSION), CERT_MANAGER, PASSWORD_GENERATOR, supplier, config, zr, kr);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME)).onComplete(context.succeeding(v -> context.verify(() -> {
        // Verify Zookeeper rolling updates
        assertThat(zr.maybeRollZooKeeperInvocations, is(1));
        assertThat(zr.zooPodNeedsRestart.apply(podWithName("my-cluster-zookeeper-0")), is(Collections.singletonList("manual rolling update")));
        assertThat(zr.zooPodNeedsRestart.apply(podWithName("my-cluster-zookeeper-1")), is(Collections.singletonList("manual rolling update")));
        assertThat(zr.zooPodNeedsRestart.apply(podWithName("my-cluster-zookeeper-2")), is(Collections.singletonList("manual rolling update")));
        // Verify Kafka rolling updates
        assertThat(kr.maybeRollKafkaInvocations, is(1));
        assertThat(kr.kafkaPodNeedsRestart.apply(podWithName("my-cluster-kafka-0")), is(Collections.singletonList("manual rolling update")));
        assertThat(kr.kafkaPodNeedsRestart.apply(podWithName("my-cluster-kafka-1")), is(Collections.singletonList("manual rolling update")));
        assertThat(kr.kafkaPodNeedsRestart.apply(podWithName("my-cluster-kafka-2")), is(Collections.singletonList("manual rolling update")));
        async.flag();
    })));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Storage(io.strimzi.api.kafka.model.storage.Storage) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Annotations(io.strimzi.operator.common.Annotations) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) KafkaVersionChange(io.strimzi.operator.cluster.model.KafkaVersionChange) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ClientsCa(io.strimzi.operator.cluster.model.ClientsCa) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Checkpoint(io.vertx.junit5.Checkpoint) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KafkaList(io.strimzi.api.kafka.KafkaList) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) CertManager(io.strimzi.certs.CertManager) ZookeeperCluster(io.strimzi.operator.cluster.model.ZookeeperCluster) Function(java.util.function.Function) Supplier(java.util.function.Supplier) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArrayList(java.util.ArrayList) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) Collections(java.util.Collections) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ZookeeperCluster(io.strimzi.operator.cluster.model.ZookeeperCluster) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) KafkaList(io.strimzi.api.kafka.KafkaList) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet)

Example 39 with ClusterOperatorConfig

use of io.strimzi.operator.cluster.ClusterOperatorConfig in project strimzi-kafka-operator by strimzi.

the class KafkaAssemblyOperatorManualRollingUpdatesTest method noManualRollingUpdate.

public void noManualRollingUpdate(VertxTestContext context, boolean useStrimziPodSets) {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withGeneration(2L).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build()).withNewEphemeralStorage().endEphemeralStorage().endKafka().withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().endSpec().build();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ZookeeperCluster zkCluster = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    if (useStrimziPodSets) {
        StrimziPodSetOperator mockPodSetOps = supplier.strimziPodSetOperator;
        when(mockPodSetOps.getAsync(any(), eq(zkCluster.getName()))).thenReturn(Future.succeededFuture(zkCluster.generatePodSet(kafka.getSpec().getZookeeper().getReplicas(), false, null, null, null)));
        when(mockPodSetOps.getAsync(any(), eq(kafkaCluster.getName()))).thenReturn(Future.succeededFuture(kafkaCluster.generatePodSet(kafka.getSpec().getKafka().getReplicas(), false, null, null, brokerId -> null)));
        StatefulSetOperator mockStsOps = supplier.stsOperations;
        when(mockStsOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    } else {
        StatefulSetOperator mockStsOps = supplier.stsOperations;
        when(mockStsOps.getAsync(any(), eq(zkCluster.getName()))).thenReturn(Future.succeededFuture(zkCluster.generateStatefulSet(false, null, null)));
        when(mockStsOps.getAsync(any(), eq(kafkaCluster.getName()))).thenReturn(Future.succeededFuture(kafkaCluster.generateStatefulSet(false, null, null, null)));
        StrimziPodSetOperator mockPodSetOps = supplier.strimziPodSetOperator;
        when(mockPodSetOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    }
    PodOperator mockPodOps = supplier.podOperations;
    when(mockPodOps.listAsync(any(), eq(zkCluster.getSelectorLabels()))).thenReturn(Future.succeededFuture(Collections.emptyList()));
    when(mockPodOps.listAsync(any(), eq(kafkaCluster.getSelectorLabels()))).thenReturn(Future.succeededFuture(Collections.emptyList()));
    when(mockPodOps.listAsync(any(), any(Labels.class))).thenReturn(Future.succeededFuture(Collections.emptyList()));
    CrdOperator<KubernetesClient, Kafka, KafkaList> mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(NAMESPACE), eq(CLUSTER_NAME))).thenReturn(Future.succeededFuture(kafka));
    when(mockKafkaOps.get(eq(NAMESPACE), eq(CLUSTER_NAME))).thenReturn(kafka);
    when(mockKafkaOps.updateStatusAsync(any(), any())).thenReturn(Future.succeededFuture());
    when(mockKafkaOps.updateStatusAsync(any(), any())).thenReturn(Future.succeededFuture());
    ClusterOperatorConfig config;
    if (useStrimziPodSets) {
        config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS, ClusterOperatorConfig.DEFAULT_OPERATION_TIMEOUT_MS, "+UseStrimziPodSets");
    } else {
        config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS, ClusterOperatorConfig.DEFAULT_OPERATION_TIMEOUT_MS);
    }
    MockZooKeeperReconciler zr = new MockZooKeeperReconciler(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), vertx, config, supplier, new PlatformFeaturesAvailability(false, KUBERNETES_VERSION), kafka, VERSION_CHANGE, null, 0, null);
    MockKafkaReconciler kr = new MockKafkaReconciler(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), vertx, config, supplier, new PlatformFeaturesAvailability(false, KUBERNETES_VERSION), kafka, VERSION_CHANGE, null, 0, null, null);
    MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, KUBERNETES_VERSION), CERT_MANAGER, PASSWORD_GENERATOR, supplier, config, zr, kr);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME)).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(zr.maybeRollZooKeeperInvocations, is(0));
        assertThat(kr.maybeRollKafkaInvocations, is(0));
        async.flag();
    })));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Storage(io.strimzi.api.kafka.model.storage.Storage) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Annotations(io.strimzi.operator.common.Annotations) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) KafkaVersionChange(io.strimzi.operator.cluster.model.KafkaVersionChange) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ClientsCa(io.strimzi.operator.cluster.model.ClientsCa) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Checkpoint(io.vertx.junit5.Checkpoint) ClusterCa(io.strimzi.operator.cluster.model.ClusterCa) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KafkaList(io.strimzi.api.kafka.KafkaList) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) CertManager(io.strimzi.certs.CertManager) ZookeeperCluster(io.strimzi.operator.cluster.model.ZookeeperCluster) Function(java.util.function.Function) Supplier(java.util.function.Supplier) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArrayList(java.util.ArrayList) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) Collections(java.util.Collections) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ZookeeperCluster(io.strimzi.operator.cluster.model.ZookeeperCluster) Labels(io.strimzi.operator.common.model.Labels) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) KafkaList(io.strimzi.api.kafka.KafkaList) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation)

Example 40 with ClusterOperatorConfig

use of io.strimzi.operator.cluster.ClusterOperatorConfig in project strimzi-kafka-operator by strimzi.

the class KafkaAssemblyOperatorMockTest method init.

/*
     * init is equivalent to a @BeforeEach method
     * since this is a parameterized set, the tests params are only available at test start
     * This must be called before each test
     */
private void init(Params params) {
    setFields(params);
    cluster = new KafkaBuilder().withNewMetadata().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(singletonMap("foo", "bar")).endMetadata().withNewSpec().withNewKafka().withReplicas(kafkaReplicas).withStorage(kafkaStorage).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build(), new GenericKafkaListenerBuilder().withName("tls").withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).build()).withResources(resources).endKafka().withNewZookeeper().withReplicas(zkReplicas).withStorage(zkStorage).endZookeeper().withNewEntityOperator().withNewTopicOperator().endTopicOperator().withNewUserOperator().endUserOperator().endEntityOperator().endSpec().build();
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(cluster).withStrimziPodSetCrd().withDeploymentController().withPodController().withStatefulSetController().withServiceController().build();
    mockKube.start();
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, kubernetesVersion);
    ResourceOperatorSupplier supplier = supplierWithMocks();
    ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
    operator = new KafkaAssemblyOperator(vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, config);
}
Also used : ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) MockKube2(io.strimzi.test.mockkube2.MockKube2) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder)

Aggregations

ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)44 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)44 Reconciliation (io.strimzi.operator.common.Reconciliation)42 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)40 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)40 Future (io.vertx.core.Future)40 Checkpoint (io.vertx.junit5.Checkpoint)40 VertxExtension (io.vertx.junit5.VertxExtension)40 VertxTestContext (io.vertx.junit5.VertxTestContext)40 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)40 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)40 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)40 Mockito.when (org.mockito.Mockito.when)40 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)38 Vertx (io.vertx.core.Vertx)38 List (java.util.List)38 CoreMatchers.is (org.hamcrest.CoreMatchers.is)38 KubernetesVersion (io.strimzi.operator.KubernetesVersion)36 Labels (io.strimzi.operator.common.model.Labels)36 Map (java.util.Map)36