use of io.strimzi.api.kafka.model.storage.PersistentClaimStorage in project strimzi by strimzi.
the class KafkaAssemblyOperatorTest method createPvcs.
private Map<String, PersistentVolumeClaim> createPvcs(String namespace, Storage storage, int replicas, BiFunction<Integer, Integer, String> pvcNameFunction) {
Map<String, PersistentVolumeClaim> pvcs = new HashMap<>();
if (storage instanceof PersistentClaimStorage) {
for (int i = 0; i < replicas; i++) {
Integer storageId = ((PersistentClaimStorage) storage).getId();
String pvcName = pvcNameFunction.apply(i, storageId);
PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder().withNewMetadata().withNamespace(namespace).withName(pvcName).endMetadata().build();
pvcs.put(pvcName, pvc);
}
}
return pvcs;
}
use of io.strimzi.api.kafka.model.storage.PersistentClaimStorage 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;
}
use of io.strimzi.api.kafka.model.storage.PersistentClaimStorage 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);
}
}
}
}
use of io.strimzi.api.kafka.model.storage.PersistentClaimStorage 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");
}
}
use of io.strimzi.api.kafka.model.storage.PersistentClaimStorage 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;
}
Aggregations