Search in sources :

Example 21 with JbodStorage

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

the class KafkaST method testKafkaJBODDeleteClaimsFalse.

@ParallelNamespaceTest
void testKafkaJBODDeleteClaimsFalse(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final int kafkaReplicas = 2;
    final String diskSizeGi = "10";
    JbodStorage jbodStorage = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withDeleteClaim(false).withId(0).withSize(diskSizeGi + "Gi").build(), new PersistentClaimStorageBuilder().withDeleteClaim(false).withId(1).withSize(diskSizeGi + "Gi").build()).build();
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaJBOD(clusterName, kafkaReplicas, jbodStorage).build());
    // kafka cluster already deployed
    verifyVolumeNamesAndLabels(namespaceName, clusterName, kafkaReplicas, 2, diskSizeGi);
    int volumesCount = kubeClient(namespaceName).listPersistentVolumeClaims(namespaceName, clusterName).size();
    LOGGER.info("Deleting cluster");
    cmdKubeClient(namespaceName).deleteByName("kafka", clusterName);
    LOGGER.info("Waiting for PVC deletion");
    PersistentVolumeClaimUtils.waitForPVCDeletion(namespaceName, volumesCount, jbodStorage, clusterName);
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) TestUtils.fromYamlString(io.strimzi.test.TestUtils.fromYamlString) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 22 with JbodStorage

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

the class KafkaST method testKafkaJBODDeleteClaimsTrue.

@ParallelNamespaceTest
void testKafkaJBODDeleteClaimsTrue(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final int kafkaReplicas = 2;
    final String diskSizeGi = "10";
    JbodStorage jbodStorage = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withDeleteClaim(true).withId(0).withSize(diskSizeGi + "Gi").build(), new PersistentClaimStorageBuilder().withDeleteClaim(true).withId(1).withSize(diskSizeGi + "Gi").build()).build();
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaJBOD(clusterName, kafkaReplicas, jbodStorage).build());
    // kafka cluster already deployed
    verifyVolumeNamesAndLabels(namespaceName, clusterName, kafkaReplicas, 2, diskSizeGi);
    final int volumesCount = kubeClient(namespaceName).listPersistentVolumeClaims(namespaceName, clusterName).size();
    LOGGER.info("Deleting cluster");
    cmdKubeClient(namespaceName).deleteByName("kafka", clusterName);
    LOGGER.info("Waiting for PVC deletion");
    PersistentVolumeClaimUtils.waitForPVCDeletion(namespaceName, volumesCount, jbodStorage, clusterName);
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) TestUtils.fromYamlString(io.strimzi.test.TestUtils.fromYamlString) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 23 with JbodStorage

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

the class AbstractModel method createPersistentVolumeClaims.

/**
 * Creates list of PersistentVolumeClaims required by stateful deployments (Kafka and Zoo). This method calls itself
 * recursively to handle volumes inside JBOD storage. When it calls itself to handle the volumes inside JBOD array,
 * the {@code jbod} flag should be set to {@code true}. When called from outside, it should be set to {@code false}.
 *
 * @param storage   The storage configuration
 * @param jbod      Indicator whether the {@code storage} is part of JBOD array or not
 *
 * @return          List with Persistent Volume Claims
 */
protected List<PersistentVolumeClaim> createPersistentVolumeClaims(Storage storage, boolean jbod) {
    List<PersistentVolumeClaim> pvcs = new ArrayList<>();
    if (storage != null) {
        if (storage instanceof PersistentClaimStorage) {
            PersistentClaimStorage persistentStorage = (PersistentClaimStorage) storage;
            String pvcBaseName = VolumeUtils.createVolumePrefix(persistentStorage.getId(), jbod) + "-" + name;
            for (int i = 0; i < replicas; i++) {
                pvcs.add(createPersistentVolumeClaim(i, pvcBaseName + "-" + i, persistentStorage));
            }
        } else if (storage instanceof JbodStorage) {
            for (SingleVolumeStorage volume : ((JbodStorage) storage).getVolumes()) {
                // it's called recursively for setting the information from the current volume
                pvcs.addAll(createPersistentVolumeClaims(volume, true));
            }
        }
    }
    return pvcs;
}
Also used : SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) ArrayList(java.util.ArrayList) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint)

Example 24 with JbodStorage

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

the class AbstractModel method validatePersistentStorage.

/**
 * Validates persistent storage
 * If storage is of a persistent type, validations are made
 * If storage is not of a persistent type, validation passes
 *
 * @param storage   Persistent Storage configuration
 * @throws InvalidResourceException if validations fails for any reason
 */
protected static void validatePersistentStorage(Storage storage) {
    if (storage instanceof PersistentClaimStorage) {
        PersistentClaimStorage persistentClaimStorage = (PersistentClaimStorage) storage;
        checkPersistentStorageSizeIsValid(persistentClaimStorage);
    } else if (storage instanceof JbodStorage) {
        JbodStorage jbodStorage = (JbodStorage) storage;
        if (jbodStorage.getVolumes().size() == 0) {
            throw new InvalidResourceException("JbodStorage needs to contain at least one volume!");
        }
        for (Storage jbodVolume : jbodStorage.getVolumes()) {
            if (jbodVolume instanceof PersistentClaimStorage) {
                PersistentClaimStorage persistentClaimStorage = (PersistentClaimStorage) jbodVolume;
                checkPersistentStorageSizeIsValid(persistentClaimStorage);
            }
        }
    }
}
Also used : PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) Storage(io.strimzi.api.kafka.model.storage.Storage) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage)

Example 25 with JbodStorage

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

the class Capacity method generateDiskCapacity.

/**
 * Generate total disk capacity using the supplied storage configuration
 *
 * @param storage Storage configuration for Kafka cluster
 * @return Disk capacity per broker as a Double
 */
public static Double generateDiskCapacity(Storage storage) {
    if (storage instanceof PersistentClaimStorage) {
        return getSizeInMiB(((PersistentClaimStorage) storage).getSize());
    } else if (storage instanceof EphemeralStorage) {
        if (((EphemeralStorage) storage).getSizeLimit() != null) {
            return getSizeInMiB(((EphemeralStorage) storage).getSizeLimit());
        } else {
            return DEFAULT_BROKER_DISK_CAPACITY_IN_MIB;
        }
    } else if (storage instanceof JbodStorage) {
        // The value generated here for JBOD storage is used for tracking the total
        // disk capacity per broker. This will NOT be used for the final disk capacity
        // configuration since JBOD storage requires a special disk configuration.
        List<SingleVolumeStorage> volumeList = ((JbodStorage) storage).getVolumes();
        double size = 0;
        for (SingleVolumeStorage volume : volumeList) {
            size += generateDiskCapacity(volume);
        }
        return size;
    } else {
        throw new IllegalStateException("The declared storage '" + storage.getType() + "' is not supported");
    }
}
Also used : SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) EphemeralStorage(io.strimzi.api.kafka.model.storage.EphemeralStorage) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage)

Aggregations

JbodStorage (io.strimzi.api.kafka.model.storage.JbodStorage)28 PersistentClaimStorage (io.strimzi.api.kafka.model.storage.PersistentClaimStorage)14 JbodStorageBuilder (io.strimzi.api.kafka.model.storage.JbodStorageBuilder)12 PersistentClaimStorageBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)12 SingleVolumeStorage (io.strimzi.api.kafka.model.storage.SingleVolumeStorage)12 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)12 ArrayList (java.util.ArrayList)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 TestUtils.fromYamlString (io.strimzi.test.TestUtils.fromYamlString)8 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)8 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)6 Kafka (io.strimzi.api.kafka.model.Kafka)6 EphemeralStorage (io.strimzi.api.kafka.model.storage.EphemeralStorage)6 JsonObject (io.vertx.core.json.JsonObject)6 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 Secret (io.fabric8.kubernetes.api.model.Secret)4 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)4 InternalKafkaClient (io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient)4 Labels (io.strimzi.operator.common.model.Labels)3