Search in sources :

Example 11 with PersistentClaimStorageOverrideBuilder

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

the class StorageDiffTest method testPersistentDiffWithOverridesBeingAddedAndRemoved.

@ParallelTest
public void testPersistentDiffWithOverridesBeingAddedAndRemoved() {
    Storage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").withOverrides(new PersistentClaimStorageOverrideBuilder().withBroker(0).withStorageClass("gp2-ssd-az1").build()).build();
    Storage persistent2 = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").withOverrides(new PersistentClaimStorageOverrideBuilder().withBroker(1).withStorageClass("gp2-ssd-az2").build()).build();
    // Test no changes
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent, 2, 2).isEmpty(), is(true));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent2, persistent2, 2, 2).isEmpty(), is(true));
    // Overrides added and removed for existing nodes => not allowed
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent2, persistent, 2, 2).isEmpty(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 2, 2).isEmpty(), is(false));
    // Overrides added for new nodes but removed for old => not allowed
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 1, 2).isEmpty(), is(false));
    // Overrides removed for new nodes but added for old => not allowed
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent2, persistent, 1, 2).isEmpty(), is(false));
}
Also used : Storage(io.strimzi.api.kafka.model.storage.Storage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) PersistentClaimStorageOverrideBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 12 with PersistentClaimStorageOverrideBuilder

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

the class StorageDiffTest method testPersistentDiffWithOverrides.

@ParallelTest
public void testPersistentDiffWithOverrides() {
    Storage persistent = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").build();
    Storage persistent2 = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").withOverrides(new PersistentClaimStorageOverrideBuilder().withBroker(1).withStorageClass("gp2-ssd-az1").build()).build();
    Storage persistent3 = new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").withOverrides(new PersistentClaimStorageOverrideBuilder().withBroker(1).withStorageClass("gp2-ssd-az2").build()).build();
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent, 3, 3).changesType(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent, 3, 3).isEmpty(), is(true));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent, 3, 3).shrinkSize(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 3, 3).changesType(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 3, 3).isEmpty(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent, persistent2, 3, 3).shrinkSize(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent2, persistent3, 3, 3).changesType(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent2, persistent3, 3, 3).isEmpty(), is(false));
    assertThat(new StorageDiff(Reconciliation.DUMMY_RECONCILIATION, persistent2, persistent3, 3, 3).shrinkSize(), is(false));
}
Also used : Storage(io.strimzi.api.kafka.model.storage.Storage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) PersistentClaimStorageOverrideBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 13 with PersistentClaimStorageOverrideBuilder

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder 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(kc.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(kc.VOLUME_NAME), is(true));
        assertThat(pvc.getMetadata().getOwnerReferences().size(), is(1));
        assertThat(pvc.getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_DELETE_CLAIM), is("true"));
    }
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) PersistentClaimStorageOverrideBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 14 with PersistentClaimStorageOverrideBuilder

use of io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder in project strimzi-kafka-operator 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(kc.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(kc.VOLUME_NAME), is(true));
        assertThat(pvc.getMetadata().getOwnerReferences().size(), is(1));
        assertThat(pvc.getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_DELETE_CLAIM), is("true"));
    }
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) PersistentClaimStorageOverrideBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 15 with PersistentClaimStorageOverrideBuilder

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

the class ZookeeperClusterTest method testGeneratePersistentVolumeClaimsWithTemplate.

@ParallelTest
public void testGeneratePersistentVolumeClaimsWithTemplate() {
    Kafka ka = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configurationJson, zooConfigurationJson)).editSpec().editZookeeper().withNewTemplate().withNewPersistentVolumeClaim().withNewMetadata().withLabels(singletonMap("testLabel", "testValue")).withAnnotations(singletonMap("testAnno", "testValue")).endMetadata().endPersistentVolumeClaim().endTemplate().withStorage(new PersistentClaimStorageBuilder().withStorageClass("gp2-ssd").withDeleteClaim(false).withId(0).withSize("100Gi").withOverrides(new PersistentClaimStorageOverrideBuilder().withBroker(1).withStorageClass("gp2-ssd-az1").build()).build()).endZookeeper().endSpec().build();
    ZookeeperCluster zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, ka, VERSIONS);
    // Check PVCs
    List<PersistentVolumeClaim> pvcs = zc.generatePersistentVolumeClaims();
    assertThat(pvcs.size(), is(3));
    for (int i = 0; i < 3; i++) {
        PersistentVolumeClaim pvc = pvcs.get(i);
        assertThat(pvc.getMetadata().getLabels().get("testLabel"), is("testValue"));
        assertThat(pvc.getMetadata().getAnnotations().get("testAnno"), is("testValue"));
    }
}
Also used : Kafka(io.strimzi.api.kafka.model.Kafka) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) PersistentClaimStorageOverrideBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

PersistentClaimStorageOverrideBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder)20 ParallelTest (io.strimzi.test.annotations.ParallelTest)20 PersistentClaimStorageBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)16 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)10 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)10 Kafka (io.strimzi.api.kafka.model.Kafka)10 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)10 Storage (io.strimzi.api.kafka.model.storage.Storage)10 Quantity (io.fabric8.kubernetes.api.model.Quantity)6 JbodStorageBuilder (io.strimzi.api.kafka.model.storage.JbodStorageBuilder)4