Search in sources :

Example 16 with PersistentClaimStorage

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

the class Capacity method generateJbodDiskCapacity.

/**
 * Generate JBOD disk capacity configuration for a broker using the supplied storage configuration
 *
 * @param storage Storage configuration for Kafka cluster
 * @param idx Index of the broker
 * @return Disk capacity configuration value as a JsonObject for broker idx
 */
private JsonObject generateJbodDiskCapacity(Storage storage, int idx) {
    JsonObject json = new JsonObject();
    String size = "";
    for (SingleVolumeStorage volume : ((JbodStorage) storage).getVolumes()) {
        String name = VolumeUtils.createVolumePrefix(volume.getId(), true);
        String path = AbstractModel.KAFKA_MOUNT_PATH + "/" + name + "/" + AbstractModel.KAFKA_LOG_DIR + idx;
        if (volume instanceof PersistentClaimStorage) {
            size = ((PersistentClaimStorage) volume).getSize();
        } else if (volume instanceof EphemeralStorage) {
            size = ((EphemeralStorage) volume).getSizeLimit();
        }
        json.put(path, String.valueOf(Capacity.getSizeInMiB(size)));
    }
    return json;
}
Also used : SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) JsonObject(io.vertx.core.json.JsonObject) EphemeralStorage(io.strimzi.api.kafka.model.storage.EphemeralStorage) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage)

Example 17 with PersistentClaimStorage

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

the class StorageDiff method isOverrideChangeAllowed.

/**
 * Validates the changes to the storage overrides and decides whether they are allowed or not. Allowed changes are
 * those to nodes which will be added, removed or which do nto exist yet.
 *
 * @param current           Current Storage configuration
 * @param desired           New storage configuration
 * @param currentReplicas   Current number of replicas
 * @param desiredReplicas   Desired number of replicas
 * @return                  True if only allowed override changes were done, false othewise
 */
private boolean isOverrideChangeAllowed(Storage current, Storage desired, int currentReplicas, int desiredReplicas) {
    List<PersistentClaimStorageOverride> currentOverrides = ((PersistentClaimStorage) current).getOverrides();
    if (currentOverrides == null) {
        currentOverrides = Collections.emptyList();
    }
    List<PersistentClaimStorageOverride> desiredOverrides = ((PersistentClaimStorage) desired).getOverrides();
    if (desiredOverrides == null) {
        desiredOverrides = Collections.emptyList();
    }
    // We care only about the nodes which existed before this reconciliation and will still exist after it
    int existedAndWillExist = Math.min(currentReplicas, desiredReplicas);
    for (int i = 0; i < existedAndWillExist; i++) {
        int nodeId = i;
        PersistentClaimStorageOverride currentOverride = currentOverrides.stream().filter(override -> override.getBroker() == nodeId).findFirst().orElse(null);
        PersistentClaimStorageOverride desiredOverride = desiredOverrides.stream().filter(override -> override.getBroker() == nodeId).findFirst().orElse(null);
        if (currentOverride != null && desiredOverride != null) {
            // Both overrides exist but are not equal
            if (!currentOverride.equals(desiredOverride)) {
                return false;
            }
        } else if (currentOverride != null || desiredOverride != null) {
            // One of them is null while the other is not null => they differ
            return false;
        }
    }
    return true;
}
Also used : PersistentClaimStorage(io.strimzi.api.kafka.model.storage.PersistentClaimStorage) PersistentClaimStorageOverride(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverride)

Example 18 with PersistentClaimStorage

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

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

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

Aggregations

PersistentClaimStorage (io.strimzi.api.kafka.model.storage.PersistentClaimStorage)30 SingleVolumeStorage (io.strimzi.api.kafka.model.storage.SingleVolumeStorage)21 JbodStorage (io.strimzi.api.kafka.model.storage.JbodStorage)19 ArrayList (java.util.ArrayList)15 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)13 EphemeralStorage (io.strimzi.api.kafka.model.storage.EphemeralStorage)12 Kafka (io.strimzi.api.kafka.model.Kafka)11 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)11 PersistentClaimStorageBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)11 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)10 Checkpoint (io.vertx.junit5.Checkpoint)10 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)9 Storage (io.strimzi.api.kafka.model.storage.Storage)9 Volume (io.fabric8.kubernetes.api.model.Volume)8 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)8 Crds (io.strimzi.api.kafka.Crds)8 KafkaList (io.strimzi.api.kafka.KafkaList)8 StrimziPodSetList (io.strimzi.api.kafka.StrimziPodSetList)8 StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)8 KafkaListenerType (io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType)8