Search in sources :

Example 16 with SingleVolumeStorage

use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage 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 17 with SingleVolumeStorage

use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage 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 18 with SingleVolumeStorage

use of io.strimzi.api.kafka.model.storage.SingleVolumeStorage 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)

Example 19 with SingleVolumeStorage

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

the class VolumeUtils method createPodSetVolumes.

/**
 * Generates the list of data volumes as used in PodSets and individual Pods. This includes both ephemeral and
 * persistent data volumes. This method calls itself recursively to create the volumes from a JBOD storage array.
 * When it does so, it sets the {@code jbod} parameter to {@code true}. When called from outside, it should be set
 * to {@code false}.
 *
 * @param podName   Name of the pod used to name the volumes
 * @param storage   Storage configuration
 * @param jbod      Indicates that the storage is part of JBOD storage and volume names are created accordingly
 *
 * @return          List of data volumes to be included in the StrimziPodSet pod
 */
public static List<Volume> createPodSetVolumes(String podName, Storage storage, boolean jbod) {
    List<Volume> volumes = new ArrayList<>();
    if (storage != null) {
        if (storage instanceof JbodStorage) {
            for (SingleVolumeStorage volume : ((JbodStorage) storage).getVolumes()) {
                // it's called recursively for setting the information from the current volume
                volumes.addAll(createPodSetVolumes(podName, volume, true));
            }
        } else if (storage instanceof EphemeralStorage) {
            EphemeralStorage ephemeralStorage = (EphemeralStorage) storage;
            volumes.add(createEmptyDirVolume(createVolumePrefix(ephemeralStorage.getId(), jbod), ephemeralStorage.getSizeLimit(), null));
        } else if (storage instanceof PersistentClaimStorage) {
            String name = createVolumePrefix(((PersistentClaimStorage) storage).getId(), jbod);
            volumes.add(createPvcVolume(name, name + "-" + podName));
        }
    }
    return volumes;
}
Also used : Volume(io.fabric8.kubernetes.api.model.Volume) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) ArrayList(java.util.ArrayList) EphemeralStorage(io.strimzi.api.kafka.model.storage.EphemeralStorage) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage)

Example 20 with SingleVolumeStorage

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

the class JbodStorageTest method testJbodStorageCreatesPersistentVolumeClaimsMatchingKafkaVolumes.

@Test
public void testJbodStorageCreatesPersistentVolumeClaimsMatchingKafkaVolumes(VertxTestContext context) {
    Checkpoint async = context.checkpoint();
    operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME)).onComplete(context.succeeding(v -> context.verify(() -> {
        List<PersistentVolumeClaim> pvcs = getPvcs(NAMESPACE, NAME);
        for (int i = 0; i < this.kafka.getSpec().getKafka().getReplicas(); i++) {
            int podId = i;
            for (SingleVolumeStorage volume : this.volumes) {
                if (volume instanceof PersistentClaimStorage) {
                    String expectedPvcName = VolumeUtils.createVolumePrefix(volume.getId(), true) + "-" + KafkaCluster.kafkaPodName(NAME, podId);
                    List<PersistentVolumeClaim> matchingPvcs = pvcs.stream().filter(pvc -> pvc.getMetadata().getName().equals(expectedPvcName)).collect(Collectors.toList());
                    assertThat("Exactly one pvc should have the name " + expectedPvcName + " in :\n" + pvcs.toString(), matchingPvcs, Matchers.hasSize(1));
                    PersistentVolumeClaim pvc = matchingPvcs.get(0);
                    boolean isDeleteClaim = ((PersistentClaimStorage) volume).isDeleteClaim();
                    assertThat("deleteClaim value did not match for volume : " + volume.toString(), Annotations.booleanAnnotation(pvc, AbstractModel.ANNO_STRIMZI_IO_DELETE_CLAIM, false), is(isDeleteClaim));
                }
            }
        }
        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) Checkpoint(io.vertx.junit5.Checkpoint) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) Reconciliation(io.strimzi.operator.common.Reconciliation) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Aggregations

SingleVolumeStorage (io.strimzi.api.kafka.model.storage.SingleVolumeStorage)20 PersistentClaimStorage (io.strimzi.api.kafka.model.storage.PersistentClaimStorage)14 JbodStorage (io.strimzi.api.kafka.model.storage.JbodStorage)12 ArrayList (java.util.ArrayList)12 EphemeralStorage (io.strimzi.api.kafka.model.storage.EphemeralStorage)10 PersistentClaimStorageBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)10 Kafka (io.strimzi.api.kafka.model.Kafka)6 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)6 ParallelTest (io.strimzi.test.annotations.ParallelTest)6 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)4 EphemeralStorageBuilder (io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder)4 JbodStorageBuilder (io.strimzi.api.kafka.model.storage.JbodStorageBuilder)4 Storage (io.strimzi.api.kafka.model.storage.Storage)4 Checkpoint (io.vertx.junit5.Checkpoint)4 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2