use of io.strimzi.api.kafka.model.storage.JbodStorageBuilder in project strimzi by strimzi.
the class KafkaClusterTest method testGeneratePersistentVolumeClaimsJbod.
@ParallelTest
public void testGeneratePersistentVolumeClaimsJbod() {
Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withStorage(new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").withOverrides(new PersistentClaimStorageOverrideBuilder().withBroker(1).withStorageClass("gp2-ssd-az1").build()).build(), new PersistentClaimStorageBuilder().withStorageClass("gp2-st1").withDeleteClaim(true).withId(1).withSize("1000Gi").withOverrides(new PersistentClaimStorageOverrideBuilder().withBroker(1).withStorageClass("gp2-st1-az1").build()).build()).build()).endKafka().endSpec().build();
KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
// Check Storage annotation on STS
assertThat(kc.generateStatefulSet(true, ImagePullPolicy.NEVER, null, null).getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_STORAGE), is(ModelUtils.encodeStorageToJson(kafkaAssembly.getSpec().getKafka().getStorage())));
// Check PVCs
List<PersistentVolumeClaim> pvcs = kc.generatePersistentVolumeClaims(kc.getStorage());
assertThat(pvcs.size(), is(6));
for (int i = 0; i < 3; i++) {
PersistentVolumeClaim pvc = pvcs.get(i);
assertThat(pvc.getSpec().getResources().getRequests().get("storage"), is(new Quantity("100Gi")));
if (i != 1) {
assertThat(pvc.getSpec().getStorageClassName(), is("gp2-ssd"));
} else {
assertThat(pvc.getSpec().getStorageClassName(), is("gp2-ssd-az1"));
}
assertThat(pvc.getMetadata().getName().startsWith(KafkaCluster.VOLUME_NAME), is(true));
assertThat(pvc.getMetadata().getOwnerReferences().size(), is(0));
assertThat(pvc.getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_DELETE_CLAIM), is("false"));
}
for (int i = 3; i < 6; i++) {
PersistentVolumeClaim pvc = pvcs.get(i);
assertThat(pvc.getSpec().getResources().getRequests().get("storage"), is(new Quantity("1000Gi")));
if (i != 4) {
assertThat(pvc.getSpec().getStorageClassName(), is("gp2-st1"));
} else {
assertThat(pvc.getSpec().getStorageClassName(), is("gp2-st1-az1"));
}
assertThat(pvc.getMetadata().getName().startsWith(KafkaCluster.VOLUME_NAME), is(true));
assertThat(pvc.getMetadata().getOwnerReferences().size(), is(1));
assertThat(pvc.getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_DELETE_CLAIM), is("true"));
}
}
use of io.strimzi.api.kafka.model.storage.JbodStorageBuilder in project strimzi by strimzi.
the class KafkaClusterTest method testGeneratePersistentVolumeClaimsJbodWithoutVolumes.
@ParallelTest
public void testGeneratePersistentVolumeClaimsJbodWithoutVolumes() {
assertThrows(InvalidResourceException.class, () -> {
Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withStorage(new JbodStorageBuilder().withVolumes(List.of()).build()).endKafka().endSpec().build();
KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaAssembly, VERSIONS);
});
}
use of io.strimzi.api.kafka.model.storage.JbodStorageBuilder in project strimzi by strimzi.
the class ModelUtilsTest method testStorageSerializationAndDeserialization.
@ParallelTest
public void testStorageSerializationAndDeserialization() {
Storage jbod = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build(), new PersistentClaimStorageBuilder().withStorageClass("gp2-st1").withDeleteClaim(true).withId(1).withSize("1000Gi").build()).build();
Storage ephemeral = new EphemeralStorageBuilder().build();
Storage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build();
assertThat(ModelUtils.decodeStorageFromJson(ModelUtils.encodeStorageToJson(jbod)), is(jbod));
assertThat(ModelUtils.decodeStorageFromJson(ModelUtils.encodeStorageToJson(ephemeral)), is(ephemeral));
assertThat(ModelUtils.decodeStorageFromJson(ModelUtils.encodeStorageToJson(persistent)), is(persistent));
}
use of io.strimzi.api.kafka.model.storage.JbodStorageBuilder in project strimzi 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));
}
use of io.strimzi.api.kafka.model.storage.JbodStorageBuilder in project strimzi by strimzi.
the class StorageDiffTest method testJbodDiff.
@ParallelTest
public void testJbodDiff() {
Storage jbod = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build(), new PersistentClaimStorageBuilder().withStorageClass("gp2-st1").withDeleteClaim(true).withId(1).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();
StorageDiff diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod, jbod, 3, 3);
assertThat(diff.changesType(), is(false));
assertThat(diff.isEmpty(), is(true));
assertThat(diff.shrinkSize(), is(false));
assertThat(diff.isVolumesAddedOrRemoved(), is(false));
diff = new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, jbod, jbod2, 3, 3);
assertThat(diff.changesType(), is(false));
assertThat(diff.isEmpty(), is(false));
assertThat(diff.shrinkSize(), is(false));
assertThat(diff.isVolumesAddedOrRemoved(), is(false));
}
Aggregations