Search in sources :

Example 16 with EphemeralStorageBuilder

use of io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaClusterTest method testStorageReverting.

@ParallelTest
public void testStorageReverting() {
    Storage jbod = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build(), new PersistentClaimStorageBuilder().withStorageClass("gp2-st1").withDeleteClaim(true).withId(1).withSize("1000Gi").build()).build();
    Storage ephemeral = new EphemeralStorageBuilder().build();
    Storage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build();
    // Test Storage changes and how the are reverted
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withStorage(jbod).endKafka().endSpec().build();
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS, ephemeral, replicas);
    // Storage is reverted
    assertThat(kc.getStorage(), is(ephemeral));
    // Warning status condition is set
    assertThat(kc.getWarningConditions().size(), is(1));
    assertThat(kc.getWarningConditions().get(0).getReason(), is("KafkaStorage"));
    kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withStorage(jbod).endKafka().endSpec().build();
    kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS, persistent, replicas);
    // Storage is reverted
    assertThat(kc.getStorage(), is(persistent));
    // Warning status condition is set
    assertThat(kc.getWarningConditions().size(), is(1));
    assertThat(kc.getWarningConditions().get(0).getReason(), is("KafkaStorage"));
    kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withStorage(ephemeral).endKafka().endSpec().build();
    kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS, jbod, replicas);
    // Storage is reverted
    assertThat(kc.getStorage(), is(jbod));
    // Warning status condition is set
    assertThat(kc.getWarningConditions().size(), is(1));
    assertThat(kc.getWarningConditions().get(0).getReason(), is("KafkaStorage"));
    kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withStorage(persistent).endKafka().endSpec().build();
    kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS, jbod, replicas);
    // Storage is reverted
    assertThat(kc.getStorage(), is(jbod));
    // Warning status condition is set
    assertThat(kc.getWarningConditions().size(), is(1));
    assertThat(kc.getWarningConditions().get(0).getReason(), is("KafkaStorage"));
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) Storage(io.strimzi.api.kafka.model.storage.Storage) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) EphemeralStorageBuilder(io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 17 with EphemeralStorageBuilder

use of io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder in project strimzi-kafka-operator 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 18 with EphemeralStorageBuilder

use of io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder in project strimzi-kafka-operator by strimzi.

the class StorageUtilsTest method testEphemeralStorage.

@ParallelTest
public void testEphemeralStorage() {
    Storage notEphemeral = new PersistentClaimStorageBuilder().build();
    Storage isEphemeral = new EphemeralStorageBuilder().build();
    Storage includesEphemeral = new JbodStorageBuilder().withVolumes(new EphemeralStorageBuilder().withId(1).build(), new EphemeralStorageBuilder().withId(2).build()).build();
    assertThat(StorageUtils.usesEphemeral(notEphemeral), is(false));
    assertThat(StorageUtils.usesEphemeral(isEphemeral), is(true));
    assertThat(StorageUtils.usesEphemeral(includesEphemeral), is(true));
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) Storage(io.strimzi.api.kafka.model.storage.Storage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) EphemeralStorageBuilder(io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 19 with EphemeralStorageBuilder

use of io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder in project strimzi-kafka-operator by strimzi.

the class ZookeeperClusterTest method testStorageReverting.

@ParallelTest
public void testStorageReverting() {
    SingleVolumeStorage ephemeral = new EphemeralStorageBuilder().build();
    SingleVolumeStorage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build();
    // Test Storage changes and how the are reverted
    Kafka ka = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configurationJson, zooConfigurationJson)).editSpec().editZookeeper().withStorage(ephemeral).endZookeeper().endSpec().build();
    ZookeeperCluster zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, ka, VERSIONS, persistent, replicas);
    assertThat(zc.getStorage(), is(persistent));
    ka = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configurationJson, zooConfigurationJson)).editSpec().editZookeeper().withStorage(persistent).endZookeeper().endSpec().build();
    zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, ka, VERSIONS, ephemeral, replicas);
    // Storage is reverted
    assertThat(zc.getStorage(), is(ephemeral));
    // Warning status condition is set
    assertThat(zc.getWarningConditions().size(), is(1));
    assertThat(zc.getWarningConditions().get(0).getReason(), is("ZooKeeperStorage"));
}
Also used : SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) EphemeralStorageBuilder(io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 20 with EphemeralStorageBuilder

use of io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder in project strimzi-kafka-operator by strimzi.

the class ModelUtilsTest method testStorageSerializationAndDeserialization.

@ParallelTest
public void testStorageSerializationAndDeserialization() {
    Storage jbod = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build(), new PersistentClaimStorageBuilder().withStorageClass("gp2-st1").withDeleteClaim(true).withId(1).withSize("1000Gi").build()).build();
    Storage ephemeral = new EphemeralStorageBuilder().build();
    Storage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build();
    assertThat(ModelUtils.decodeStorageFromJson(ModelUtils.encodeStorageToJson(jbod)), is(jbod));
    assertThat(ModelUtils.decodeStorageFromJson(ModelUtils.encodeStorageToJson(ephemeral)), is(ephemeral));
    assertThat(ModelUtils.decodeStorageFromJson(ModelUtils.encodeStorageToJson(persistent)), is(persistent));
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) Storage(io.strimzi.api.kafka.model.storage.Storage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) EphemeralStorageBuilder(io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

EphemeralStorageBuilder (io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder)20 ParallelTest (io.strimzi.test.annotations.ParallelTest)18 Storage (io.strimzi.api.kafka.model.storage.Storage)16 JbodStorageBuilder (io.strimzi.api.kafka.model.storage.JbodStorageBuilder)14 PersistentClaimStorageBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)14 Kafka (io.strimzi.api.kafka.model.Kafka)8 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)8 SingleVolumeStorage (io.strimzi.api.kafka.model.storage.SingleVolumeStorage)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)2 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)2 Condition (io.strimzi.api.kafka.model.status.Condition)2 EphemeralStorage (io.strimzi.api.kafka.model.storage.EphemeralStorage)2 Test (org.junit.jupiter.api.Test)2