Search in sources :

Example 6 with PersistentClaimStorageBuilder

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder in project strimzi by strimzi.

the class JbodStorageTest method testReconcileWithNewVolumeAddedToJbodStorage.

@Test
public void testReconcileWithNewVolumeAddedToJbodStorage(VertxTestContext context) {
    Checkpoint async = context.checkpoint();
    // Add a new volume to Jbod Storage
    volumes.add(new PersistentClaimStorageBuilder().withId(2).withDeleteClaim(false).withSize("100Gi").build());
    Kafka kafkaWithNewJbodVolume = new KafkaBuilder(kafka).editSpec().editKafka().withStorage(new JbodStorageBuilder().withVolumes(volumes).build()).endKafka().endSpec().build();
    Set<String> expectedPvcs = expectedPvcs(kafka);
    Set<String> expectedPvcsWithNewJbodStorageVolume = expectedPvcs(kafkaWithNewJbodVolume);
    // reconcile for kafka cluster creation
    operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME)).onComplete(context.succeeding(v -> context.verify(() -> {
        List<PersistentVolumeClaim> pvcs = getPvcs(NAMESPACE, NAME);
        Set<String> pvcsNames = pvcs.stream().map(pvc -> pvc.getMetadata().getName()).collect(Collectors.toSet());
        assertThat(pvcsNames, is(expectedPvcs));
    }))).compose(v -> {
        Crds.kafkaOperation(mockClient).inNamespace(NAMESPACE).withName(NAME).patch(kafkaWithNewJbodVolume);
        // reconcile kafka cluster with new Jbod storage
        return operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME));
    }).onComplete(context.succeeding(v -> context.verify(() -> {
        List<PersistentVolumeClaim> pvcs = getPvcs(NAMESPACE, NAME);
        Set<String> pvcsNames = pvcs.stream().map(pvc -> pvc.getMetadata().getName()).collect(Collectors.toSet());
        assertThat(pvcsNames, is(expectedPvcsWithNewJbodStorageVolume));
        async.flag();
    })));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) Annotations(io.strimzi.operator.common.Annotations) MockKube(io.strimzi.test.mockkube.MockKube) AfterAll(org.junit.jupiter.api.AfterAll) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Set(java.util.Set) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) VertxExtension(io.vertx.junit5.VertxExtension) Collectors(java.util.stream.Collectors) 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) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) VertxTestContext(io.vertx.junit5.VertxTestContext) KafkaList(io.strimzi.api.kafka.KafkaList) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) Crds(io.strimzi.api.kafka.Crds) VolumeUtils(io.strimzi.operator.cluster.model.VolumeUtils) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) FeatureGates(io.strimzi.operator.cluster.FeatureGates) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Matchers(org.hamcrest.Matchers) 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) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) Checkpoint(io.vertx.junit5.Checkpoint) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Test(org.junit.jupiter.api.Test)

Example 7 with PersistentClaimStorageBuilder

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder in project strimzi by strimzi.

the class KRaftUtilsTest method testInvalidKafka.

@ParallelTest
public void testInvalidKafka() {
    KafkaSpec spec = new KafkaSpecBuilder().withNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("listener").withPort(9092).withTls(true).withType(KafkaListenerType.INTERNAL).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build()).withNewJbodStorage().withVolumes(new PersistentClaimStorageBuilder().withId(0).withSize("100Gi").build(), new PersistentClaimStorageBuilder().withId(1).withSize("100Gi").build()).endJbodStorage().withNewKafkaAuthorizationSimple().endKafkaAuthorizationSimple().endKafka().build();
    InvalidResourceException ex = assertThrows(InvalidResourceException.class, () -> KRaftUtils.validateKafkaCrForKRaft(spec));
    assertThat(ex.getMessage(), is("Kafka configuration is not valid: [Authentication of type 'scram-sha-512` is currently not supported when the UseKRaft feature gate is enabled, Using more than one disk in a JBOD storage is currently not supported when the UseKRaft feature gate is enabled]"));
}
Also used : KafkaSpecBuilder(io.strimzi.api.kafka.model.KafkaSpecBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaSpec(io.strimzi.api.kafka.model.KafkaSpec) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 8 with PersistentClaimStorageBuilder

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder in project strimzi by strimzi.

the class KRaftUtilsTest method testJbodStorageWithMultipleDisks.

@ParallelTest
public void testJbodStorageWithMultipleDisks() {
    Set<String> errors = new HashSet<>(0);
    KafkaClusterSpec kcs = new KafkaClusterSpecBuilder().withNewJbodStorage().withVolumes(new PersistentClaimStorageBuilder().withId(0).withSize("100Gi").build(), new PersistentClaimStorageBuilder().withId(1).withSize("100Gi").build()).endJbodStorage().build();
    KRaftUtils.validateKafkaSpec(errors, kcs);
    assertThat(errors, is(Set.of("Using more than one disk in a JBOD storage is currently not supported when the UseKRaft feature gate is enabled")));
}
Also used : KafkaClusterSpec(io.strimzi.api.kafka.model.KafkaClusterSpec) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaClusterSpecBuilder(io.strimzi.api.kafka.model.KafkaClusterSpecBuilder) HashSet(java.util.HashSet) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 9 with PersistentClaimStorageBuilder

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder in project strimzi by strimzi.

the class AbstractModelTest method testCreatePersistentVolumeClaims.

@ParallelTest
public void testCreatePersistentVolumeClaims() {
    Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().withNewSpec().withNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withTls(false).withType(KafkaListenerType.INTERNAL).build()).withReplicas(2).withNewEphemeralStorage().endEphemeralStorage().endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, KafkaVersionTestUtils.getKafkaVersionLookup());
    // JBOD Storage
    Storage storage = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withDeleteClaim(false).withId(0).withSize("20Gi").build(), new PersistentClaimStorageBuilder().withDeleteClaim(true).withId(1).withSize("10Gi").build()).build();
    List<PersistentVolumeClaim> pvcs = kc.generatePersistentVolumeClaims(storage);
    assertThat(pvcs.size(), is(4));
    assertThat(pvcs.get(0).getMetadata().getName(), is("data-0-my-cluster-kafka-0"));
    assertThat(pvcs.get(1).getMetadata().getName(), is("data-0-my-cluster-kafka-1"));
    assertThat(pvcs.get(2).getMetadata().getName(), is("data-1-my-cluster-kafka-0"));
    assertThat(pvcs.get(3).getMetadata().getName(), is("data-1-my-cluster-kafka-1"));
    // JBOD with Ephemeral storage
    storage = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withDeleteClaim(false).withId(0).withSize("20Gi").build(), new EphemeralStorageBuilder().withId(1).build()).build();
    pvcs = kc.generatePersistentVolumeClaims(storage);
    assertThat(pvcs.size(), is(2));
    assertThat(pvcs.get(0).getMetadata().getName(), is("data-0-my-cluster-kafka-0"));
    assertThat(pvcs.get(1).getMetadata().getName(), is("data-0-my-cluster-kafka-1"));
    // Persistent Claim storage
    storage = new PersistentClaimStorageBuilder().withDeleteClaim(false).withSize("20Gi").build();
    pvcs = kc.generatePersistentVolumeClaims(storage);
    assertThat(pvcs.size(), is(2));
    assertThat(pvcs.get(0).getMetadata().getName(), is("data-my-cluster-kafka-0"));
    assertThat(pvcs.get(1).getMetadata().getName(), is("data-my-cluster-kafka-1"));
    // Persistent Claim with ID storage
    storage = new PersistentClaimStorageBuilder().withDeleteClaim(false).withId(0).withSize("20Gi").build();
    pvcs = kc.generatePersistentVolumeClaims(storage);
    assertThat(pvcs.size(), is(2));
    assertThat(pvcs.get(0).getMetadata().getName(), is("data-my-cluster-kafka-0"));
    assertThat(pvcs.get(1).getMetadata().getName(), is("data-my-cluster-kafka-1"));
    // Ephemeral Storage
    storage = new EphemeralStorageBuilder().build();
    pvcs = kc.generatePersistentVolumeClaims(storage);
    assertThat(pvcs.size(), is(0));
    // JBOD Storage without ID
    final Storage finalStorage = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withDeleteClaim(false).withSize("20Gi").build()).build();
    InvalidResourceException ex = Assertions.assertThrows(InvalidResourceException.class, () -> kc.generatePersistentVolumeClaims(finalStorage));
    assertThat(ex.getMessage(), is("The 'id' property is required for volumes in JBOD storage."));
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) Storage(io.strimzi.api.kafka.model.storage.Storage) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) EphemeralStorageBuilder(io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 10 with PersistentClaimStorageBuilder

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder in project strimzi by strimzi.

the class KafkaBrokerConfigurationBuilderTest method testPersistentStorageLogDirs.

@ParallelTest
public void testPersistentStorageLogDirs() {
    Storage storage = new PersistentClaimStorageBuilder().withSize("1Ti").withStorageClass("aws-ebs").withDeleteClaim(true).build();
    String configuration = new KafkaBrokerConfigurationBuilder(Reconciliation.DUMMY_RECONCILIATION).withLogDirs(VolumeUtils.createVolumeMounts(storage, "/var/lib/kafka", false)).build();
    assertThat(configuration, isEquivalent("log.dirs=/var/lib/kafka/data/kafka-log${STRIMZI_BROKER_ID}"));
}
Also used : Storage(io.strimzi.api.kafka.model.storage.Storage) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

PersistentClaimStorageBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)95 ParallelTest (io.strimzi.test.annotations.ParallelTest)64 JbodStorageBuilder (io.strimzi.api.kafka.model.storage.JbodStorageBuilder)52 Storage (io.strimzi.api.kafka.model.storage.Storage)45 Kafka (io.strimzi.api.kafka.model.Kafka)38 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)36 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)23 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)22 SingleVolumeStorage (io.strimzi.api.kafka.model.storage.SingleVolumeStorage)21 JbodStorage (io.strimzi.api.kafka.model.storage.JbodStorage)20 ArrayList (java.util.ArrayList)19 PersistentClaimStorageOverrideBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder)17 Quantity (io.fabric8.kubernetes.api.model.Quantity)16 EphemeralStorageBuilder (io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder)16 List (java.util.List)16 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)15 KRaftNotSupported (io.strimzi.systemtest.annotations.KRaftNotSupported)14 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)14 Map (java.util.Map)14 CoreMatchers.is (org.hamcrest.CoreMatchers.is)14