Search in sources :

Example 26 with CertManager

use of io.strimzi.certs.CertManager in project strimzi by strimzi.

the class VolumeResizingTest method testNotBoundVolumes.

@Test
public void testNotBoundVolumes() {
    Kafka kafka = getKafkaCrd();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the PVC Operator
    PvcOperator mockPvcOps = supplier.pvcOperations;
    List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage());
    when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))).thenAnswer(invocation -> {
        String pvcName = invocation.getArgument(1);
        return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null));
    });
    ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class);
    when(mockPvcOps.reconcile(any(), anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture());
    // Mock the StorageClass Operator
    StorageClassOperator mockSco = supplier.storageClassOperations;
    when(mockSco.getAsync(eq("mysc"))).thenAnswer(invocation -> {
        StorageClass sc = new StorageClassBuilder().withNewMetadata().withName("mysc").endMetadata().withAllowVolumeExpansion(true).build();
        return Future.succeededFuture(sc);
    });
    MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> {
        assertThat(res.succeeded(), is(true));
        assertThat(pvcCaptor.getAllValues().size(), is(3));
        assertThat(pvcCaptor.getAllValues(), is(kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage())));
    });
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers(org.mockito.ArgumentMatchers) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CertManager(io.strimzi.certs.CertManager) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PersistentVolumeClaimConditionBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimConditionBuilder) AfterAll(org.junit.jupiter.api.AfterAll) ArgumentCaptor(org.mockito.ArgumentCaptor) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) PersistentVolumeClaimStatusBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatusBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Collections.singletonMap(java.util.Collections.singletonMap) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) StorageClassOperator(io.strimzi.operator.common.operator.resource.StorageClassOperator) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Mockito.when(org.mockito.Mockito.when) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) Future(io.vertx.core.Future) StorageClassBuilder(io.fabric8.kubernetes.api.model.storage.StorageClassBuilder) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) StorageClass(io.fabric8.kubernetes.api.model.storage.StorageClass) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Kafka(io.strimzi.api.kafka.model.Kafka) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) StorageClassOperator(io.strimzi.operator.common.operator.resource.StorageClassOperator) StorageClass(io.fabric8.kubernetes.api.model.storage.StorageClass) Kafka(io.strimzi.api.kafka.model.Kafka) StorageClassBuilder(io.fabric8.kubernetes.api.model.storage.StorageClassBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Test(org.junit.jupiter.api.Test)

Example 27 with CertManager

use of io.strimzi.certs.CertManager in project strimzi by strimzi.

the class VolumeResizingTest method testVolumesWaitingForRestart.

@Test
public void testVolumesWaitingForRestart() {
    Kafka kafka = getKafkaCrd();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the PVC Operator
    PvcOperator mockPvcOps = supplier.pvcOperations;
    List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage());
    for (PersistentVolumeClaim pvc : realPvcs) {
        pvc.setStatus(new PersistentVolumeClaimStatusBuilder().withPhase("Bound").withConditions(new PersistentVolumeClaimConditionBuilder().withStatus("True").withType("FileSystemResizePending").build()).withCapacity(singletonMap("storage", new Quantity("10Gi"))).build());
    }
    when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))).thenAnswer(invocation -> {
        String pvcName = invocation.getArgument(1);
        return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null));
    });
    ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class);
    when(mockPvcOps.reconcile(any(), anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture());
    // Mock the StorageClass Operator
    StorageClassOperator mockSco = supplier.storageClassOperations;
    when(mockSco.getAsync(eq("mysc"))).thenAnswer(invocation -> {
        StorageClass sc = new StorageClassBuilder().withNewMetadata().withName("mysc").endMetadata().withAllowVolumeExpansion(true).build();
        return Future.succeededFuture(sc);
    });
    MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> {
        assertThat(res.succeeded(), is(true));
        // The volumes are waiting for pod restart => no reconciliation
        assertThat(pvcCaptor.getAllValues().size(), is(0));
        for (int i = 0; i < kafkaCluster.getReplicas(); i++) {
            assertThat(res.result().fsResizingRestartRequest.contains(kafkaCluster.getPodName(i)), is(true));
        }
    });
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers(org.mockito.ArgumentMatchers) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CertManager(io.strimzi.certs.CertManager) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PersistentVolumeClaimConditionBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimConditionBuilder) AfterAll(org.junit.jupiter.api.AfterAll) ArgumentCaptor(org.mockito.ArgumentCaptor) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) PersistentVolumeClaimStatusBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatusBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Collections.singletonMap(java.util.Collections.singletonMap) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) StorageClassOperator(io.strimzi.operator.common.operator.resource.StorageClassOperator) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Mockito.when(org.mockito.Mockito.when) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) Future(io.vertx.core.Future) StorageClassBuilder(io.fabric8.kubernetes.api.model.storage.StorageClassBuilder) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) StorageClass(io.fabric8.kubernetes.api.model.storage.StorageClass) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Kafka(io.strimzi.api.kafka.model.Kafka) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PersistentVolumeClaimStatusBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatusBuilder) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) StorageClassOperator(io.strimzi.operator.common.operator.resource.StorageClassOperator) StorageClass(io.fabric8.kubernetes.api.model.storage.StorageClass) Kafka(io.strimzi.api.kafka.model.Kafka) Quantity(io.fabric8.kubernetes.api.model.Quantity) StorageClassBuilder(io.fabric8.kubernetes.api.model.storage.StorageClassBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) PersistentVolumeClaimConditionBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimConditionBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Test(org.junit.jupiter.api.Test)

Example 28 with CertManager

use of io.strimzi.certs.CertManager in project strimzi by strimzi.

the class KafkaStatusTest method testModelWarnings.

@Test
public void testModelWarnings(VertxTestContext context) throws ParseException {
    Kafka kafka = getKafkaCrd();
    Kafka oldKafka = new KafkaBuilder(getKafkaCrd()).editOrNewSpec().editOrNewKafka().withNewPersistentClaimStorage().withSize("100Gi").endPersistentClaimStorage().endKafka().endSpec().build();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, oldKafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the CRD Operator for Kafka resources
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
    when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
    ArgumentCaptor<Kafka> kafkaCaptor = ArgumentCaptor.forClass(Kafka.class);
    when(mockKafkaOps.updateStatusAsync(any(), kafkaCaptor.capture())).thenReturn(Future.succeededFuture());
    // Mock the KafkaSetOperator
    StatefulSetOperator mockStsOps = supplier.stsOperations;
    when(mockStsOps.getAsync(eq(namespace), eq(KafkaCluster.kafkaClusterName(clusterName)))).thenReturn(Future.succeededFuture(kafkaCluster.generateStatefulSet(false, null, null, null)));
    // Mock the StrimziPodSet operator
    CrdOperator<KubernetesClient, StrimziPodSet, StrimziPodSetList> mockPodSetOps = supplier.strimziPodSetOperator;
    when(mockPodSetOps.getAsync(any(), any())).thenReturn(Future.succeededFuture(null));
    // Mock the ConfigMapOperator
    ConfigMapOperator mockCmOps = supplier.configMapOperations;
    when(mockCmOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafkaCluster.generateMetricsAndLogConfigMap(new MetricsAndLogging(null, null))));
    // Mock the PodOperator
    PodOperator mockPodOps = supplier.podOperations;
    when(mockPodOps.listAsync(eq(namespace), any(Labels.class))).thenReturn(Future.succeededFuture(emptyList()));
    MockModelWarningsStatusKafkaAssemblyOperator kao = new MockModelWarningsStatusKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(kafkaCaptor.getValue(), is(notNullValue()));
        assertThat(kafkaCaptor.getValue().getStatus(), is(notNullValue()));
        KafkaStatus status = kafkaCaptor.getValue().getStatus();
        assertThat(status.getConditions().size(), is(2));
        assertThat(status.getConditions().get(0).getType(), is("Warning"));
        assertThat(status.getConditions().get(0).getReason(), is("KafkaStorage"));
        assertThat(status.getConditions().get(1).getType(), is("Ready"));
        async.flag();
    })));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) BeforeAll(org.junit.jupiter.api.BeforeAll) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) ParseException(java.text.ParseException) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) Collections.emptyList(java.util.Collections.emptyList) ListenerAddress(io.strimzi.api.kafka.model.status.ListenerAddress) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) ListenerStatus(io.strimzi.api.kafka.model.status.ListenerStatus) Test(org.junit.jupiter.api.Test) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) NodeAddressType(io.strimzi.api.kafka.model.listener.NodeAddressType) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) 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) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) CertManager(io.strimzi.certs.CertManager) SimpleDateFormat(java.text.SimpleDateFormat) ListenerAddressBuilder(io.strimzi.api.kafka.model.status.ListenerAddressBuilder) ListenerStatusBuilder(io.strimzi.api.kafka.model.status.ListenerStatusBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) ArrayList(java.util.ArrayList) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) ArgumentCaptor(org.mockito.ArgumentCaptor) NodeBuilder(io.fabric8.kubernetes.api.model.NodeBuilder) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Node(io.fabric8.kubernetes.api.model.Node) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) NodeOperator(io.strimzi.operator.common.operator.resource.NodeOperator) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) 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) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Kafka(io.strimzi.api.kafka.model.Kafka) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Labels(io.strimzi.operator.common.model.Labels) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) KafkaStatus(io.strimzi.api.kafka.model.status.KafkaStatus) Test(org.junit.jupiter.api.Test)

Example 29 with CertManager

use of io.strimzi.certs.CertManager in project strimzi by strimzi.

the class VolumeResizingTest method testVolumesBoundNonExpandableStorageClass.

@Test
public void testVolumesBoundNonExpandableStorageClass() {
    Kafka kafka = getKafkaCrd();
    KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the PVC Operator
    PvcOperator mockPvcOps = supplier.pvcOperations;
    List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage());
    for (PersistentVolumeClaim pvc : realPvcs) {
        pvc.getSpec().getResources().getRequests().put("storage", new Quantity("10Gi"));
        pvc.setStatus(new PersistentVolumeClaimStatusBuilder().withPhase("Bound").withCapacity(pvc.getSpec().getResources().getRequests()).build());
    }
    when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))).thenAnswer(invocation -> {
        String pvcName = invocation.getArgument(1);
        return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null));
    });
    ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class);
    when(mockPvcOps.reconcile(any(), anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture());
    // Mock the StorageClass Operator
    StorageClassOperator mockSco = supplier.storageClassOperations;
    when(mockSco.getAsync(eq("mysc"))).thenAnswer(invocation -> {
        StorageClass sc = new StorageClassBuilder().withNewMetadata().withName("mysc").endMetadata().withAllowVolumeExpansion(false).build();
        return Future.succeededFuture(sc);
    });
    MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
    kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> {
        assertThat(res.succeeded(), is(true));
        // Resizing is not supported, we do not reconcile
        assertThat(pvcCaptor.getAllValues().size(), is(0));
    });
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers(org.mockito.ArgumentMatchers) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CertManager(io.strimzi.certs.CertManager) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PersistentVolumeClaimConditionBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimConditionBuilder) AfterAll(org.junit.jupiter.api.AfterAll) ArgumentCaptor(org.mockito.ArgumentCaptor) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) PersistentVolumeClaimStatusBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatusBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Collections.singletonMap(java.util.Collections.singletonMap) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) StorageClassOperator(io.strimzi.operator.common.operator.resource.StorageClassOperator) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Mockito.when(org.mockito.Mockito.when) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) Future(io.vertx.core.Future) StorageClassBuilder(io.fabric8.kubernetes.api.model.storage.StorageClassBuilder) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) StorageClass(io.fabric8.kubernetes.api.model.storage.StorageClass) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Kafka(io.strimzi.api.kafka.model.Kafka) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PersistentVolumeClaimStatusBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimStatusBuilder) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) StorageClassOperator(io.strimzi.operator.common.operator.resource.StorageClassOperator) StorageClass(io.fabric8.kubernetes.api.model.storage.StorageClass) Kafka(io.strimzi.api.kafka.model.Kafka) Quantity(io.fabric8.kubernetes.api.model.Quantity) StorageClassBuilder(io.fabric8.kubernetes.api.model.storage.StorageClassBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PvcOperator(io.strimzi.operator.common.operator.resource.PvcOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Reconciliation(io.strimzi.operator.common.Reconciliation) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Test(org.junit.jupiter.api.Test)

Example 30 with CertManager

use of io.strimzi.certs.CertManager in project strimzi by strimzi.

the class KafkaAssemblyOperatorRbacScopeTest method testRolesDeployedWhenNamespaceRbacScope.

/**
 * This test checks that when STRIMZI_RBAC_SCOPE feature is set to 'NAMESPACE', the cluster operator only
 * deploys and binds to Roles
 */
@Test
public void testRolesDeployedWhenNamespaceRbacScope(VertxTestContext context) {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName(clusterName).withNamespace(namespace).endMetadata().withNewSpec().withNewKafka().withReplicas(3).endKafka().withNewZookeeper().withReplicas(3).endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Mock the CRD Operator for Kafka resources
    CrdOperator mockKafkaOps = supplier.kafkaOperator;
    when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
    when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
    when(mockKafkaOps.updateStatusAsync(any(), any(Kafka.class))).thenReturn(Future.succeededFuture());
    // Mock the operations for RoleBindings
    RoleBindingOperator mockRoleBindingOps = supplier.roleBindingOperations;
    // Capture the names of reconciled rolebindings and their patched state
    ArgumentCaptor<String> roleBindingNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<RoleBinding> roleBindingCaptor = ArgumentCaptor.forClass(RoleBinding.class);
    when(mockRoleBindingOps.reconcile(any(), eq(namespace), roleBindingNameCaptor.capture(), roleBindingCaptor.capture())).thenReturn(Future.succeededFuture());
    KafkaAssemblyOperatorRolesSubset kao = new KafkaAssemblyOperatorRolesSubset(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, configNamespaceRbacScope);
    Checkpoint async = context.checkpoint();
    kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(context.succeeding(v -> context.verify(() -> {
        List<String> roleBindingNames = roleBindingNameCaptor.getAllValues();
        List<RoleBinding> roleBindings = roleBindingCaptor.getAllValues();
        assertThat(roleBindingNames, hasSize(2));
        assertThat(roleBindings, hasSize(2));
        // Check all RoleBindings, easier to index by order applied
        assertThat(roleBindingNames.get(0), is("test-instance-entity-topic-operator-role"));
        assertThat(roleBindings.get(0), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName("test-instance-entity-operator").build()));
        assertThat(roleBindingNames.get(1), is("test-instance-entity-user-operator-role"));
        assertThat(roleBindings.get(1), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName("test-instance-entity-operator").build()));
        verify(supplier.clusterRoleBindingOperator, never()).reconcile(any(), anyString(), any());
        async.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Role(io.fabric8.kubernetes.api.model.rbac.Role) CertManager(io.strimzi.certs.CertManager) RoleBindingOperator(io.strimzi.operator.common.operator.resource.RoleBindingOperator) RoleOperator(io.strimzi.operator.common.operator.resource.RoleOperator) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher) AfterAll(org.junit.jupiter.api.AfterAll) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) BeforeAll(org.junit.jupiter.api.BeforeAll) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Description(org.hamcrest.Description) KubernetesVersion(io.strimzi.operator.KubernetesVersion) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Vertx(io.vertx.core.Vertx) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder) Mockito.when(org.mockito.Mockito.when) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Mockito.never(org.mockito.Mockito.never) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Matcher(org.hamcrest.Matcher) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.is(org.hamcrest.Matchers.is) EntityOperator(io.strimzi.operator.cluster.model.EntityOperator) Kafka(io.strimzi.api.kafka.model.Kafka) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) RoleBindingOperator(io.strimzi.operator.common.operator.resource.RoleBindingOperator) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Kafka (io.strimzi.api.kafka.model.Kafka)32 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)32 CertManager (io.strimzi.certs.CertManager)32 KubernetesVersion (io.strimzi.operator.KubernetesVersion)32 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)32 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)32 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)32 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)32 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)32 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)32 Reconciliation (io.strimzi.operator.common.Reconciliation)32 Future (io.vertx.core.Future)32 Vertx (io.vertx.core.Vertx)32 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)32 AfterAll (org.junit.jupiter.api.AfterAll)32 BeforeAll (org.junit.jupiter.api.BeforeAll)32 Test (org.junit.jupiter.api.Test)32 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)32 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)32 Mockito.when (org.mockito.Mockito.when)32