Search in sources :

Example 1 with KafkaClusterTemplateBuilder

use of io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder in project strimzi by strimzi.

the class KafkaRollerIsolatedST method testKafkaPodPendingDueToRack.

@ParallelNamespaceTest
void testKafkaPodPendingDueToRack(ExtensionContext extensionContext) {
    // Testing this scenario
    // 1. deploy Kafka with wrong pod template (looking for nonexistent node) kafka pods should not exist
    // 2. wait for Kafka not ready, kafka pods should be in the pending state
    // 3. fix the Kafka CR, kafka pods should be in the pending state
    // 4. wait for Kafka ready, kafka pods should NOT be in the pending state
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    NodeSelectorRequirement nsr = new NodeSelectorRequirementBuilder().withKey("dedicated_test").withOperator("In").withValues("Kafka").build();
    NodeSelectorTerm nst = new NodeSelectorTermBuilder().withMatchExpressions(nsr).build();
    Affinity affinity = new AffinityBuilder().withNewNodeAffinity().withNewRequiredDuringSchedulingIgnoredDuringExecution().withNodeSelectorTerms(nst).endRequiredDuringSchedulingIgnoredDuringExecution().endNodeAffinity().build();
    PodTemplate pt = new PodTemplate();
    pt.setAffinity(affinity);
    KafkaClusterTemplate kct = new KafkaClusterTemplateBuilder().withPod(pt).build();
    resourceManager.createResource(extensionContext, false, KafkaTemplates.kafkaEphemeral(clusterName, 3, 3).editSpec().editKafka().withTemplate(kct).endKafka().endSpec().build());
    // pods are stable in the Pending state
    PodUtils.waitUntilPodStabilityReplicasCount(namespaceName, KafkaResources.kafkaStatefulSetName(clusterName), 3);
    LOGGER.info("Removing requirement for the affinity");
    KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> kafka.getSpec().getKafka().getTemplate().getPod().setAffinity(null), namespaceName);
    // kafka should get back ready in some reasonable time frame
    KafkaUtils.waitForKafkaReady(namespaceName, clusterName);
    KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
    KafkaUtils.waitForKafkaDeletion(namespaceName, clusterName);
}
Also used : NodeSelectorRequirementBuilder(io.fabric8.kubernetes.api.model.NodeSelectorRequirementBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) KafkaClusterTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder) NodeSelectorRequirement(io.fabric8.kubernetes.api.model.NodeSelectorRequirement) Affinity(io.fabric8.kubernetes.api.model.Affinity) KafkaClusterTemplate(io.strimzi.api.kafka.model.template.KafkaClusterTemplate) NodeSelectorTerm(io.fabric8.kubernetes.api.model.NodeSelectorTerm) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) PodTemplate(io.strimzi.api.kafka.model.template.PodTemplate) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Example 2 with KafkaClusterTemplateBuilder

use of io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaRollerIsolatedST method testKafkaPodPendingDueToRack.

@ParallelNamespaceTest
void testKafkaPodPendingDueToRack(ExtensionContext extensionContext) {
    // Testing this scenario
    // 1. deploy Kafka with wrong pod template (looking for nonexistent node) kafka pods should not exist
    // 2. wait for Kafka not ready, kafka pods should be in the pending state
    // 3. fix the Kafka CR, kafka pods should be in the pending state
    // 4. wait for Kafka ready, kafka pods should NOT be in the pending state
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    NodeSelectorRequirement nsr = new NodeSelectorRequirementBuilder().withKey("dedicated_test").withOperator("In").withValues("Kafka").build();
    NodeSelectorTerm nst = new NodeSelectorTermBuilder().withMatchExpressions(nsr).build();
    Affinity affinity = new AffinityBuilder().withNewNodeAffinity().withNewRequiredDuringSchedulingIgnoredDuringExecution().withNodeSelectorTerms(nst).endRequiredDuringSchedulingIgnoredDuringExecution().endNodeAffinity().build();
    PodTemplate pt = new PodTemplate();
    pt.setAffinity(affinity);
    KafkaClusterTemplate kct = new KafkaClusterTemplateBuilder().withPod(pt).build();
    resourceManager.createResource(extensionContext, false, KafkaTemplates.kafkaEphemeral(clusterName, 3, 3).editSpec().editKafka().withTemplate(kct).endKafka().endSpec().build());
    // pods are stable in the Pending state
    PodUtils.waitUntilPodStabilityReplicasCount(namespaceName, KafkaResources.kafkaStatefulSetName(clusterName), 3);
    LOGGER.info("Removing requirement for the affinity");
    KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, kafka -> kafka.getSpec().getKafka().getTemplate().getPod().setAffinity(null), namespaceName);
    // kafka should get back ready in some reasonable time frame
    KafkaUtils.waitForKafkaReady(namespaceName, clusterName);
    KafkaResource.kafkaClient().inNamespace(namespaceName).withName(clusterName).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
    KafkaUtils.waitForKafkaDeletion(namespaceName, clusterName);
}
Also used : NodeSelectorRequirementBuilder(io.fabric8.kubernetes.api.model.NodeSelectorRequirementBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) KafkaClusterTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder) NodeSelectorRequirement(io.fabric8.kubernetes.api.model.NodeSelectorRequirement) Affinity(io.fabric8.kubernetes.api.model.Affinity) KafkaClusterTemplate(io.strimzi.api.kafka.model.template.KafkaClusterTemplate) NodeSelectorTerm(io.fabric8.kubernetes.api.model.NodeSelectorTerm) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) PodTemplate(io.strimzi.api.kafka.model.template.PodTemplate) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest)

Aggregations

Affinity (io.fabric8.kubernetes.api.model.Affinity)2 AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)2 NodeSelectorRequirement (io.fabric8.kubernetes.api.model.NodeSelectorRequirement)2 NodeSelectorRequirementBuilder (io.fabric8.kubernetes.api.model.NodeSelectorRequirementBuilder)2 NodeSelectorTerm (io.fabric8.kubernetes.api.model.NodeSelectorTerm)2 NodeSelectorTermBuilder (io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder)2 KafkaClusterTemplate (io.strimzi.api.kafka.model.template.KafkaClusterTemplate)2 KafkaClusterTemplateBuilder (io.strimzi.api.kafka.model.template.KafkaClusterTemplateBuilder)2 PodTemplate (io.strimzi.api.kafka.model.template.PodTemplate)2 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)2