Search in sources :

Example 31 with PersistentClaimStorageBuilder

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

the class KafkaST method testKafkaJBODDeleteClaimsTrueFalse.

@ParallelNamespaceTest
@KRaftNotSupported("JBOD is not supported by KRaft mode and is used in this test case.")
void testKafkaJBODDeleteClaimsTrueFalse(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final int kafkaReplicas = 2;
    final String diskSizeGi = "10";
    JbodStorage jbodStorage = new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withDeleteClaim(false).withId(0).withSize(diskSizeGi + "Gi").build(), new PersistentClaimStorageBuilder().withDeleteClaim(true).withId(1).withSize(diskSizeGi + "Gi").build()).build();
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaJBOD(clusterName, kafkaReplicas, jbodStorage).build());
    // kafka cluster already deployed
    verifyVolumeNamesAndLabels(namespaceName, clusterName, kafkaReplicas, 2, diskSizeGi);
    final int volumesCount = kubeClient(namespaceName).listPersistentVolumeClaims(namespaceName, clusterName).size();
    LOGGER.info("Deleting cluster");
    cmdKubeClient(namespaceName).deleteByName("kafka", clusterName);
    LOGGER.info("Waiting for PVC deletion");
    PersistentVolumeClaimUtils.waitForJbodStorageDeletion(namespaceName, volumesCount, jbodStorage, clusterName);
}
Also used : JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) TestUtils.fromYamlString(io.strimzi.test.TestUtils.fromYamlString) JbodStorage(io.strimzi.api.kafka.model.storage.JbodStorage) KRaftNotSupported(io.strimzi.systemtest.annotations.KRaftNotSupported) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 32 with PersistentClaimStorageBuilder

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

the class KafkaClusterTest method testGeneratePersistentVolumeClaimsJbodWithTemplate.

@ParallelTest
public void testGeneratePersistentVolumeClaimsJbodWithTemplate() {
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, configuration, emptyMap())).editSpec().editKafka().withNewTemplate().withNewPersistentVolumeClaim().withNewMetadata().withLabels(singletonMap("testLabel", "testValue")).withAnnotations(singletonMap("testAnno", "testValue")).endMetadata().endPersistentVolumeClaim().endTemplate().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 PVCs
    List<PersistentVolumeClaim> pvcs = kc.generatePersistentVolumeClaims(kc.getStorage());
    assertThat(pvcs.size(), is(6));
    for (int i = 0; i < 6; i++) {
        PersistentVolumeClaim pvc = pvcs.get(i);
        assertThat(pvc.getMetadata().getLabels().get("testLabel"), is("testValue"));
        assertThat(pvc.getMetadata().getAnnotations().get("testAnno"), is("testValue"));
    }
}
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) 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 33 with PersistentClaimStorageBuilder

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

the class KRaftUtilsTest method testInvalidKafka.

@ParallelTest
public void testInvalidKafka() {
    KafkaSpec spec = new KafkaSpecBuilder().withNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("listener").withPort(9092).withTls(true).withType(KafkaListenerType.INTERNAL).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build()).withNewJbodStorage().withVolumes(new PersistentClaimStorageBuilder().withId(0).withSize("100Gi").build(), new PersistentClaimStorageBuilder().withId(1).withSize("100Gi").build()).endJbodStorage().withNewKafkaAuthorizationSimple().endKafkaAuthorizationSimple().endKafka().build();
    InvalidResourceException ex = assertThrows(InvalidResourceException.class, () -> KRaftUtils.validateKafkaCrForKRaft(spec));
    assertThat(ex.getMessage(), is("Kafka configuration is not valid: [Authentication of type 'scram-sha-512` is currently not supported when the UseKRaft feature gate is enabled, Using more than one disk in a JBOD storage is currently not supported when the UseKRaft feature gate is enabled]"));
}
Also used : KafkaSpecBuilder(io.strimzi.api.kafka.model.KafkaSpecBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) KafkaSpec(io.strimzi.api.kafka.model.KafkaSpec) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 34 with PersistentClaimStorageBuilder

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

the class KafkaPodSetTest method testPodSet.

@ParallelTest
public void testPodSet() {
    KafkaCluster kc = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, KAFKA, VERSIONS);
    StrimziPodSet ps = kc.generatePodSet(3, true, null, null, brokerId -> Map.of("test-anno", kc.getPodName(brokerId)));
    assertThat(ps.getMetadata().getName(), is(KafkaResources.kafkaStatefulSetName(CLUSTER)));
    assertThat(ps.getMetadata().getLabels().entrySet().containsAll(kc.getLabelsWithStrimziName(kc.getName(), null).toMap().entrySet()), is(true));
    assertThat(ps.getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_STORAGE), is(ModelUtils.encodeStorageToJson(new JbodStorageBuilder().withVolumes(new PersistentClaimStorageBuilder().withId(0).withSize("100Gi").withDeleteClaim(false).build()).build())));
    assertThat(ps.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(ps.getMetadata().getOwnerReferences().get(0), is(kc.createOwnerReference()));
    assertThat(ps.getSpec().getSelector().getMatchLabels(), is(kc.getSelectorLabels().toMap()));
    assertThat(ps.getSpec().getPods().size(), is(3));
    // We need to loop through the pods to make sure they have the right values
    List<Pod> pods = PodSetUtils.mapsToPods(ps.getSpec().getPods());
    for (Pod pod : pods) {
        assertThat(pod.getMetadata().getLabels().entrySet().containsAll(kc.getLabelsWithStrimziNameAndPodName(kc.getName(), pod.getMetadata().getName(), null).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(kc.getName()).toMap().entrySet()), is(true));
        assertThat(pod.getMetadata().getAnnotations().size(), is(2));
        assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
        assertThat(pod.getMetadata().getAnnotations().get("test-anno"), is(pod.getMetadata().getName()));
        assertThat(pod.getSpec().getHostname(), is(pod.getMetadata().getName()));
        assertThat(pod.getSpec().getSubdomain(), is(kc.getHeadlessServiceName()));
        assertThat(pod.getSpec().getRestartPolicy(), is("Always"));
        assertThat(pod.getSpec().getTerminationGracePeriodSeconds(), is(30L));
        assertThat(pod.getSpec().getVolumes().stream().filter(volume -> volume.getName().equalsIgnoreCase("strimzi-tmp")).findFirst().orElse(null).getEmptyDir().getSizeLimit(), is(new Quantity(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_SIZE)));
        assertThat(pod.getSpec().getContainers().size(), is(1));
        assertThat(pod.getSpec().getContainers().get(0).getLivenessProbe().getTimeoutSeconds(), is(5));
        assertThat(pod.getSpec().getContainers().get(0).getLivenessProbe().getInitialDelaySeconds(), is(15));
        assertThat(pod.getSpec().getContainers().get(0).getReadinessProbe().getTimeoutSeconds(), is(5));
        assertThat(pod.getSpec().getContainers().get(0).getReadinessProbe().getInitialDelaySeconds(), is(15));
        assertThat(AbstractModel.containerEnvVars(pod.getSpec().getContainers().get(0)).get(AbstractModel.ENV_VAR_STRIMZI_KAFKA_GC_LOG_ENABLED), is(Boolean.toString(AbstractModel.DEFAULT_JVM_GC_LOGGING_ENABLED)));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), is("data-0"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), is("/var/lib/kafka/data-0"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getName(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_MOUNT_PATH));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getName(), is(KafkaCluster.CLUSTER_CA_CERTS_VOLUME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getMountPath(), is(KafkaCluster.CLUSTER_CA_CERTS_VOLUME_MOUNT));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getName(), is(KafkaCluster.BROKER_CERTS_VOLUME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getMountPath(), is(KafkaCluster.BROKER_CERTS_VOLUME_MOUNT));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getName(), is(KafkaCluster.CLIENT_CA_CERTS_VOLUME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getMountPath(), is(KafkaCluster.CLIENT_CA_CERTS_VOLUME_MOUNT));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(5).getName(), is("kafka-metrics-and-logging"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(5).getMountPath(), is("/opt/kafka/custom-config/"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(6).getName(), is("ready-files"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(6).getMountPath(), is("/var/opt/kafka"));
        assertThat(pod.getSpec().getVolumes().size(), is(7));
        assertThat(pod.getSpec().getVolumes().get(0).getName(), is("data-0"));
        assertThat(pod.getSpec().getVolumes().get(0).getPersistentVolumeClaim(), is(notNullValue()));
        assertThat(pod.getSpec().getVolumes().get(1).getName(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
        assertThat(pod.getSpec().getVolumes().get(1).getEmptyDir(), is(notNullValue()));
        assertThat(pod.getSpec().getVolumes().get(2).getName(), is(KafkaCluster.CLUSTER_CA_CERTS_VOLUME));
        assertThat(pod.getSpec().getVolumes().get(2).getSecret().getSecretName(), is("my-cluster-cluster-ca-cert"));
        assertThat(pod.getSpec().getVolumes().get(3).getName(), is(KafkaCluster.BROKER_CERTS_VOLUME));
        assertThat(pod.getSpec().getVolumes().get(3).getSecret().getSecretName(), is("my-cluster-kafka-brokers"));
        assertThat(pod.getSpec().getVolumes().get(4).getName(), is(KafkaCluster.CLIENT_CA_CERTS_VOLUME));
        assertThat(pod.getSpec().getVolumes().get(4).getSecret().getSecretName(), is("my-cluster-clients-ca-cert"));
        assertThat(pod.getSpec().getVolumes().get(5).getName(), is("kafka-metrics-and-logging"));
        assertThat(pod.getSpec().getVolumes().get(5).getConfigMap().getName(), is(pod.getMetadata().getName()));
        assertThat(pod.getSpec().getVolumes().get(6).getName(), is("ready-files"));
        assertThat(pod.getSpec().getVolumes().get(6).getEmptyDir(), is(notNullValue()));
    }
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) ParallelSuite(io.strimzi.test.annotations.ParallelSuite) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) SecurityContextBuilder(io.fabric8.kubernetes.api.model.SecurityContextBuilder) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Map(java.util.Map) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) PodRevision(io.strimzi.operator.cluster.operator.resource.PodRevision) Affinity(io.fabric8.kubernetes.api.model.Affinity) Probe(io.strimzi.api.kafka.model.Probe) LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) List(java.util.List) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) HostAliasBuilder(io.fabric8.kubernetes.api.model.HostAliasBuilder) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) TestUtils(io.strimzi.test.TestUtils) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) Pod(io.fabric8.kubernetes.api.model.Pod) Toleration(io.fabric8.kubernetes.api.model.Toleration) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) Kafka(io.strimzi.api.kafka.model.Kafka) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) JbodStorageBuilder(io.strimzi.api.kafka.model.storage.JbodStorageBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 35 with PersistentClaimStorageBuilder

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

the class KafkaBrokerConfigurationBuilderTest method testPerBrokerPersistentStorageLogDirs.

@ParallelTest
public void testPerBrokerPersistentStorageLogDirs() {
    Storage storage = new PersistentClaimStorageBuilder().withSize("1Ti").withStorageClass("aws-ebs").withDeleteClaim(true).build();
    String configuration = new KafkaBrokerConfigurationBuilder(Reconciliation.DUMMY_RECONCILIATION).withBrokerId("2").withLogDirs(VolumeUtils.createVolumeMounts(storage, "/var/lib/kafka", false)).build();
    assertThat(configuration, isEquivalent("broker.id=2", "node.id=2", "log.dirs=/var/lib/kafka/data/kafka-log2"));
}
Also used : Storage(io.strimzi.api.kafka.model.storage.Storage) SingleVolumeStorage(io.strimzi.api.kafka.model.storage.SingleVolumeStorage) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

PersistentClaimStorageBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder)95 ParallelTest (io.strimzi.test.annotations.ParallelTest)64 JbodStorageBuilder (io.strimzi.api.kafka.model.storage.JbodStorageBuilder)52 Storage (io.strimzi.api.kafka.model.storage.Storage)45 Kafka (io.strimzi.api.kafka.model.Kafka)38 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)36 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)23 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)22 SingleVolumeStorage (io.strimzi.api.kafka.model.storage.SingleVolumeStorage)21 JbodStorage (io.strimzi.api.kafka.model.storage.JbodStorage)20 ArrayList (java.util.ArrayList)19 PersistentClaimStorageOverrideBuilder (io.strimzi.api.kafka.model.storage.PersistentClaimStorageOverrideBuilder)17 Quantity (io.fabric8.kubernetes.api.model.Quantity)16 EphemeralStorageBuilder (io.strimzi.api.kafka.model.storage.EphemeralStorageBuilder)16 List (java.util.List)16 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)15 KRaftNotSupported (io.strimzi.systemtest.annotations.KRaftNotSupported)14 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)14 Map (java.util.Map)14 CoreMatchers.is (org.hamcrest.CoreMatchers.is)14