Search in sources :

Example 16 with Storage

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

the class StorageDiffTest method testEphemeralDiff.

@ParallelTest
public void testEphemeralDiff() {
    Storage ephemeral = new EphemeralStorageBuilder().build();
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, ephemeral, ephemeral, 3, 3).changesType(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, ephemeral, ephemeral, 3, 3).isEmpty(), is(true));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, ephemeral, ephemeral, 3, 3).shrinkSize(), is(false));
}
Also used : Storage(io.strimzi.api.kafka.model.storage.Storage) EphemeralStorageBuilder(io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 17 with Storage

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

the class StorageDiffTest method testPersistentDiff.

@ParallelTest
public void testPersistentDiff() {
    Storage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build();
    Storage persistent2 = new PersistentClaimStorageBuilder().withStorageClass("gp2-st1").withDeleteClaim(false).withId(0).withSize("1000Gi").build();
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent, 3, 3).changesType(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent, 3, 3).isEmpty(), is(true));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent, 3, 3).shrinkSize(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 3, 3).changesType(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 3, 3).isEmpty(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 3, 3).shrinkSize(), is(false));
}
Also used : Storage(io.strimzi.api.kafka.model.storage.Storage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 18 with Storage

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

the class StorageDiffTest method testJbodDiffWithNewVolume.

@ParallelTest
public void testJbodDiffWithNewVolume() {
    Storage jbod = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("1000Gi").build()).build();
    Storage jbod2 = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("1000Gi").build(), new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(true).withId(1).withSize("1000Gi").build()).build();
    Storage jbod3 = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-st1").withDeleteClaim(false).withId(0).withSize("100Gi").build(), new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(true).withId(1).withSize("1000Gi").build()).build();
    Storage jbod4 = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(2).withSize("1000Gi").build()).build();
    Storage jbod5 = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(true).withId(1).withSize("1000Gi").build()).build();
    Storage jbod6 = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("1000Gi").build(), new PersistentClaimStorageBuilder().withStorageClass("gp2-st1").withDeleteClaim(true).withId(2).withSize("5000Gi").build()).build();
    // Volume added
    StorageDiff diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod, jbod2, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(true));
    assertThat(diff.shrinkSize(), is(false));
    assertThat(diff.isVolumesAddedOrRemoved(), is(true));
    // Volume removed
    diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod2, jbod, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(true));
    assertThat(diff.shrinkSize(), is(false));
    assertThat(diff.isVolumesAddedOrRemoved(), is(true));
    // Volume added with changes
    diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod, jbod3, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(false));
    assertThat(diff.shrinkSize(), is(true));
    assertThat(diff.isVolumesAddedOrRemoved(), is(true));
    // No volume added, but with changes
    diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod2, jbod3, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(false));
    assertThat(diff.shrinkSize(), is(true));
    assertThat(diff.isVolumesAddedOrRemoved(), is(false));
    // Volume removed from the beginning
    diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod3, jbod5, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(true));
    assertThat(diff.shrinkSize(), is(false));
    assertThat(diff.isVolumesAddedOrRemoved(), is(true));
    // Volume added to the beginning
    diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod5, jbod3, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(true));
    assertThat(diff.shrinkSize(), is(false));
    assertThat(diff.isVolumesAddedOrRemoved(), is(true));
    // Volume replaced with another ID and another volume which is kept changed
    diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod3, jbod6, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(false));
    assertThat(diff.shrinkSize(), is(false));
    assertThat(diff.isVolumesAddedOrRemoved(), is(true));
    // Volume replaced with another ID in single volume broker
    diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod, jbod4, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(true));
    assertThat(diff.shrinkSize(), is(false));
    assertThat(diff.isVolumesAddedOrRemoved(), is(true));
    // Volume replaced with another ID without chenging the volumes which are kept
    diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod2, jbod6, 3, 3);
    assertThat(diff.changesType(), is(false));
    assertThat(diff.isEmpty(), is(true));
    assertThat(diff.shrinkSize(), is(false));
    assertThat(diff.isVolumesAddedOrRemoved(), 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) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 19 with Storage

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

the class StorageDiffTest method testSizeChanges.

@ParallelTest
public void testSizeChanges() {
    Storage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build();
    Storage persistent2 = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("1000Gi").build();
    Storage persistent3 = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("10Gi").build();
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent, 3, 3).shrinkSize(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 3, 3).shrinkSize(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent3, 3, 3).shrinkSize(), is(true));
}
Also used : Storage(io.strimzi.api.kafka.model.storage.Storage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 20 with Storage

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

the class KafkaAssemblyOperatorMockTest method testReconcileUpdatesKafkaStorageType.

@ParameterizedTest
@MethodSource("data")
public void testReconcileUpdatesKafkaStorageType(Params params, VertxTestContext context) {
    init(params);
    AtomicReference<List<PersistentVolumeClaim>> originalPVCs = new AtomicReference<>();
    AtomicReference<List<Volume>> originalVolumes = new AtomicReference<>();
    AtomicReference<List<Container>> originalInitContainers = new AtomicReference<>();
    Checkpoint async = context.checkpoint();
    initialReconcile(context).onComplete(context.succeeding(v -> context.verify(() -> {
        originalPVCs.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getVolumeClaimTemplates).orElse(new ArrayList<>()));
        originalVolumes.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getTemplate).map(PodTemplateSpec::getSpec).map(PodSpec::getVolumes).orElse(new ArrayList<>()));
        originalInitContainers.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getTemplate).map(PodTemplateSpec::getSpec).map(PodSpec::getInitContainers).orElse(new ArrayList<>()));
        // Update the storage type
        // ephemeral -> persistent
        // or
        // persistent -> ephemeral
        Kafka updatedStorageKafka = null;
        if (kafkaStorage instanceof EphemeralStorage) {
            updatedStorageKafka = new KafkaBuilder(cluster).editSpec().editKafka().withNewPersistentClaimStorage().withSize("123").endPersistentClaimStorage().endKafka().endSpec().build();
        } else if (kafkaStorage instanceof PersistentClaimStorage) {
            updatedStorageKafka = new KafkaBuilder(cluster).editSpec().editKafka().withNewEphemeralStorage().endEphemeralStorage().endKafka().endSpec().build();
        } else {
            context.failNow(new Exception("If storage is not ephemeral or persistent something has gone wrong"));
        }
        kafkaAssembly(NAMESPACE, CLUSTER_NAME).patch(updatedStorageKafka);
        LOGGER.info("Updating with changed storage type");
    }))).compose(v -> operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME))).onComplete(context.succeeding(v -> context.verify(() -> {
        // Check the Volumes and PVCs were not changed
        assertPVCs(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalPVCs.get());
        assertVolumes(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalVolumes.get());
        assertInitContainers(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalInitContainers.get());
        async.flag();
    })));
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) DeletionPropagation(io.fabric8.kubernetes.api.model.DeletionPropagation) Storage(io.strimzi.api.kafka.model.storage.Storage) StatefulSetStatus(io.fabric8.kubernetes.api.model.apps.StatefulSetStatus) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) MockKube(io.strimzi.test.mockkube.MockKube) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) Resource(io.fabric8.kubernetes.client.dsl.Resource) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Ca(io.strimzi.operator.cluster.model.Ca) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) StatefulSetOperator(io.strimzi.operator.cluster.operator.resource.StatefulSetOperator) MethodSource(org.junit.jupiter.params.provider.MethodSource) 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) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) StatefulSetSpec(io.fabric8.kubernetes.api.model.apps.StatefulSetSpec) List(java.util.List) EphemeralStorage(io.strimzi.api.kafka.model.storage.EphemeralStorage) KafkaConfiguration(io.strimzi.operator.cluster.model.KafkaConfiguration) Labels(io.strimzi.operator.common.model.Labels) Logger(org.apache.logging.log4j.Logger) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Optional(java.util.Optional) 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) KafkaList(io.strimzi.api.kafka.KafkaList) Matchers.aMapWithSize(org.hamcrest.Matchers.aMapWithSize) Container(io.fabric8.kubernetes.api.model.Container) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) HashMap(java.util.HashMap) Storage.deleteClaim(io.strimzi.api.kafka.model.storage.Storage.deleteClaim) Crds(io.strimzi.api.kafka.Crds) ZookeeperCluster(io.strimzi.operator.cluster.model.ZookeeperCluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) FeatureGates(io.strimzi.operator.cluster.FeatureGates) ArrayList(java.util.ArrayList) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Volume(io.fabric8.kubernetes.api.model.Volume) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Reconciliation(io.strimzi.operator.common.Reconciliation) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) StatefulSetSpec(io.fabric8.kubernetes.api.model.apps.StatefulSetSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ArrayList(java.util.ArrayList) Kafka(io.strimzi.api.kafka.model.Kafka) AtomicReference(java.util.concurrent.atomic.AtomicReference) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) Checkpoint(io.vertx.junit5.Checkpoint) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) KafkaList(io.strimzi.api.kafka.KafkaList) ArrayList(java.util.ArrayList) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) EphemeralStorage(io.strimzi.api.kafka.model.storage.EphemeralStorage) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Storage (io.strimzi.api.kafka.model.storage.Storage)56 PersistentClaimStorageBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)46 ParallelTest (io.strimzi.test.annotations.ParallelTest)42 JbodStorageBuilder (io.strimzi.api.kafka.model.storage.JbodStorageBuilder)20 SingleVolumeStorage (io.strimzi.api.kafka.model.storage.SingleVolumeStorage)18 EphemeralStorageBuilder (io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder)16 Kafka (io.strimzi.api.kafka.model.Kafka)14 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)14 PersistentClaimStorage (io.strimzi.api.kafka.model.storage.PersistentClaimStorage)10 PersistentClaimStorageOverrideBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder)9 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)8 Quantity (io.fabric8.kubernetes.api.model.Quantity)8 ResourceRequirements (io.fabric8.kubernetes.api.model.ResourceRequirements)8 ResourceRequirementsBuilder (io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder)8 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)8 EphemeralStorage (io.strimzi.api.kafka.model.storage.EphemeralStorage)8 Checkpoint (io.vertx.junit5.Checkpoint)8 ArrayList (java.util.ArrayList)8 Container (io.fabric8.kubernetes.api.model.Container)6 DeletionPropagation (io.fabric8.kubernetes.api.model.DeletionPropagation)6